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_position : get the event's position
188 * e : an instance of an event type
189 * ep : a pointer to event's position structure
190 ****************************************************************************/
192 void ltt_event_position(LttEvent
*e
, LttEventPosition
*ep
)
194 ep
->block_num
= e
->which_block
;
195 ep
->event_num
= e
->which_event
;
196 ep
->event_time
= e
->event_time
;
197 ep
->event_cycle_count
= e
->event_cycle_count
;
198 ep
->heart_beat_number
= e
->tracefile
->cur_heart_beat_number
;
199 ep
->old_position
= FALSE
;
200 ep
->event_offset
= e
->data
- e
->tracefile
->buffer
- EVENT_HEADER_SIZE
;
201 ep
->tf
= e
->tracefile
;
204 /*****************************************************************************
206 * ltt_event_position_get : get the block number and index of the event
208 * ep : a pointer to event's position structure
209 * block_number : the block number of the event
210 * index_in_block : the index of the event within the block
211 ****************************************************************************/
213 void ltt_event_position_get(LttEventPosition
*ep
,
214 unsigned *block_number
, unsigned *index_in_block
, LttTracefile
** tf
)
216 *block_number
= ep
->block_num
;
217 *index_in_block
= ep
->event_num
;
221 /*****************************************************************************
223 * ltt_event_position_set : set the block number and index of the event
225 * ep : a pointer to event's position structure
226 * block_number : the block number of the event
227 * index_in_block : the index of the event within the block
228 ****************************************************************************/
230 void ltt_event_position_set(LttEventPosition
*ep
,
231 unsigned block_number
, unsigned index_in_block
)
233 ep
->block_num
= block_number
;
234 ep
->event_num
= index_in_block
;
237 /*****************************************************************************
239 * ltt_event_cpu_i: get the cpu id where the event happens
241 * e : an instance of an event type
243 * unsigned : the cpu id
244 ****************************************************************************/
246 unsigned ltt_event_cpu_id(LttEvent
*e
)
248 return (unsigned)atoi(e
->tracefile
->name
);
251 /*****************************************************************************
253 * ltt_event_data : get the raw data for the event
255 * e : an instance of an event type
257 * void * : pointer to the raw data for the event
258 ****************************************************************************/
260 void *ltt_event_data(LttEvent
*e
)
265 /*****************************************************************************
267 * ltt_event_field_element_number
268 * : The number of elements in a sequence field is specific
269 * to each event. This function returns the number of
270 * elements for an array or sequence field in an event.
272 * e : an instance of an event type
273 * f : a field of the instance
275 * unsigned : the number of elements for an array/sequence field
276 ****************************************************************************/
278 unsigned ltt_event_field_element_number(LttEvent
*e
, LttField
*f
)
280 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
281 f
->field_type
->type_class
!= LTT_SEQUENCE
)
284 if(f
->field_type
->type_class
== LTT_ARRAY
)
285 return f
->field_type
->element_number
;
286 return (unsigned) getIntNumber(f
->sequ_number_size
, e
+ f
->offset_root
);
289 /*****************************************************************************
291 * ltt_event_field_element_select
292 * : Set the currently selected element for a sequence or
295 * e : an instance of an event type
296 * f : a field of the instance
297 * i : the ith element
298 ****************************************************************************/
300 void ltt_event_field_element_select(LttEvent
*e
, LttField
*f
, unsigned i
)
302 unsigned element_number
;
307 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
308 f
->field_type
->type_class
!= LTT_SEQUENCE
)
311 element_number
= ltt_event_field_element_number(e
,f
);
312 if((element_number
-1) < i
|| i
< 0) return;
316 evD
= e
->data
+ f
->offset_root
;
319 size
+= ltt_event_refresh_fields(f
->offset_root
+size
,size
, fld
, evD
+size
);
322 f
->current_element
= i
- 1;
325 /*****************************************************************************
326 * These functions extract data from an event after architecture specific
328 ****************************************************************************/
330 unsigned ltt_event_get_unsigned(LttEvent
*e
, LttField
*f
)
332 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
333 e
->tracefile
->trace
->system_description
->endian
? 0:1;
334 LttTypeEnum t
= f
->field_type
->type_class
;
336 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
337 g_error("The type of the field is not unsigned int\n");
339 if(f
->field_size
== 1){
340 uint8_t x
= *(uint8_t*)(e
->data
+ f
->offset_root
);
341 return (unsigned int) x
;
342 }else if(f
->field_size
== 2){
343 uint16_t x
= *(uint16_t*)(e
->data
+ f
->offset_root
);
344 return (unsigned int) (revFlag
? BREV16(x
): x
);
345 }else if(f
->field_size
== 4){
346 uint32_t x
= *(uint32_t*)(e
->data
+ f
->offset_root
);
347 return (unsigned int) (revFlag
? BREV32(x
): x
);
348 }else if(f
->field_size
== 8){
349 uint64_t x
= *(uint64_t*)(e
->data
+ f
->offset_root
);
350 return (unsigned int) (revFlag
? BREV64(x
): x
);
354 int ltt_event_get_int(LttEvent
*e
, LttField
*f
)
356 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
357 e
->tracefile
->trace
->system_description
->endian
? 0:1;
359 if(f
->field_type
->type_class
!= LTT_INT
)
360 g_error("The type of the field is not int\n");
362 if(f
->field_size
== 1){
363 int8_t x
= *(int8_t*)(e
->data
+ f
->offset_root
);
365 }else if(f
->field_size
== 2){
366 int16_t x
= *(int16_t*)(e
->data
+ f
->offset_root
);
367 return (int) (revFlag
? BREV16(x
): x
);
368 }else if(f
->field_size
== 4){
369 int32_t x
= *(int32_t*)(e
->data
+ f
->offset_root
);
370 return (int) (revFlag
? BREV32(x
): x
);
371 }else if(f
->field_size
== 8){
372 int64_t x
= *(int64_t*)(e
->data
+ f
->offset_root
);
373 return (int) (revFlag
? BREV64(x
): x
);
377 unsigned long ltt_event_get_long_unsigned(LttEvent
*e
, LttField
*f
)
379 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
380 e
->tracefile
->trace
->system_description
->endian
? 0:1;
381 LttTypeEnum t
= f
->field_type
->type_class
;
383 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
384 g_error("The type of the field is not unsigned long\n");
386 if(f
->field_size
== 1){
387 uint8_t x
= *(uint8_t*)(e
->data
+ f
->offset_root
);
388 return (unsigned long) x
;
389 }else if(f
->field_size
== 2){
390 uint16_t x
= *(uint16_t*)(e
->data
+ f
->offset_root
);
391 return (unsigned long) (revFlag
? BREV16(x
): x
);
392 }else if(f
->field_size
== 4){
393 uint32_t x
= *(uint32_t*)(e
->data
+ f
->offset_root
);
394 return (unsigned long) (revFlag
? BREV32(x
): x
);
395 }else if(f
->field_size
== 8){
396 uint64_t x
= *(uint64_t*)(e
->data
+ f
->offset_root
);
397 return (unsigned long) (revFlag
? BREV64(x
): x
);
401 long int ltt_event_get_long_int(LttEvent
*e
, LttField
*f
)
403 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
404 e
->tracefile
->trace
->system_description
->endian
? 0:1;
406 if( f
->field_type
->type_class
!= LTT_INT
)
407 g_error("The type of the field is not long int\n");
409 if(f
->field_size
== 1){
410 int8_t x
= *(int8_t*)(e
->data
+ f
->offset_root
);
412 }else if(f
->field_size
== 2){
413 int16_t x
= *(int16_t*)(e
->data
+ f
->offset_root
);
414 return (long) (revFlag
? BREV16(x
): x
);
415 }else if(f
->field_size
== 4){
416 int32_t x
= *(int32_t*)(e
->data
+ f
->offset_root
);
417 return (long) (revFlag
? BREV32(x
): x
);
418 }else if(f
->field_size
== 8){
419 int64_t x
= *(int64_t*)(e
->data
+ f
->offset_root
);
420 return (long) (revFlag
? BREV64(x
): x
);
424 float ltt_event_get_float(LttEvent
*e
, LttField
*f
)
426 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
427 e
->tracefile
->trace
->system_description
->endian
? 0:1;
429 if(f
->field_type
->type_class
!= LTT_FLOAT
||
430 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 4))
431 g_error("The type of the field is not float\n");
433 if(revFlag
== 0) return *(float *)(e
->data
+ f
->offset_root
);
436 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 4);
437 aInt
= ___swab32(aInt
);
438 return *((float*)&aInt
);
442 double ltt_event_get_double(LttEvent
*e
, LttField
*f
)
444 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
445 e
->tracefile
->trace
->system_description
->endian
? 0:1;
447 if(f
->field_type
->type_class
!= LTT_FLOAT
||
448 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 8))
449 g_error("The type of the field is not double\n");
451 if(revFlag
== 0) return *(double *)(e
->data
+ f
->offset_root
);
454 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 8);
455 aInt
= ___swab64(aInt
);
456 return *((double *)&aInt
);
460 /*****************************************************************************
461 * The string obtained is only valid until the next read from
462 * the same tracefile.
463 ****************************************************************************/
465 char *ltt_event_get_string(LttEvent
*e
, LttField
*f
)
467 if(f
->field_type
->type_class
!= LTT_STRING
)
468 g_error("The field contains no string\n");
469 return (char*)g_strdup((char*)(e
->data
+ f
->offset_root
));
This page took 0.040946 seconds and 4 git commands to generate.