3 #include <linux/byteorder/swab.h>
7 #include "ltt-private.h"
11 /*****************************************************************************
13 * ltt_event_refresh_fields : refresh fields of an event
15 * offsetRoot : offset from the root
16 * offsetParent : offset from the parrent
20 * int : size of the field
21 ****************************************************************************/
23 int ltt_event_refresh_fields(int offsetRoot
,int offsetParent
,
24 LttField
* fld
, void *evD
)
26 int size
, size1
, element_number
, i
, offset1
, offset2
;
27 LttType
* type
= fld
->field_type
;
29 if(type
->type_class
!= LTT_STRUCT
&& type
->type_class
!= LTT_ARRAY
&&
30 type
->type_class
!= LTT_SEQUENCE
&& type
->type_class
!= LTT_STRING
){
31 size
= fld
->field_size
;
32 }else if(type
->type_class
== LTT_ARRAY
){
33 element_number
= (int) type
->element_number
;
34 if(fld
->field_fixed
== 0){// has string or sequence
36 for(i
=0;i
<element_number
;i
++){
37 size
+= ltt_event_refresh_fields(offsetRoot
+size
,size
,
38 fld
->child
[0], evD
+size
);
40 }else size
= fld
->field_size
;
41 }else if(type
->type_class
== LTT_SEQUENCE
){
42 size1
= fld
->sequ_number_size
;
43 element_number
= getIntNumber(size1
,evD
);
44 type
->element_number
= element_number
;
45 if(fld
->element_size
> 0){
46 size
= element_number
* fld
->element_size
;
47 }else{//sequence has string or sequence
49 for(i
=0;i
<element_number
;i
++){
50 size
+= ltt_event_refresh_fields(offsetRoot
+size
+size1
,size
+size1
,
51 fld
->child
[0], evD
+size
+size1
);
55 }else if(type
->type_class
== LTT_STRING
){
56 size
= strlen((char*)evD
) + 1; //include end : '\0'
57 }else if(type
->type_class
== LTT_STRUCT
){
58 element_number
= (int) type
->element_number
;
59 if(fld
->field_fixed
== 0){
62 for(i
=0;i
<element_number
;i
++){
63 size
=ltt_event_refresh_fields(offset1
,offset2
,fld
->child
[i
],evD
+offset2
);
68 }else size
= fld
->field_size
;
71 fld
->offset_root
= offsetRoot
;
72 fld
->offset_parent
= offsetParent
;
73 fld
->fixed_root
= (offsetRoot
==-1) ? 0 : 1;
74 fld
->fixed_parent
= (offsetParent
==-1) ? 0 : 1;
75 fld
->field_size
= size
;
80 /*****************************************************************************
82 * ltt_event_eventtype_id: get event type id
83 * (base id + position of the event)
85 * e : an instance of an event type
87 * unsigned : event type id
88 ****************************************************************************/
90 unsigned ltt_event_eventtype_id(LttEvent
*e
)
92 return (unsigned) e
->event_id
;
95 /*****************************************************************************
97 * ltt_event_facility : get the facility of the event
99 * e : an instance of an event type
101 * LttFacility * : the facility of the event
102 ****************************************************************************/
104 LttFacility
*ltt_event_facility(LttEvent
*e
)
106 LttTrace
* trace
= e
->tracefile
->trace
;
107 unsigned id
= e
->event_id
;
108 return ltt_trace_facility_by_id(trace
,id
);
111 /*****************************************************************************
113 * ltt_event_eventtype : get the event type of the event
115 * e : an instance of an event type
117 * LttEventType * : the event type of the event
118 ****************************************************************************/
120 LttEventType
*ltt_event_eventtype(LttEvent
*e
)
122 LttFacility
* facility
= ltt_event_facility(e
);
123 if(!facility
) return NULL
;
124 return facility
->events
[e
->event_id
- facility
->base_id
];
127 /*****************************************************************************
129 * ltt_event_field : get the root field of the event
131 * e : an instance of an event type
133 * LttField * : the root field of the event
134 ****************************************************************************/
136 LttField
*ltt_event_field(LttEvent
*e
)
139 LttEventType
* event_type
= ltt_event_eventtype(e
);
140 if(!event_type
) return NULL
;
141 field
= event_type
->root_field
;
142 if(!field
) return NULL
;
144 //check if the field need refresh
145 if(e
->which_block
!= event_type
->latest_block
||
146 e
->which_event
!= event_type
->latest_event
){
148 event_type
->latest_block
= e
->which_block
;
149 event_type
->latest_event
= e
->which_event
;
151 if(field
->field_fixed
== 1)return field
;
154 ltt_event_refresh_fields(0, 0, field
, e
->data
);
159 /*****************************************************************************
161 * ltt_event_time : get the time of the event
163 * e : an instance of an event type
165 * LttTime : the time of the event
166 ****************************************************************************/
168 LttTime
ltt_event_time(LttEvent
*e
)
170 return e
->event_time
;
173 /*****************************************************************************
175 * ltt_event_time : get the cycle count of the event
177 * e : an instance of an event type
179 * LttCycleCount : the cycle count of the event
180 ****************************************************************************/
182 LttCycleCount
ltt_event_cycle_count(LttEvent
*e
)
184 return e
->event_cycle_count
;
187 /*****************************************************************************
189 * ltt_event_position : get the event's position
191 * e : an instance of an event type
192 * ep : a pointer to event's position structure
193 ****************************************************************************/
195 void ltt_event_position(LttEvent
*e
, LttEventPosition
*ep
)
197 ep
->block_num
= e
->which_block
;
198 ep
->event_num
= e
->which_event
;
199 ep
->event_time
= e
->event_time
;
200 ep
->event_cycle_count
= e
->event_cycle_count
;
201 ep
->heart_beat_number
= e
->tracefile
->cur_heart_beat_number
;
202 ep
->old_position
= FALSE
;
203 ep
->event_offset
= e
->data
- e
->tracefile
->buffer
- EVENT_HEADER_SIZE
;
204 ep
->tf
= e
->tracefile
;
207 LttEventPosition
* ltt_event_position_new()
209 return g_new(LttEventPosition
, 1);
212 /*****************************************************************************
214 * ltt_event_position_get : get the block number and index of the event
216 * ep : a pointer to event's position structure
217 * block_number : the block number of the event
218 * index_in_block : the index of the event within the block
219 ****************************************************************************/
221 void ltt_event_position_get(LttEventPosition
*ep
,
222 unsigned *block_number
, unsigned *index_in_block
, LttTracefile
** tf
)
224 *block_number
= ep
->block_num
;
225 *index_in_block
= ep
->event_num
;
229 /*****************************************************************************
231 * ltt_event_position_set : set the block number and index of the event
233 * ep : a pointer to event's position structure
234 * block_number : the block number of the event
235 * index_in_block : the index of the event within the block
236 ****************************************************************************/
238 void ltt_event_position_set(LttEventPosition
*ep
,
239 unsigned block_number
, unsigned index_in_block
)
241 ep
->block_num
= block_number
;
242 ep
->event_num
= index_in_block
;
245 /*****************************************************************************
247 * ltt_event_cpu_i: get the cpu id where the event happens
249 * e : an instance of an event type
251 * unsigned : the cpu id
252 ****************************************************************************/
254 unsigned ltt_event_cpu_id(LttEvent
*e
)
256 char * c1
, * c2
, * c3
;
257 c1
= strrchr(e
->tracefile
->name
,'\\');
258 c2
= strrchr(e
->tracefile
->name
,'/');
259 if(c1
== NULL
&& c2
== NULL
){
260 return (unsigned)atoi(e
->tracefile
->name
);
261 }else if(c1
== NULL
){
263 return (unsigned)atoi(c2
);
264 }else if(c2
== NULL
){
266 return (unsigned)atoi(c1
);
268 c3
= (c1
> c2
) ? c1
: c2
;
270 return (unsigned)atoi(c3
);
274 /*****************************************************************************
276 * ltt_event_data : get the raw data for the event
278 * e : an instance of an event type
280 * void * : pointer to the raw data for the event
281 ****************************************************************************/
283 void *ltt_event_data(LttEvent
*e
)
288 /*****************************************************************************
290 * ltt_event_field_element_number
291 * : The number of elements in a sequence field is specific
292 * to each event. This function returns the number of
293 * elements for an array or sequence field in an event.
295 * e : an instance of an event type
296 * f : a field of the instance
298 * unsigned : the number of elements for an array/sequence field
299 ****************************************************************************/
301 unsigned ltt_event_field_element_number(LttEvent
*e
, LttField
*f
)
303 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
304 f
->field_type
->type_class
!= LTT_SEQUENCE
)
307 if(f
->field_type
->type_class
== LTT_ARRAY
)
308 return f
->field_type
->element_number
;
309 return (unsigned) getIntNumber(f
->sequ_number_size
, e
+ f
->offset_root
);
312 /*****************************************************************************
314 * ltt_event_field_element_select
315 * : Set the currently selected element for a sequence or
318 * e : an instance of an event type
319 * f : a field of the instance
320 * i : the ith element
321 ****************************************************************************/
323 void ltt_event_field_element_select(LttEvent
*e
, LttField
*f
, unsigned i
)
325 unsigned element_number
;
330 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
331 f
->field_type
->type_class
!= LTT_SEQUENCE
)
334 element_number
= ltt_event_field_element_number(e
,f
);
335 if((element_number
-1) < i
|| i
< 0) return;
339 evD
= e
->data
+ f
->offset_root
;
342 size
+= ltt_event_refresh_fields(f
->offset_root
+size
,size
, fld
, evD
+size
);
345 f
->current_element
= i
- 1;
348 /*****************************************************************************
349 * These functions extract data from an event after architecture specific
351 ****************************************************************************/
353 unsigned ltt_event_get_unsigned(LttEvent
*e
, LttField
*f
)
355 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
356 e
->tracefile
->trace
->system_description
->endian
? 0:1;
357 LttTypeEnum t
= f
->field_type
->type_class
;
359 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
360 g_error("The type of the field is not unsigned int\n");
362 if(f
->field_size
== 1){
363 guint8 x
= *(guint8
*)(e
->data
+ f
->offset_root
);
364 return (unsigned int) x
;
365 }else if(f
->field_size
== 2){
366 guint16 x
= *(guint16
*)(e
->data
+ f
->offset_root
);
367 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
368 return (unsigned int) (revFlag
? GUINT16_FROM_BE(x
): x
);
370 return (unsigned int) (revFlag
? GUINT16_FROM_LE(x
): x
);
371 }else if(f
->field_size
== 4){
372 guint32 x
= *(guint32
*)(e
->data
+ f
->offset_root
);
373 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
374 return (unsigned int) (revFlag
? GUINT32_FROM_BE(x
): x
);
376 return (unsigned int) (revFlag
? GUINT32_FROM_LE(x
): x
);
377 }else if(f
->field_size
== 8){
378 guint64 x
= *(guint64
*)(e
->data
+ f
->offset_root
);
379 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
380 return (unsigned int) (revFlag
? GUINT64_FROM_BE(x
): x
);
382 return (unsigned int) (revFlag
? GUINT64_FROM_LE(x
): x
);
386 int ltt_event_get_int(LttEvent
*e
, LttField
*f
)
388 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
389 e
->tracefile
->trace
->system_description
->endian
? 0:1;
391 if(f
->field_type
->type_class
!= LTT_INT
)
392 g_error("The type of the field is not int\n");
394 if(f
->field_size
== 1){
395 gint8 x
= *(gint8
*)(e
->data
+ f
->offset_root
);
397 }else if(f
->field_size
== 2){
398 gint16 x
= *(gint16
*)(e
->data
+ f
->offset_root
);
399 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
400 return (int) (revFlag
? GINT16_FROM_BE(x
): x
);
402 return (int) (revFlag
? GINT16_FROM_LE(x
): x
);
403 }else if(f
->field_size
== 4){
404 gint32 x
= *(gint32
*)(e
->data
+ f
->offset_root
);
405 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
406 return (int) (revFlag
? GINT32_FROM_BE(x
): x
);
408 return (int) (revFlag
? GINT32_FROM_LE(x
): x
);
409 }else if(f
->field_size
== 8){
410 gint64 x
= *(gint64
*)(e
->data
+ f
->offset_root
);
411 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
412 return (int) (revFlag
? GINT64_FROM_BE(x
): x
);
414 return (int) (revFlag
? GINT64_FROM_LE(x
): x
);
418 unsigned long ltt_event_get_long_unsigned(LttEvent
*e
, LttField
*f
)
420 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
421 e
->tracefile
->trace
->system_description
->endian
? 0:1;
422 LttTypeEnum t
= f
->field_type
->type_class
;
424 if(t
!= LTT_UINT
&& t
!= LTT_ENUM
)
425 g_error("The type of the field is not unsigned long\n");
427 if(f
->field_size
== 1){
428 guint8 x
= *(guint8
*)(e
->data
+ f
->offset_root
);
429 return (unsigned long) x
;
430 }else if(f
->field_size
== 2){
431 guint16 x
= *(guint16
*)(e
->data
+ f
->offset_root
);
432 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
433 return (unsigned long) (revFlag
? GUINT16_FROM_BE(x
): x
);
435 return (unsigned long) (revFlag
? GUINT16_FROM_LE(x
): x
);
436 }else if(f
->field_size
== 4){
437 guint32 x
= *(guint32
*)(e
->data
+ f
->offset_root
);
438 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
439 return (unsigned long) (revFlag
? GUINT32_FROM_BE(x
): x
);
441 return (unsigned long) (revFlag
? GUINT32_FROM_LE(x
): x
);
442 }else if(f
->field_size
== 8){
443 guint64 x
= *(guint64
*)(e
->data
+ f
->offset_root
);
444 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
445 return (unsigned long) (revFlag
? GUINT64_FROM_BE(x
): x
);
447 return (unsigned long) (revFlag
? GUINT64_FROM_LE(x
): x
);
451 long int ltt_event_get_long_int(LttEvent
*e
, LttField
*f
)
453 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
454 e
->tracefile
->trace
->system_description
->endian
? 0:1;
456 if( f
->field_type
->type_class
!= LTT_INT
)
457 g_error("The type of the field is not long int\n");
459 if(f
->field_size
== 1){
460 gint8 x
= *(gint8
*)(e
->data
+ f
->offset_root
);
462 }else if(f
->field_size
== 2){
463 gint16 x
= *(gint16
*)(e
->data
+ f
->offset_root
);
464 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
465 return (long) (revFlag
? GINT16_FROM_BE(x
): x
);
467 return (long) (revFlag
? GINT16_FROM_LE(x
): x
);
468 }else if(f
->field_size
== 4){
469 gint32 x
= *(gint32
*)(e
->data
+ f
->offset_root
);
470 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
471 return (long) (revFlag
? GINT32_FROM_BE(x
): x
);
473 return (long) (revFlag
? GINT32_FROM_LE(x
): x
);
474 }else if(f
->field_size
== 8){
475 gint64 x
= *(gint64
*)(e
->data
+ f
->offset_root
);
476 if(e
->tracefile
->trace
->my_arch_endian
== LTT_LITTLE_ENDIAN
)
477 return (long) (revFlag
? GINT64_FROM_BE(x
): x
);
479 return (long) (revFlag
? GINT64_FROM_LE(x
): x
);
483 float ltt_event_get_float(LttEvent
*e
, LttField
*f
)
485 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
486 e
->tracefile
->trace
->system_description
->endian
? 0:1;
488 if(f
->field_type
->type_class
!= LTT_FLOAT
||
489 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 4))
490 g_error("The type of the field is not float\n");
492 if(revFlag
== 0) return *(float *)(e
->data
+ f
->offset_root
);
495 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 4);
496 aInt
= ___swab32(aInt
);
497 return *((float*)&aInt
);
501 double ltt_event_get_double(LttEvent
*e
, LttField
*f
)
503 int revFlag
= e
->tracefile
->trace
->my_arch_endian
==
504 e
->tracefile
->trace
->system_description
->endian
? 0:1;
506 if(f
->field_type
->type_class
!= LTT_FLOAT
||
507 (f
->field_type
->type_class
== LTT_FLOAT
&& f
->field_size
!= 8))
508 g_error("The type of the field is not double\n");
510 if(revFlag
== 0) return *(double *)(e
->data
+ f
->offset_root
);
513 memcpy((void*)&aInt
, e
->data
+ f
->offset_root
, 8);
514 aInt
= ___swab64(aInt
);
515 return *((double *)&aInt
);
519 /*****************************************************************************
520 * The string obtained is only valid until the next read from
521 * the same tracefile.
522 ****************************************************************************/
524 char *ltt_event_get_string(LttEvent
*e
, LttField
*f
)
526 if(f
->field_type
->type_class
!= LTT_STRING
)
527 g_error("The field contains no string\n");
528 return (char*)g_strdup((char*)(e
->data
+ f
->offset_root
));
This page took 0.043202 seconds and 4 git commands to generate.