#include "ltt-private.h"
#include <ltt/event.h>
#include <ltt/trace.h>
+#include <ltt/ltt-types.h>
LttEvent *ltt_event_new()
* offsetParent : offset from the parent
* fld : field
* evD : event data
+ * reverse_byte_order : 1 or 0
*Return value
* int : size of the field
****************************************************************************/
int ltt_event_refresh_fields(int offsetRoot,int offsetParent,
- LttField * fld, void *evD)
+ LttField * fld, void *evD, gboolean reverse_byte_order)
{
int size, size1, element_number, i, offset1, offset2;
LttType * type = fld->field_type;
size = 0;
for(i=0;i<element_number;i++){
size += ltt_event_refresh_fields(offsetRoot+size,size,
- fld->child[0], evD+size);
+ fld->child[0], evD+size, reverse_byte_order);
}
}else size = fld->field_size;
break;
case LTT_SEQUENCE:
size1 = fld->sequ_number_size;
- element_number = getIntNumber(size1,evD);
+ element_number = getIntNumber(reverse_byte_order,size1,evD);
type->element_number = element_number;
if(fld->element_size > 0){
size = element_number * fld->element_size;
size = 0;
for(i=0;i<element_number;i++){
size += ltt_event_refresh_fields(offsetRoot+size+size1,size+size1,
- fld->child[0], evD+size+size1);
+ fld->child[0], evD+size+size1, reverse_byte_order);
}
size += size1;
}
offset2 = 0;
for(i=0;i<element_number;i++){
size=ltt_event_refresh_fields(offset1,offset2,
- fld->child[i],evD+offset2);
+ fld->child[i],evD+offset2, reverse_byte_order);
offset1 += size;
offset2 += size;
}
event_type->latest_event = e->which_event;
if(unlikely(field->field_fixed != 1))
- ltt_event_refresh_fields(0, 0, field, e->data);
+ ltt_event_refresh_fields(0, 0, field, e->data,
+ e->tracefile->trace->reverse_byte_order);
}
return field;
}
if(f->field_type->type_class == LTT_ARRAY)
return f->field_type->element_number;
- return (unsigned) getIntNumber(f->sequ_number_size, e + f->offset_root);
+ return (unsigned) getIntNumber(e->tracefile->trace->reverse_byte_order,
+ f->sequ_number_size, e + f->offset_root);
}
/*****************************************************************************
evD = e->data + f->offset_root;
size = 0;
for(k=0;k<i;k++){
- size += ltt_event_refresh_fields(f->offset_root+size,size, fld, evD+size);
+ size += ltt_event_refresh_fields(f->offset_root+size,size, fld, evD+size,
+ e->tracefile->trace->reverse_byte_order);
}
f->current_element = i - 1;
}
guint32 ltt_event_get_unsigned(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
+
LttTypeEnum t = f->field_type->type_class;
g_assert(t == LTT_UINT || t == LTT_ENUM);
guint8 x = *(guint8 *)(e->data + f->offset_root);
return (guint32) x;
}else if(f->field_size == 2){
- guint16 x = *(guint16 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (guint32) (revFlag ? GUINT16_FROM_BE(x): x);
- else
- return (guint32) (revFlag ? GUINT16_FROM_LE(x): x);
+ return (guint32)ltt_get_uint16(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 4){
- guint32 x = *(guint32 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (guint32) (revFlag ? GUINT32_FROM_BE(x): x);
- else
- return (guint32) (revFlag ? GUINT32_FROM_LE(x): x);
+ return (guint32)ltt_get_uint32(reverse_byte_order, e->data + f->offset_root);
}
#if 0
else if(f->field_size == 8){
gint32 ltt_event_get_int(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
g_assert(f->field_type->type_class == LTT_INT);
gint8 x = *(gint8 *)(e->data + f->offset_root);
return (gint32) x;
}else if(f->field_size == 2){
- gint16 x = *(gint16 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (gint32) (revFlag ? GINT16_FROM_BE(x): x);
- else
- return (gint32) (revFlag ? GINT16_FROM_LE(x): x);
+ return (gint32)ltt_get_int16(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 4){
- gint32 x = *(gint32 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (gint32) (revFlag ? GINT32_FROM_BE(x): x);
- else
- return (gint32) (revFlag ? GINT32_FROM_LE(x): x);
+ return (gint32)ltt_get_int32(reverse_byte_order, e->data + f->offset_root);
}
#if 0
else if(f->field_size == 8){
guint64 ltt_event_get_long_unsigned(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
LttTypeEnum t = f->field_type->type_class;
g_assert(t == LTT_UINT || t == LTT_ENUM);
guint8 x = *(guint8 *)(e->data + f->offset_root);
return (guint64) x;
}else if(f->field_size == 2){
- guint16 x = *(guint16 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (guint64) (revFlag ? GUINT16_FROM_BE(x): x);
- else
- return (guint64) (revFlag ? GUINT16_FROM_LE(x): x);
+ return (guint64)ltt_get_uint16(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 4){
- guint32 x = *(guint32 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (guint64) (revFlag ? GUINT32_FROM_BE(x): x);
- else
- return (guint64) (revFlag ? GUINT32_FROM_LE(x): x);
+ return (guint64)ltt_get_uint32(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 8){
- guint64 x = *(guint64 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (guint64) (revFlag ? GUINT64_FROM_BE(x): x);
- else
- return (guint64) (revFlag ? GUINT64_FROM_LE(x): x);
+ return ltt_get_uint64(reverse_byte_order, e->data + f->offset_root);
}
g_critical("ltt_event_get_long_unsigned : field size %i unknown", f->field_size);
return 0;
gint64 ltt_event_get_long_int(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
g_assert( f->field_type->type_class == LTT_INT);
gint8 x = *(gint8 *)(e->data + f->offset_root);
return (gint64) x;
}else if(f->field_size == 2){
- gint16 x = *(gint16 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (gint64) (revFlag ? GINT16_FROM_BE(x): x);
- else
- return (gint64) (revFlag ? GINT16_FROM_LE(x): x);
+ return (gint64)ltt_get_int16(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 4){
- gint32 x = *(gint32 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (gint64) (revFlag ? GINT32_FROM_BE(x): x);
- else
- return (gint64) (revFlag ? GINT32_FROM_LE(x): x);
+ return (gint64)ltt_get_int32(reverse_byte_order, e->data + f->offset_root);
}else if(f->field_size == 8){
- gint64 x = *(gint64 *)(e->data + f->offset_root);
- if(e->tracefile->trace->my_arch_endian == LTT_LITTLE_ENDIAN)
- return (gint64) (revFlag ? GINT64_FROM_BE(x): x);
- else
- return (gint64) (revFlag ? GINT64_FROM_LE(x): x);
+ return ltt_get_int64(reverse_byte_order, e->data + f->offset_root);
}
g_critical("ltt_event_get_long_int : field size %i unknown", f->field_size);
return 0;
float ltt_event_get_float(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 4);
- if(revFlag == 0) return *(float *)(e->data + f->offset_root);
+ if(reverse_byte_order == 0) return *(float *)(e->data + f->offset_root);
else{
guint32 aInt;
memcpy((void*)&aInt, e->data + f->offset_root, 4);
double ltt_event_get_double(LttEvent *e, LttField *f)
{
- int revFlag = e->tracefile->trace->my_arch_endian ==
- e->tracefile->trace->system_description->endian ? 0:1;
+ gboolean reverse_byte_order = e->tracefile->trace->reverse_byte_order;
+ //int revFlag = e->tracefile->trace->my_arch_endian ==
+ // e->tracefile->trace->system_description->endian ? 0:1;
g_assert(f->field_type->type_class == LTT_FLOAT && f->field_size == 8);
- if(revFlag == 0) return *(double *)(e->data + f->offset_root);
+ if(reverse_byte_order == 0) return *(double *)(e->data + f->offset_root);
else{
guint64 aInt;
memcpy((void*)&aInt, e->data + f->offset_root, 8);
* */
#include <ltt/ltt.h>
-#include <ltt/ltt-private.h>
+//#include <ltt/ltt-private.h>
#include <glib.h>
+#include <ltt/time.h>
/*****************************************************************************
*
****************************************************************************/
-inline gint64 ltt_get_int64(LttTrace t, void *ptr)
+static inline gint64 ltt_get_int64(gboolean reverse_byte_order, void *ptr)
{
- return (gint64) (t->reverse_byte_order ? GUINT64_SWAP_LE_BE(ptr): ptr);
+ guint64 value = *(guint64*)ptr;
+ return (gint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value);
}
-inline guint64 ltt_get_uint64(LttTrace t, void *ptr)
+static inline guint64 ltt_get_uint64(gboolean reverse_byte_order, void *ptr)
{
- return (guint64) (t->reverse_byte_order ? GUINT64_SWAP_LE_BE(ptr): ptr);
+ guint64 value = *(guint64*)ptr;
+ return (guint64) (reverse_byte_order ? GUINT64_SWAP_LE_BE(value): value);
}
-inline gint32 ltt_get_int32(LttTrace t, void *ptr)
+static inline gint32 ltt_get_int32(gboolean reverse_byte_order, void *ptr)
{
- return (gint32) (t->reverse_byte_order ? GUINT32_SWAP_LE_BE(ptr): ptr);
+ guint32 value = *(guint32*)ptr;
+ return (gint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value);
}
-inline guint32 ltt_get_uint32(LttTrace t, void *ptr)
+static inline guint32 ltt_get_uint32(gboolean reverse_byte_order, void *ptr)
{
- return (guint32) (t->reverse_byte_order ? GUINT32_SWAP_LE_BE(ptr): ptr);
+ guint32 value = *(guint32*)ptr;
+ return (guint32) (reverse_byte_order ? GUINT32_SWAP_LE_BE(value): value);
}
-inline gint16 ltt_get_int16(LttTrace t, void *ptr)
+static inline gint16 ltt_get_int16(gboolean reverse_byte_order, void *ptr)
{
- return (gint16) (t->reverse_byte_order ? GUINT16_SWAP_LE_BE(ptr): ptr);
+ guint16 value = *(guint16*)ptr;
+ return (gint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value);
}
-inline guint16 ltt_get_uint16(LttTrace t, void *ptr)
+static inline guint16 ltt_get_uint16(gboolean reverse_byte_order, void *ptr)
{
- return (guint16) (t->reverse_byte_order ? GUINT16_SWAP_LE_BE(ptr): ptr);
+ guint16 value = *(guint16*)ptr;
+ return (guint16) (reverse_byte_order ? GUINT16_SWAP_LE_BE(value): value);
+}
+
+static inline LttTime ltt_get_time(gboolean reverse_byte_order, void *ptr)
+{
+ LttTime output;
+
+ output.tv_sec = ltt_get_uint64(reverse_byte_order, ptr);
+ ptr += sizeof(guint64);
+ output.tv_nsec = ltt_get_uint64(reverse_byte_order, ptr);
+
+ return output;
}
#endif // LTT_TYPES_H
/* Set the reverse byte order between trace and reader */
if(sys_description->endian == LTT_LITTLE_ENDIAN
&& G_BYTE_ORDER != G_LITTLE_ENDIAN) {
- t->reverse_byte_order = true;
+ t->reverse_byte_order = 1;
} else if(sys_description->endian == LTT_BIG_ENDIAN
&& G_BYTE_ORDER != G_BIG_ENDIAN) {
- t->reverse_byte_order = true;
- } else t->reverse_byte_order = false;
+ t->reverse_byte_order = 1;
+ } else t->reverse_byte_order = 0;
//get facilities info
if(getFacilityInfo(t,eventdefs)) {
if(unlikely(err))g_error("Can not read tracefile");
}
- event->event_id = ltt_get_uint16(t, t->cur_event_pos);
+ event->event_id = ltt_get_uint16(t->trace->reverse_byte_order, t->cur_event_pos);
if(unlikely(event->event_id == TRACE_TIME_HEARTBEAT))
t->cur_heart_beat_number++;
t->prev_event_time = t->current_event_time;
// t->current_event_time = getEventTime(t);
- event->time_delta = ltt_get_uint32(t, t->cur_event_pos + EVENT_ID_SIZE);
+ event->time_delta = ltt_get_uint32(t->trace->reverse_byte_order, t->cur_event_pos + EVENT_ID_SIZE);
event->event_time = t->current_event_time;
event->event_cycle_count = t->cur_cycle_count;
/* read the whole block to precalculate total of cycles in it */
tf->count = 0;
tf->pre_cycle_count = 0;
- tf->cur_cycle_count = ltt_get_uint32(tf, tf->cur_event_pos + EVENT_ID_SIZE);
+ tf->cur_cycle_count = ltt_get_uint32(tf->trace->reverse_byte_order, tf->cur_event_pos + EVENT_ID_SIZE);
getCyclePerNsec(tf);
tf->overflow_nsec =
(-((double)
- (ltt_get_uint32(tf, tf->a_block_start->cycle_count)&0xFFFFFFFF))
+ (ltt_get_uint32(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count)&0xFFFFFFFF))
* tf->nsec_per_cycle);
tf->current_event_time = getEventTime(tf);
tf->count = 0;
tf->overflow_nsec =
- (-((double)ltt_get_uint32(tf, tf->a_block_start->cycle_count))
+ (-((double)ltt_get_uint32(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
}
LttEventType * evT;
LttField * rootFld;
- evId = ltt_get_uint16(t, t->cur_event_pos);
+ evId = ltt_get_uint16(t->trace->reverse_byte_order, t->cur_event_pos);
evData = t->cur_event_pos + EVENT_HEADER_SIZE;
evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
if(unlikely(evId == TRACE_BLOCK_END)){
t->cur_event_pos = t->buffer + t->block_size;
}else{
- t->cur_cycle_count = ltt_get_uint32(t, t->cur_event_pos + EVENT_ID_SIZE);
+ t->cur_cycle_count = ltt_get_uint32(t->trace->reverse_byte_order,
+ t->cur_event_pos + EVENT_ID_SIZE);
t->which_event++;
t->current_event_time = getEventTime(t);
}
lBufTotalTime = ltt_time_sub(t->a_block_end->time, t->a_block_start->time);
/* Calculate the total cycles for this bufffer */
- lBufTotalCycle = ltt_get_uint32(t, t->a_block_end->cycle_count);
- lBufTotalCycle -= ltt_get_uint32(t, t->a_block_start->cycle_count);
+ lBufTotalCycle = ltt_get_uint32(t->trace->reverse_byte_order,
+ &t->a_block_end->cycle_count);
+ lBufTotalCycle -= ltt_get_uint32(t->trace->reverse_byte_order,
+ &t->a_block_start->cycle_count);
/* Convert the total time to double */
lBufTotalNSec = ltt_time_to_double(lBufTotalTime);
LttTime lTimeOffset; // Time offset in struct LttTime
guint16 evId;
- evId = ltt_get_uint16(tf, tf->cur_event_pos);
+ evId = ltt_get_uint16(tf->trace->reverse_byte_order,
+ tf->cur_event_pos);
- cycle_count = ltt_get_uint32(tf, tf->cur_event_pos + EVENT_ID_SIZE);
+ cycle_count = ltt_get_uint32(tf->trace->reverse_byte_order,
+ tf->cur_event_pos + EVENT_ID_SIZE);
gboolean comp_count = cycle_count < tf->pre_cycle_count;
lEventNSec = 0;
} else if(unlikely(evId == TRACE_BLOCK_END)) {
lEventNSec = ((double)
- (ltt_get_uint32(tf, tf->a_block_end->cycle_count)
- - ltt_get_uint32(tf, tf->a_block_start->cycle_count))
+ (ltt_get_uint32(tf->trace->reverse_byte_order,
+ &tf->a_block_end->cycle_count)
+ - ltt_get_uint32(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
}
#if 0
0,fld->child[0], NULL, trace);
fld->element_size = size;
}else{//0: sequence
- element_number = getIntNumber(t,size1,evD);
+ element_number = getIntNumber(t->trace->reverse_byte_order,size1,evD);
type->element_number = element_number;
if(fld->element_size > 0){
size = element_number * fld->element_size;
* gint64 : a 64 bits integer
****************************************************************************/
-gint64 getIntNumber(LttTracefile * t, int size, void *evD)
+gint64 getIntNumber(gboolean reverse_byte_order, int size, void *evD)
{
gint64 i;
switch(size) {
case 1: i = *((gint8*)evD); break;
- case 2: i = ltt_get_int16(t, evD); break;
- case 4: i = ltt_get_int32(t, evD); break;
- case 8: i = ltt_get_int64(t, evD); break;
- default: i = ltt_get_int64(t, evD);
+ case 2: i = ltt_get_int16(reverse_byte_order, evD); break;
+ case 4: i = ltt_get_int32(reverse_byte_order, evD); break;
+ case 8: i = ltt_get_int64(reverse_byte_order, evD); break;
+ default: i = ltt_get_int64(reverse_byte_order, evD);
g_critical("getIntNumber : integer size %d unknown", size);
break;
}
return i;
}
-
+#if 0
/*****************************************************************************
*Function name
* getDataEndianType : get the data type size and endian type of the local
*size = LTT_ILP64;
else *size = LTT_UNKNOWN;
}
-
+#endif //0
/* get the node name of the system */
char * ltt_trace_system_description_node_name (LttSystemDescription * s)