ad7e6c33366fb0e822b8dd2e19993cd1ece75b9e
3 #include <linux/byteorder/swab.h>
4 #include <ltt/LTTTypes.h>
8 /*****************************************************************************
10 * ltt_event_refresh_fields : refresh fields of an event
12 * offsetRoot : offset from the root
13 * offsetParent : offset from the parrent
17 * int : size of the field
18 ****************************************************************************/
20 int ltt_event_refresh_fields(int offsetRoot
,int offsetParent
,
21 LttField
* fld
, void *evD
)
23 int size
, size1
, element_number
, i
, offset1
, offset2
;
24 LttType
* type
= fld
->field_type
;
26 if(type
->type_class
!= LTT_STRUCT
&& type
->type_class
!= LTT_ARRAY
&&
27 type
->type_class
!= LTT_SEQUENCE
&& type
->type_class
!= LTT_STRING
){
28 size
= fld
->field_size
;
29 }else if(type
->type_class
== LTT_ARRAY
){
30 element_number
= (int) type
->element_number
;
31 if(fld
->field_fixed
== 0){// has string or sequence
33 for(i
=0;i
<element_number
;i
++){
34 size
+= ltt_event_refresh_fields(offsetRoot
+size
,size
,
35 fld
->child
[0], evD
+size
);
37 }else size
= fld
->field_size
;
38 }else if(type
->type_class
== LTT_SEQUENCE
){
39 size1
= fld
->sequ_number_size
;
40 element_number
= getIntNumber(size1
,evD
);
41 type
->element_number
= element_number
;
42 if(fld
->element_size
> 0){
43 size
= element_number
* fld
->element_size
;
44 }else{//sequence has string or sequence
46 for(i
=0;i
<element_number
;i
++){
47 size
+= ltt_event_refresh_fields(offsetRoot
+size
+size1
,size
+size1
,
48 fld
->child
[0], evD
+size
+size1
);
52 }else if(type
->type_class
== LTT_STRING
){
53 size
= strlen((char*)evD
) + 1; //include end : '\0'
54 }else if(type
->type_class
== LTT_STRUCT
){
55 element_number
= (int) type
->element_number
;
56 if(fld
->field_fixed
== 0){
59 for(i
=0;i
<element_number
;i
++){
60 size
=ltt_event_refresh_fields(offset1
,offset2
,fld
->child
[i
],evD
+offset2
);
65 }else size
= fld
->field_size
;
68 fld
->offset_root
= offsetRoot
;
69 fld
->offset_parent
= offsetParent
;
70 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
71 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
72 fld
->field_size
= size
;
77 /*****************************************************************************
79 * ltt_event_eventtype_id: get event type id
80 * (base id + position of the event)
82 * e : an instance of an event type
84 * unsigned : event type id
85 ****************************************************************************/
87 unsigned ltt_event_eventtype_id(LttEvent
*e
)
89 return (unsigned) e
->event_id
;
92 /*****************************************************************************
94 * ltt_event_facility : get the facility of the event
96 * e : an instance of an event type
98 * LttFacility * : the facility of the event
99 ****************************************************************************/
101 LttFacility
*ltt_event_facility(LttEvent
*e
)
103 LttTrace
* trace
= e
->tracefile
->trace
;
104 unsigned id
= e
->event_id
;
105 return ltt_trace_facility_by_id(trace
,id
);
108 /*****************************************************************************
110 * ltt_event_eventtype : get the event type of the event
112 * e : an instance of an event type
114 * LttEventType * : the event type of the event
115 ****************************************************************************/
117 LttEventType
*ltt_event_eventtype(LttEvent
*e
)
119 LttFacility
* facility
= ltt_event_facility(e
);
120 if(!facility
) return NULL
;
121 return facility
->events
[e
->event_id
- facility
->base_id
];
124 /*****************************************************************************
126 * ltt_event_field : get the root field of the event
128 * e : an instance of an event type
130 * LttField * : the root field of the event
131 ****************************************************************************/
133 LttField
*ltt_event_field(LttEvent
*e
)
136 LttEventType
* event_type
= ltt_event_eventtype(e
);
137 if(!event_type
) return NULL
;
138 field
= event_type
->root_field
;
139 if(!field
) return NULL
;
141 //check if the field need refresh
142 if(e
->which_block
!= event_type
->latest_block
||
143 e
->which_event
!= event_type
->latest_event
){
145 event_type
->latest_block
= e
->which_block
;
146 event_type
->latest_event
= e
->which_event
;
148 if(field
->field_fixed
== 1)return field
;
151 ltt_event_refresh_fields(0, 0, field
, e
->data
);
156 /*****************************************************************************
158 * ltt_event_time : get the time of the event
160 * e : an instance of an event type
162 * LttTime : the time of the event
163 ****************************************************************************/
165 LttTime
ltt_event_time(LttEvent
*e
)
167 return e
->event_time
;
170 /*****************************************************************************
172 * ltt_event_time : get the cycle count of the event
174 * e : an instance of an event type
176 * LttCycleCount : the cycle count of the event
177 ****************************************************************************/
179 LttCycleCount
ltt_event_cycle_count(LttEvent
*e
)
181 return e
->event_cycle_count
;
184 /*****************************************************************************
186 * ltt_event_cpu_i: get the cpu id where the event happens
188 * e : an instance of an event type
190 * unsigned : the cpu id
191 ****************************************************************************/
193 unsigned ltt_event_cpu_id(LttEvent
*e
)
195 return (unsigned)atoi(e
->tracefile
->name
);
198 /*****************************************************************************
200 * ltt_event_data : get the raw data for the event
202 * e : an instance of an event type
204 * void * : pointer to the raw data for the event
205 ****************************************************************************/
207 void *ltt_event_data(LttEvent
*e
)
212 /*****************************************************************************
214 * ltt_event_field_element_number
215 * : The number of elements in a sequence field is specific
216 * to each event. This function returns the number of
217 * elements for an array or sequence field in an event.
219 * e : an instance of an event type
220 * f : a field of the instance
222 * unsigned : the number of elements for an array/sequence field
223 ****************************************************************************/
225 unsigned ltt_event_field_element_number(LttEvent
*e
, LttField
*f
)
227 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
228 f
->field_type
->type_class
!= LTT_SEQUENCE
)
231 if(f
->field_type
->type_class
== LTT_ARRAY
)
232 return f
->field_type
->element_number
;
233 return (unsigned) getIntNumber(f
->sequ_number_size
, e
+ f
->offset_root
);
236 /*****************************************************************************
238 * ltt_event_field_element_select
239 * : Set the currently selected element for a sequence or
242 * e : an instance of an event type
243 * f : a field of the instance
244 * i : the ith element
245 ****************************************************************************/
247 void ltt_event_field_element_select(LttEvent
*e
, LttField
*f
, unsigned i
)
249 unsigned element_number
;
254 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
255 f
->field_type
->type_class
!= LTT_SEQUENCE
)
258 element_number
= ltt_event_field_element_number(e
,f
);
259 if((element_number
-1) < i
|| i
< 0) return;
263 evD
= e
->data
+ f
->offset_root
;
266 size
+= ltt_event_refresh_fields(f
->offset_root
+size
,size
, fld
, evD
+size
);
269 f
->current_element
= i
- 1;
272 /*****************************************************************************
273 * These functions extract data from an event after architecture specific
275 ****************************************************************************/
277 unsigned ltt_event_get_unsigned(LttEvent
*e
, LttField
*f
)
279 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
280 e
->tracefile
->trace
->system_description
->endian
? 0:1;
281 LttTypeEnum t
= f
->field_type
->type_class
;
283 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
284 g_error("The type of the field is not unsigned int\n");
286 if(f
->field_size
== 1){
287 uint8_t x
= *(uint8_t*)(e
->data
+ f
->offset_root
);
288 return (unsigned int) x
;
289 }else if(f
->field_size
== 2){
290 uint16_t x
= *(uint16_t*)(e
->data
+ f
->offset_root
);
291 return (unsigned int) (revFlag
? BREV16(x
): x
);
292 }else if(f
->field_size
== 4){
293 uint32_t x
= *(uint32_t*)(e
->data
+ f
->offset_root
);
294 return (unsigned int) (revFlag
? BREV32(x
): x
);
295 }else if(f
->field_size
== 8){
296 uint64_t x
= *(uint64_t*)(e
->data
+ f
->offset_root
);
297 return (unsigned int) (revFlag
? BREV64(x
): x
);
301 int ltt_event_get_int(LttEvent
*e
, LttField
*f
)
303 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
304 e
->tracefile
->trace
->system_description
->endian
? 0:1;
306 if(f
->field_type
->type_class
!= LTT_INT
)
307 g_error("The type of the field is not int\n");
309 if(f
->field_size
== 1){
310 int8_t x
= *(int8_t*)(e
->data
+ f
->offset_root
);
312 }else if(f
->field_size
== 2){
313 int16_t x
= *(int16_t*)(e
->data
+ f
->offset_root
);
314 return (int) (revFlag
? BREV16(x
): x
);
315 }else if(f
->field_size
== 4){
316 int32_t x
= *(int32_t*)(e
->data
+ f
->offset_root
);
317 return (int) (revFlag
? BREV32(x
): x
);
318 }else if(f
->field_size
== 8){
319 int64_t x
= *(int64_t*)(e
->data
+ f
->offset_root
);
320 return (int) (revFlag
? BREV64(x
): x
);
324 unsigned long ltt_event_get_long_unsigned(LttEvent
*e
, LttField
*f
)
326 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
327 e
->tracefile
->trace
->system_description
->endian
? 0:1;
328 LttTypeEnum t
= f
->field_type
->type_class
;
330 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
331 g_error("The type of the field is not unsigned long\n");
333 if(f
->field_size
== 1){
334 uint8_t x
= *(uint8_t*)(e
->data
+ f
->offset_root
);
335 return (unsigned long) x
;
336 }else if(f
->field_size
== 2){
337 uint16_t x
= *(uint16_t*)(e
->data
+ f
->offset_root
);
338 return (unsigned long) (revFlag
? BREV16(x
): x
);
339 }else if(f
->field_size
== 4){
340 uint32_t x
= *(uint32_t*)(e
->data
+ f
->offset_root
);
341 return (unsigned long) (revFlag
? BREV32(x
): x
);
342 }else if(f
->field_size
== 8){
343 uint64_t x
= *(uint64_t*)(e
->data
+ f
->offset_root
);
344 return (unsigned long) (revFlag
? BREV64(x
): x
);
348 long int ltt_event_get_long_int(LttEvent
*e
, LttField
*f
)
350 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
351 e
->tracefile
->trace
->system_description
->endian
? 0:1;
353 if( f
->field_type
->type_class
!= LTT_INT
)
354 g_error("The type of the field is not long int\n");
356 if(f
->field_size
== 1){
357 int8_t x
= *(int8_t*)(e
->data
+ f
->offset_root
);
359 }else if(f
->field_size
== 2){
360 int16_t x
= *(int16_t*)(e
->data
+ f
->offset_root
);
361 return (long) (revFlag
? BREV16(x
): x
);
362 }else if(f
->field_size
== 4){
363 int32_t x
= *(int32_t*)(e
->data
+ f
->offset_root
);
364 return (long) (revFlag
? BREV32(x
): x
);
365 }else if(f
->field_size
== 8){
366 int64_t x
= *(int64_t*)(e
->data
+ f
->offset_root
);
367 return (long) (revFlag
? BREV64(x
): x
);
371 float ltt_event_get_float(LttEvent
*e
, LttField
*f
)
373 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
374 e
->tracefile
->trace
->system_description
->endian
? 0:1;
376 if(f
->field_type
->type_class
!= LTT_FLOAT
||
377 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 4))
378 g_error("The type of the field is not float\n");
380 if(revFlag
== 0) return *(float *)(e
->data
+ f
->offset_root
);
383 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 4);
384 aInt
= ___swab32(aInt
);
385 return *((float*)&aInt
);
389 double ltt_event_get_double(LttEvent
*e
, LttField
*f
)
391 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
392 e
->tracefile
->trace
->system_description
->endian
? 0:1;
394 if(f
->field_type
->type_class
!= LTT_FLOAT
||
395 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 8))
396 g_error("The type of the field is not double\n");
398 if(revFlag
== 0) return *(double *)(e
->data
+ f
->offset_root
);
401 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 8);
402 aInt
= ___swab64(aInt
);
403 return *((double *)&aInt
);
407 /*****************************************************************************
408 * The string obtained is only valid until the next read from
409 * the same tracefile.
410 ****************************************************************************/
412 char *ltt_event_get_string(LttEvent
*e
, LttField
*f
)
414 if(f
->field_type
->type_class
!= LTT_STRING
)
415 g_error("The field contains no string\n");
416 return (char*)g_strdup((char*)(e
->data
+ f
->offset_root
));
This page took 0.039042 seconds and 3 git commands to generate.