1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2007 Mathieu Desnoyers
4 * Complete rewrite from the original version made by XangXiu Yang.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License Version 2.1 as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
27 #include <ltt/event.h>
28 #include <ltt/ltt-types.h>
29 #include <ltt/ltt-private.h>
30 #include <ltt/marker.h>
31 #include <ltt/marker-field.h>
33 /*****************************************************************************
35 * ltt_event_position_get : get the event position data
37 * e : an instance of an event type
38 * ep : a pointer to event's position structure
39 * tf : tracefile pointer
40 * block : current block
41 * offset : current offset
43 ****************************************************************************/
44 void ltt_event_position_get(LttEventPosition
*ep
, LttTracefile
**tf
,
45 guint
*block
, guint
*offset
, guint64
*tsc
)
54 void ltt_event_position_set(LttEventPosition
*ep
, LttTracefile
*tf
,
55 guint block
, guint offset
, guint64 tsc
)
64 /*****************************************************************************
66 * ltt_event_position : get the event's position
68 * e : an instance of an event type
69 * ep : a pointer to event's position structure
70 ****************************************************************************/
72 void ltt_event_position(LttEvent
*e
, LttEventPosition
*ep
)
74 ep
->tracefile
= e
->tracefile
;
76 ep
->offset
= e
->offset
;
80 LttEventPosition
* ltt_event_position_new()
82 return g_new(LttEventPosition
, 1);
86 /*****************************************************************************
88 * ltt_event_position_compare : compare two positions
89 * A NULL value is infinite.
91 * ep1 : a pointer to event's position structure
92 * ep2 : a pointer to event's position structure
97 ****************************************************************************/
100 gint
ltt_event_position_compare(const LttEventPosition
*ep1
,
101 const LttEventPosition
*ep2
)
103 if(ep1
== NULL
&& ep2
== NULL
)
105 if(ep1
!= NULL
&& ep2
== NULL
)
107 if(ep1
== NULL
&& ep2
!= NULL
)
110 if(ep1
->tracefile
!= ep2
->tracefile
)
111 g_error("ltt_event_position_compare on different tracefiles makes no sense");
113 if(ep1
->block
< ep2
->block
)
115 if(ep1
->block
> ep2
->block
)
117 if(ep1
->offset
< ep2
->offset
)
119 if(ep1
->offset
> ep2
->offset
)
124 /*****************************************************************************
126 * ltt_event_position_copy : copy position
128 * src : a pointer to event's position structure source
129 * dest : a pointer to event's position structure dest
132 ****************************************************************************/
133 void ltt_event_position_copy(LttEventPosition
*dest
,
134 const LttEventPosition
*src
)
144 LttTracefile
*ltt_event_position_tracefile(LttEventPosition
*ep
)
146 return ep
->tracefile
;
149 /*****************************************************************************
150 * These functions extract data from an event after architecture specific
152 ****************************************************************************/
153 guint32
ltt_event_get_unsigned(LttEvent
*e
, struct marker_field
*f
)
155 gboolean reverse_byte_order
;
157 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
158 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
160 reverse_byte_order
= LTT_GET_BO(e
->tracefile
);
166 guint8 x
= *(guint8
*)(e
->data
+ f
->offset
);
171 return (guint32
)ltt_get_uint16(reverse_byte_order
, e
->data
+ f
->offset
);
174 return (guint32
)ltt_get_uint32(reverse_byte_order
, e
->data
+ f
->offset
);
178 g_critical("ltt_event_get_unsigned : field size %li unknown", f
->size
);
184 gint32
ltt_event_get_int(LttEvent
*e
, struct marker_field
*f
)
186 gboolean reverse_byte_order
;
187 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
188 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
190 reverse_byte_order
= LTT_GET_BO(e
->tracefile
);
196 gint8 x
= *(gint8
*)(e
->data
+ f
->offset
);
201 return (gint32
)ltt_get_int16(reverse_byte_order
, e
->data
+ f
->offset
);
204 return (gint32
)ltt_get_int32(reverse_byte_order
, e
->data
+ f
->offset
);
208 g_critical("ltt_event_get_int : field size %li unknown", f
->size
);
214 guint64
ltt_event_get_long_unsigned(LttEvent
*e
, struct marker_field
*f
)
216 gboolean reverse_byte_order
;
217 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
218 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
220 reverse_byte_order
= LTT_GET_BO(e
->tracefile
);
226 guint8 x
= *(guint8
*)(e
->data
+ f
->offset
);
231 return (guint64
)ltt_get_uint16(reverse_byte_order
, e
->data
+ f
->offset
);
234 return (guint64
)ltt_get_uint32(reverse_byte_order
, e
->data
+ f
->offset
);
237 return ltt_get_uint64(reverse_byte_order
, e
->data
+ f
->offset
);
240 g_critical("ltt_event_get_long_unsigned : field size %li unknown", f
->size
);
246 gint64
ltt_event_get_long_int(LttEvent
*e
, struct marker_field
*f
)
248 gboolean reverse_byte_order
;
249 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
250 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
252 reverse_byte_order
= LTT_GET_BO(e
->tracefile
);
258 gint8 x
= *(gint8
*)(e
->data
+ f
->offset
);
263 return (gint64
)ltt_get_int16(reverse_byte_order
, e
->data
+ f
->offset
);
266 return (gint64
)ltt_get_int32(reverse_byte_order
, e
->data
+ f
->offset
);
269 return ltt_get_int64(reverse_byte_order
, e
->data
+ f
->offset
);
272 g_critical("ltt_event_get_long_int : field size %li unknown", f
->size
);
279 float ltt_event_get_float(LttEvent
*e
, struct marker_field
*f
)
281 gboolean reverse_byte_order
;
282 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
283 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
285 g_assert(LTT_HAS_FLOAT(e
->tracefile
));
286 reverse_byte_order
= LTT_GET_FLOAT_BO(e
->tracefile
);
289 g_assert(f
->field_type
.type_class
== LTT_FLOAT
&& f
->size
== 4);
291 if(reverse_byte_order
== 0) return *(float *)(e
->data
+ f
->offset
);
293 void *ptr
= e
->data
+ f
->offset
;
294 guint32 value
= bswap_32(*(guint32
*)ptr
);
295 return *(float*)&value
;
299 double ltt_event_get_double(LttEvent
*e
, struct marker_field
*f
)
301 gboolean reverse_byte_order
;
302 if(unlikely(f
->attributes
& LTT_ATTRIBUTE_NETWORK_BYTE_ORDER
)) {
303 reverse_byte_order
= (g_ntohs(0x1) != 0x1);
305 g_assert(LTT_HAS_FLOAT(e
->tracefile
));
306 reverse_byte_order
= LTT_GET_FLOAT_BO(e
->tracefile
);
310 return ltt_event_get_float(e
, f
);
312 g_assert(f
->field_type
.type_class
== LTT_FLOAT
&& f
->size
== 8);
314 if(reverse_byte_order
== 0) return *(double *)(e
->data
+ f
->offset
);
316 void *ptr
= e
->data
+ f
->offset
;
317 guint64 value
= bswap_64(*(guint64
*)ptr
);
318 return *(double*)&value
;
323 /*****************************************************************************
324 * The string obtained is only valid until the next read from
325 * the same tracefile. We reference directly the buffers.
326 ****************************************************************************/
327 gchar
*ltt_event_get_string(LttEvent
*e
, struct marker_field
*f
)
329 g_assert(f
->type
== LTT_TYPE_STRING
);
331 //caused memory leaks
332 //return (gchar*)g_strdup((gchar*)(e->data + f->offset));
333 return (gchar
*)(e
->data
+ f
->offset
);