3 #include <linux/byteorder/swab.h>
9 /*****************************************************************************
11 * ltt_facility_eventtype_id: get event type id
12 * (base id + position of the event)
14 * e : an instance of an event type
16 * unsigned : event type id
17 ****************************************************************************/
19 unsigned ltt_event_eventtype_id(ltt_event
*e
)
21 return (unsigned) e
->event_id
;
24 /*****************************************************************************
26 * ltt_event_facility : get the facility of the event
28 * e : an instance of an event type
30 * ltt_facility * : the facility of the event
31 ****************************************************************************/
33 ltt_facility
*ltt_event_facility(ltt_event
*e
)
37 ptr
= (ptr_wrap
*)g_ptr_array_index(e
->tracefile
->eventtype_event_id
,
39 evT
= (ltt_eventtype
*)(ptr
->ptr
);
45 /*****************************************************************************
47 * ltt_event_eventtype : get the event type of the event
49 * e : an instance of an event type
51 * ltt_eventtype * : the event type of the event
52 ****************************************************************************/
54 ltt_eventtype
*ltt_event_eventtype(ltt_event
*e
)
57 ptr
= (ptr_wrap
*)g_ptr_array_index(e
->tracefile
->eventtype_event_id
,
59 return (ltt_eventtype
*)(ptr
->ptr
);
62 /*****************************************************************************
64 * ltt_event_time : get the time of the event
66 * e : an instance of an event type
68 * ltt_time : the time of the event
69 ****************************************************************************/
71 ltt_time
ltt_event_time(ltt_event
*e
)
73 return getEventTime(e
->tracefile
);
76 /*****************************************************************************
78 * ltt_event_time : get the cycle count of the event
80 * e : an instance of an event type
82 * ltt_time : the cycle count of the event
83 ****************************************************************************/
85 ltt_cycle_count
ltt_event_cycle_count(ltt_event
*e
)
87 return e
->cycle_count
;
90 /*****************************************************************************
92 * ltt_event_cpu_i: get the cpu id where the event happens
94 * e : an instance of an event type
96 * unsigned : the cpu id
97 ****************************************************************************/
99 unsigned ltt_event_cpu_id(ltt_event
*e
)
101 return e
->tracefile
->trace_header
->cpu_id
;
104 /*****************************************************************************
106 * ltt_event_cpu_i: get the name of the system where the event happens
108 * e : an instance of an event type
110 * char * : the name of the system
111 ****************************************************************************/
113 char *ltt_event_system_name(ltt_event
*e
)
115 return e
->tracefile
->trace_header
->system_name
;
118 /*****************************************************************************
120 * ltt_event_data : get the raw data for the event
122 * e : an instance of an event type
124 * void * : pointer to the raw data for the event
125 ****************************************************************************/
127 void *ltt_event_data(ltt_event
*e
)
132 /*****************************************************************************
134 * ltt_event_field_element_number
135 * : The number of elements in a sequence field is specific
136 * to each event. This function returns the number of
137 * elements for an array or sequence field in an event.
139 * e : an instance of an event type ????
140 * f : a field of the instance
142 * unsigned : the number of elements for an array/sequence field
143 ****************************************************************************/
145 unsigned ltt_event_field_element_number(ltt_event
*e
, ltt_field
*f
)
147 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
148 f
->field_type
->type_class
!= LTT_SEQUENCE
)
151 return f
->field_type
->element_number
;
154 /*****************************************************************************
156 * ltt_event_field_element_select
157 * : Set the currently selected element for a sequence or
160 * e : an instance of an event type ????
161 * f : a field of the instance
162 * i : the ith element
164 * int : ???? error number
165 ****************************************************************************/
167 int ltt_event_field_element_select(ltt_event
*e
, ltt_field
*f
, unsigned i
)
169 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
170 f
->field_type
->type_class
!= LTT_SEQUENCE
)
173 if(f
->field_type
->element_number
< i
|| i
== 0) return -1; //????
175 f
->current_element
= i
- 1;
179 /*****************************************************************************
180 * These functions extract data from an event after architecture specific
182 ****************************************************************************/
184 unsigned ltt_event_get_unsigned(ltt_event
*e
, ltt_field
*f
)
186 ltt_arch_size rSize
= e
->tracefile
->trace_header
->arch_size
;
187 int revFlag
= e
->tracefile
->my_arch_endian
==
188 e
->tracefile
->trace_header
->arch_endian
? 0:1;
189 ltt_type_enum t
= f
->field_type
->type_class
;
191 if(t
!= LTT_UINT
|| t
!= LTT_ENUM
)
192 g_error("The type of the field is not unsigned int\n");
194 if(rSize
== LTT_LP32
){
195 if(f
->field_size
!= 2)
196 g_error("The type of the field is not unsigned int: uint16_t\n");
198 uint16_t x
= *(uint16_t *)(e
->data
+ f
->offset_root
);
199 return (unsigned) (revFlag
? BREV16(x
) : x
);
201 }else if(rSize
== LTT_ILP32
|| rSize
== LTT_LP64
){
202 if(f
->field_size
!= 4)
203 g_error("The type of the field is not unsigned int: uint32_t\n");
205 uint32_t x
= *(uint32_t *)(e
->data
+ f
->offset_root
);
206 return (unsigned) (revFlag
? BREV32(x
): x
);
208 }else if(rSize
== LTT_ILP64
){
209 if(f
->field_size
!= 8)
210 g_error("The type of the field is not unsigned int: uint64_t\n");
212 uint64_t x
= *(uint64_t *)(e
->data
+ f
->offset_root
);
213 return (unsigned) (revFlag
? BREV64(x
): x
);
218 int ltt_event_get_int(ltt_event
*e
, ltt_field
*f
)
220 ltt_arch_size rSize
= e
->tracefile
->trace_header
->arch_size
;
221 int revFlag
= e
->tracefile
->my_arch_endian
==
222 e
->tracefile
->trace_header
->arch_endian
? 0:1;
224 if(f
->field_type
->type_class
!= LTT_INT
)
225 g_error("The type of the field is not int\n");
227 if(rSize
== LTT_LP32
){
228 if(f
->field_size
!= 2)
229 g_error("The type of the field is not int: int16_t\n");
231 int16_t x
= *(int16_t *)(e
->data
+ f
->offset_root
);
232 return (int) (revFlag
? BREV16(x
) : x
);
234 }else if(rSize
== LTT_ILP32
|| rSize
== LTT_LP64
){
235 if(f
->field_size
!= 4)
236 g_error("The type of the field is not int: int32_t\n");
238 int32_t x
= *(int32_t *)(e
->data
+ f
->offset_root
);
239 return (int) (revFlag
? BREV32(x
): x
);
241 }else if(rSize
== LTT_ILP64
){
242 if(f
->field_size
!= 8)
243 g_error("The type of the field is not int: int64_t\n");
245 int64_t x
= *(int64_t *)(e
->data
+ f
->offset_root
);
246 return (int) (revFlag
? BREV64(x
): x
);
251 unsigned long ltt_event_get_long_unsigned(ltt_event
*e
, ltt_field
*f
)
253 ltt_arch_size rSize
= e
->tracefile
->trace_header
->arch_size
;
254 int revFlag
= e
->tracefile
->my_arch_endian
==
255 e
->tracefile
->trace_header
->arch_endian
? 0:1;
256 ltt_type_enum t
= f
->field_type
->type_class
;
258 if(t
!= LTT_UINT
|| t
!= LTT_ENUM
)
259 g_error("The type of the field is not unsigned long\n");
261 if(rSize
== LTT_LP32
|| rSize
== LTT_ILP32
){
262 if(f
->field_size
!= 4)
263 g_error("The type of the field is not unsigned long: uint32_t\n");
265 uint32_t x
= *(uint32_t *)(e
->data
+ f
->offset_root
);
266 return (unsigned long) (revFlag
? BREV32(x
) : x
);
268 }else if(rSize
== LTT_LP64
|| rSize
== LTT_ILP64
){
269 if(f
->field_size
!= 8)
270 g_error("The type of the field is not unsigned long: uint64_t\n");
272 uint64_t x
= *(uint64_t *)(e
->data
+ f
->offset_root
);
273 return (unsigned long) (revFlag
? BREV64(x
): x
);
278 long int ltt_event_get_long_int(ltt_event
*e
, ltt_field
*f
)
280 ltt_arch_size rSize
= e
->tracefile
->trace_header
->arch_size
;
281 int revFlag
= e
->tracefile
->my_arch_endian
==
282 e
->tracefile
->trace_header
->arch_endian
? 0:1;
284 if( f
->field_type
->type_class
!= LTT_INT
)
285 g_error("The type of the field is not long int\n");
287 if(rSize
== LTT_LP32
|| rSize
== LTT_ILP32
){
288 if(f
->field_size
!= 4)
289 g_error("The type of the field is not long int: int32_t\n");
291 int32_t x
= *(int32_t *)(e
->data
+ f
->offset_root
);
292 return (long) (revFlag
? BREV32(x
) : x
);
294 }else if(rSize
== LTT_LP64
|| rSize
== LTT_ILP64
){
295 if(f
->field_size
!= 8)
296 g_error("The type of the field is not long int: int64_t\n");
298 int64_t x
= *(int64_t *)(e
->data
+ f
->offset_root
);
299 return (long) (revFlag
? BREV64(x
): x
);
304 float ltt_event_get_float(ltt_event
*e
, ltt_field
*f
)
306 int revFlag
= e
->tracefile
->my_arch_endian
==
307 e
->tracefile
->trace_header
->arch_endian
? 0:1;
309 if(f
->field_type
->type_class
!= LTT_FLOAT
||
310 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 4))
311 g_error("The type of the field is not float\n");
313 if(revFlag
== 0) return *(float *)(e
->data
+ f
->offset_root
);
316 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 4);
317 aInt
= ___swab32(aInt
);
318 return *((float*)&aInt
);
322 double ltt_event_get_double(ltt_event
*e
, ltt_field
*f
)
324 int revFlag
= e
->tracefile
->my_arch_endian
==
325 e
->tracefile
->trace_header
->arch_endian
? 0:1;
327 if(f
->field_type
->type_class
!= LTT_FLOAT
||
328 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 8))
329 g_error("The type of the field is not double\n");
331 if(revFlag
== 0) return *(double *)(e
->data
+ f
->offset_root
);
334 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 8);
335 aInt
= ___swab64(aInt
);
336 return *((double *)&aInt
);
340 /*****************************************************************************
341 * The string obtained is only valid until the next read from
342 * the same tracefile. ????
343 ****************************************************************************/
345 char *ltt_event_get_string(ltt_event
*e
, ltt_field
*f
)
347 if(f
->field_type
->type_class
!= LTT_STRING
)
348 g_error("The field contains no string\n");
349 return (char*)g_strdup((char*)(e
->data
+ f
->offset_root
));
This page took 0.03784 seconds and 4 git commands to generate.