3 #include <linux/byteorder/swab.h>
4 #include <ltt/LTTTypes.h>
8 /*****************************************************************************
10 * ltt_event_eventtype_id: get event type id
11 * (base id + position of the event)
13 * e : an instance of an event type
15 * unsigned : event type id
16 ****************************************************************************/
18 unsigned ltt_event_eventtype_id(LttEvent
*e
)
20 return (unsigned) e
->event_id
;
23 /*****************************************************************************
25 * ltt_event_facility : get the facility of the event
27 * e : an instance of an event type
29 * LttFacility * : the facility of the event
30 ****************************************************************************/
32 LttFacility
*ltt_event_facility(LttEvent
*e
)
34 LttTrace
* trace
= e
->tracefile
->trace
;
35 unsigned id
= e
->event_id
;
36 return ltt_trace_facility_by_id(trace
,id
);
39 /*****************************************************************************
41 * ltt_event_eventtype : get the event type of the event
43 * e : an instance of an event type
45 * LttEventType * : the event type of the event
46 ****************************************************************************/
48 LttEventType
*ltt_event_eventtype(LttEvent
*e
)
50 LttFacility
* facility
= ltt_event_facility(e
);
51 if(!facility
) return NULL
;
52 return facility
->events
[e
->event_id
- facility
->base_id
];
55 /*****************************************************************************
57 * ltt_event_field : get the root field of the event
59 * e : an instance of an event type
61 * LttField * : the root field of the event
62 ****************************************************************************/
64 LttField
*ltt_event_field(LttEvent
*e
)
66 LttEventType
* event_type
= ltt_event_eventtype(e
);
67 if(!event_type
) return NULL
;
68 return event_type
->root_field
;
71 /*****************************************************************************
73 * ltt_event_time : get the time of the event
75 * e : an instance of an event type
77 * LttTime : the time of the event
78 ****************************************************************************/
80 LttTime
ltt_event_time(LttEvent
*e
)
85 /*****************************************************************************
87 * ltt_event_time : get the cycle count of the event
89 * e : an instance of an event type
91 * LttCycleCount : the cycle count of the event
92 ****************************************************************************/
94 LttCycleCount
ltt_event_cycle_count(LttEvent
*e
)
96 return e
->event_cycle_count
;
99 /*****************************************************************************
101 * ltt_event_cpu_i: get the cpu id where the event happens
103 * e : an instance of an event type
105 * unsigned : the cpu id
106 ****************************************************************************/
108 unsigned ltt_event_cpu_id(LttEvent
*e
)
110 return (unsigned)atoi(e
->tracefile
->name
);
113 /*****************************************************************************
115 * ltt_event_data : get the raw data for the event
117 * e : an instance of an event type
119 * void * : pointer to the raw data for the event
120 ****************************************************************************/
122 void *ltt_event_data(LttEvent
*e
)
127 /*****************************************************************************
129 * ltt_event_field_element_number
130 * : The number of elements in a sequence field is specific
131 * to each event. This function returns the number of
132 * elements for an array or sequence field in an event.
134 * e : an instance of an event type ????
135 * f : a field of the instance
137 * unsigned : the number of elements for an array/sequence field
138 ****************************************************************************/
140 unsigned ltt_event_field_element_number(LttEvent
*e
, LttField
*f
)
142 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
143 f
->field_type
->type_class
!= LTT_SEQUENCE
)
146 return f
->field_type
->element_number
;
149 /*****************************************************************************
151 * ltt_event_field_element_select
152 * : Set the currently selected element for a sequence or
155 * e : an instance of an event type ????
156 * f : a field of the instance
157 * i : the ith element
158 ****************************************************************************/
160 void ltt_event_field_element_select(LttEvent
*e
, LttField
*f
, unsigned i
)
162 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
163 f
->field_type
->type_class
!= LTT_SEQUENCE
)
166 if(f
->field_type
->element_number
< i
|| i
== 0) return;
168 f
->current_element
= i
- 1;
171 /*****************************************************************************
172 * These functions extract data from an event after architecture specific
174 ****************************************************************************/
176 unsigned ltt_event_get_unsigned(LttEvent
*e
, LttField
*f
)
178 LttArchSize rSize
= e
->tracefile
->trace
->system_description
->size
;
179 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
180 e
->tracefile
->trace
->system_description
->endian
? 0:1;
181 LttTypeEnum t
= f
->field_type
->type_class
;
183 if(t
!= LTT_UINT
|| t
!= LTT_ENUM
)
184 g_error("The type of the field is not unsigned int\n");
186 if(rSize
== LTT_LP32
){
187 if(f
->field_size
!= 2)
188 g_error("The type of the field is not unsigned int: uint16_t\n");
190 uint16_t x
= *(uint16_t *)(e
->data
+ f
->offset_root
);
191 return (unsigned) (revFlag
? BREV16(x
) : x
);
193 }else if(rSize
== LTT_ILP32
|| rSize
== LTT_LP64
){
194 if(f
->field_size
!= 4)
195 g_error("The type of the field is not unsigned int: uint32_t\n");
197 uint32_t x
= *(uint32_t *)(e
->data
+ f
->offset_root
);
198 return (unsigned) (revFlag
? BREV32(x
): x
);
200 }else if(rSize
== LTT_ILP64
){
201 if(f
->field_size
!= 8)
202 g_error("The type of the field is not unsigned int: uint64_t\n");
204 uint64_t x
= *(uint64_t *)(e
->data
+ f
->offset_root
);
205 return (unsigned) (revFlag
? BREV64(x
): x
);
210 int ltt_event_get_int(LttEvent
*e
, LttField
*f
)
212 LttArchSize rSize
= e
->tracefile
->trace
->system_description
->size
;
213 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
214 e
->tracefile
->trace
->system_description
->endian
? 0:1;
216 if(f
->field_type
->type_class
!= LTT_INT
)
217 g_error("The type of the field is not int\n");
219 if(rSize
== LTT_LP32
){
220 if(f
->field_size
!= 2)
221 g_error("The type of the field is not int: int16_t\n");
223 int16_t x
= *(int16_t *)(e
->data
+ f
->offset_root
);
224 return (int) (revFlag
? BREV16(x
) : x
);
226 }else if(rSize
== LTT_ILP32
|| rSize
== LTT_LP64
){
227 if(f
->field_size
!= 4)
228 g_error("The type of the field is not int: int32_t\n");
230 int32_t x
= *(int32_t *)(e
->data
+ f
->offset_root
);
231 return (int) (revFlag
? BREV32(x
): x
);
233 }else if(rSize
== LTT_ILP64
){
234 if(f
->field_size
!= 8)
235 g_error("The type of the field is not int: int64_t\n");
237 int64_t x
= *(int64_t *)(e
->data
+ f
->offset_root
);
238 return (int) (revFlag
? BREV64(x
): x
);
243 unsigned long ltt_event_get_long_unsigned(LttEvent
*e
, LttField
*f
)
245 LttArchSize rSize
= e
->tracefile
->trace
->system_description
->size
;
246 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
247 e
->tracefile
->trace
->system_description
->endian
? 0:1;
248 LttTypeEnum t
= f
->field_type
->type_class
;
250 if(t
!= LTT_UINT
|| t
!= LTT_ENUM
)
251 g_error("The type of the field is not unsigned long\n");
253 if(rSize
== LTT_LP32
|| rSize
== LTT_ILP32
){
254 if(f
->field_size
!= 4)
255 g_error("The type of the field is not unsigned long: uint32_t\n");
257 uint32_t x
= *(uint32_t *)(e
->data
+ f
->offset_root
);
258 return (unsigned long) (revFlag
? BREV32(x
) : x
);
260 }else if(rSize
== LTT_LP64
|| rSize
== LTT_ILP64
){
261 if(f
->field_size
!= 8)
262 g_error("The type of the field is not unsigned long: uint64_t\n");
264 uint64_t x
= *(uint64_t *)(e
->data
+ f
->offset_root
);
265 return (unsigned long) (revFlag
? BREV64(x
): x
);
270 long int ltt_event_get_long_int(LttEvent
*e
, LttField
*f
)
272 LttArchSize rSize
= e
->tracefile
->trace
->system_description
->size
;
273 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
274 e
->tracefile
->trace
->system_description
->endian
? 0:1;
276 if( f
->field_type
->type_class
!= LTT_INT
)
277 g_error("The type of the field is not long int\n");
279 if(rSize
== LTT_LP32
|| rSize
== LTT_ILP32
){
280 if(f
->field_size
!= 4)
281 g_error("The type of the field is not long int: int32_t\n");
283 int32_t x
= *(int32_t *)(e
->data
+ f
->offset_root
);
284 return (long) (revFlag
? BREV32(x
) : x
);
286 }else if(rSize
== LTT_LP64
|| rSize
== LTT_ILP64
){
287 if(f
->field_size
!= 8)
288 g_error("The type of the field is not long int: int64_t\n");
290 int64_t x
= *(int64_t *)(e
->data
+ f
->offset_root
);
291 return (long) (revFlag
? BREV64(x
): x
);
296 float ltt_event_get_float(LttEvent
*e
, LttField
*f
)
298 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
299 e
->tracefile
->trace
->system_description
->endian
? 0:1;
301 if(f
->field_type
->type_class
!= LTT_FLOAT
||
302 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 4))
303 g_error("The type of the field is not float\n");
305 if(revFlag
== 0) return *(float *)(e
->data
+ f
->offset_root
);
308 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 4);
309 aInt
= ___swab32(aInt
);
310 return *((float*)&aInt
);
314 double ltt_event_get_double(LttEvent
*e
, LttField
*f
)
316 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
317 e
->tracefile
->trace
->system_description
->endian
? 0:1;
319 if(f
->field_type
->type_class
!= LTT_FLOAT
||
320 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 8))
321 g_error("The type of the field is not double\n");
323 if(revFlag
== 0) return *(double *)(e
->data
+ f
->offset_root
);
326 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 8);
327 aInt
= ___swab64(aInt
);
328 return *((double *)&aInt
);
332 /*****************************************************************************
333 * The string obtained is only valid until the next read from
334 * the same tracefile. ????
335 ****************************************************************************/
337 char *ltt_event_get_string(LttEvent
*e
, LttField
*f
)
339 if(f
->field_type
->type_class
!= LTT_STRING
)
340 g_error("The field contains no string\n");
341 return (char*)g_strdup((char*)(e
->data
+ f
->offset_root
));
This page took 0.0402090000000001 seconds and 4 git commands to generate.