#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
+#include <math.h>
// For realpath
#include <limits.h>
#include <ltt/facility.h>
#include <ltt/event.h>
#include <ltt/type.h>
+#include <ltt/ltt-types.h>
#define DIR_NAME_SIZE 256
#define __UNUSED__ __attribute__((__unused__))
t->control_tracefiles = g_ptr_array_new();
t->per_cpu_tracefiles = g_ptr_array_new();
t->facilities = g_ptr_array_new();
- getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
-
+ //getDataEndianType(&(t->my_arch_size), &(t->my_arch_endian));
+
//get system description
strcpy(tmp,info);
strcat(tmp,"system.xml");
g_free(t);
return NULL;
}
-
-
+
+ /* 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 = 1;
+ } else if(sys_description->endian == LTT_BIG_ENDIAN
+ && G_BYTE_ORDER != G_BIG_ENDIAN) {
+ t->reverse_byte_order = 1;
+ } else t->reverse_byte_order = 0;
//get facilities info
if(getFacilityInfo(t,eventdefs)) {
for(i=0;i<t->control_tracefile_number;i++){
tf = g_ptr_array_index(t->control_tracefiles, i);
readBlock(tf,1);
- startTmp = tf->a_block_start->time;
+ startTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_start->time);
readBlock(tf,tf->block_number);
- endTmp = tf->a_block_end->time;
+ endTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_end->time);
if(i==0){
startSmall = startTmp;
endBig = endTmp;
for(i=0;i<t->per_cpu_tracefile_number;i++){
tf = g_ptr_array_index(t->per_cpu_tracefiles, i);
readBlock(tf,1);
- startTmp = tf->a_block_start->time;
+ startTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_start->time);
readBlock(tf,tf->block_number);
- endTmp = tf->a_block_end->time;
+ endTmp = ltt_get_time(t->reverse_byte_order, &tf->a_block_end->time);
if(j == 0 && i==0){
startSmall = startTmp;
endBig = endTmp;
if(err) g_error("Can not read tracefile: %s\n", t->name);
if(start_block == end_block)return;
- tailTime = ltt_time_compare(t->a_block_end->time, time);
+ tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(tailTime >= 0) return;
err=readBlock(t,end_block);
if(err) g_error("Can not read tracefile: %s\n", t->name);
if(start_block+1 == end_block)return;
- headTime = ltt_time_compare(t->a_block_start->time, time);
+ headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
if(headTime <= 0 ) return;
tmp_block = (end_block + start_block)/2;
err=readBlock(t,tmp_block);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- headTime = ltt_time_compare(t->a_block_start->time, time);
- tailTime = ltt_time_compare(t->a_block_end->time, time);
+ headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(headTime <= 0 && tailTime >= 0) return;
if(headTime > 0){
int t_time, h_time, err;
err=readBlock(t,t->which_block-1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- h_time = ltt_time_compare(t->a_block_start->time, time);
- t_time = ltt_time_compare(t->a_block_end->time, time);
+ h_time = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ t_time = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(h_time == 0){
int tmp;
if(t->which_block == 1) return;
err=readBlock(t,t->which_block-1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
- tmp = ltt_time_compare(t->a_block_end->time, time);
+ tmp = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
if(tmp == 0) return ltt_tracefile_seek_time(t, time);
err=readBlock(t,t->which_block+1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
{
int err;
LttTime lttTime;
- int headTime = ltt_time_compare(t->a_block_start->time, time);
- int tailTime = ltt_time_compare(t->a_block_end->time, time);
+ int headTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_start->time), time);
+ int tailTime = ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time), time);
LttEvent ev;
if(headTime < 0 && tailTime > 0){
- if(ltt_time_compare(t->a_block_end->time, t->current_event_time) !=0) {
+ if(ltt_time_compare(ltt_get_time(t->trace->reverse_byte_order,
+ &t->a_block_end->time),
+ t->current_event_time) !=0) {
lttTime = getEventTime(t);
err = ltt_time_compare(lttTime, time);
if(err > 0){
if(unlikely(err))g_error("Can not read tracefile");
}
- event->event_id = (int)(*(guint16 *)(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 = *(guint32 *)(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;
event->tracefile = t;
- event->data = t->cur_event_pos + EVENT_HEADER_SIZE;
+ event->data = t->cur_event_pos + EVENT_HEADER_SIZE;
event->which_block = t->which_block;
event->which_event = t->which_event;
if((guint)whichBlock == tf->which_block) return 0;
if(likely(whichBlock - tf->which_block == 1 && tf->which_block != 0)){
- tf->prev_block_end_time = tf->a_block_end->time;
- tf->prev_event_time = tf->a_block_end->time;
+ tf->prev_block_end_time = ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_end->time);
+ tf->prev_event_time = ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_end->time);
}else{
tf->prev_block_end_time.tv_sec = 0;
tf->prev_block_end_time.tv_nsec = 0;
/* read the whole block to precalculate total of cycles in it */
tf->count = 0;
tf->pre_cycle_count = 0;
- tf->cur_cycle_count = 0;
+ 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)(tf->a_block_start->cycle_count&0xFFFFFFFF))
+ tf->overflow_nsec =
+ (-((double)
+ (ltt_get_uint64(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count)&0xFFFFFFFF))
* tf->nsec_per_cycle);
tf->current_event_time = getEventTime(tf);
tf->prev_event_time.tv_nsec = 0;
tf->count = 0;
- tf->overflow_nsec = (-((double)tf->a_block_start->cycle_count)
+ tf->overflow_nsec =
+ (-((double)ltt_get_uint64(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
}
LttEventType * evT;
LttField * rootFld;
- evId = (int)(*(guint16 *)(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->trace->reverse_byte_order,
+ t->cur_event_pos + EVENT_ID_SIZE);
t->which_event++;
t->current_event_time = getEventTime(t);
}
LttCycleCount lBufTotalCycle;/* Total cycles for this buffer */
/* Calculate the total time for this buffer */
- lBufTotalTime = ltt_time_sub(t->a_block_end->time, t->a_block_start->time);
+ lBufTotalTime = ltt_time_sub(
+ ltt_get_time(t->trace->reverse_byte_order, &t->a_block_end->time),
+ ltt_get_time(t->trace->reverse_byte_order, &t->a_block_start->time));
/* Calculate the total cycles for this bufffer */
- lBufTotalCycle = t->a_block_end->cycle_count;
- lBufTotalCycle -= t->a_block_start->cycle_count;
+ lBufTotalCycle = ltt_get_uint64(t->trace->reverse_byte_order,
+ &t->a_block_end->cycle_count);
+ lBufTotalCycle -= ltt_get_uint64(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 = *(guint16 *)tf->cur_event_pos;
+ evId = ltt_get_uint16(tf->trace->reverse_byte_order,
+ tf->cur_event_pos);
- cycle_count = (LttCycleCount)*(guint32 *)(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)
- (tf->a_block_end->cycle_count - tf->a_block_start->cycle_count)
+ (ltt_get_uint64(tf->trace->reverse_byte_order,
+ &tf->a_block_end->cycle_count)
+ - ltt_get_uint64(tf->trace->reverse_byte_order,
+ &tf->a_block_start->cycle_count))
* tf->nsec_per_cycle);
}
#if 0
lTimeOffset = ltt_time_from_uint64(lEventNSec);
- time = ltt_time_add(tf->a_block_start->time, lTimeOffset);
+ time = ltt_time_add(ltt_get_time(tf->trace->reverse_byte_order,
+ &tf->a_block_start->time), lTimeOffset);
return time;
}
0,fld->child[0], NULL, trace);
fld->element_size = size;
}else{//0: sequence
- element_number = getIntNumber(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(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 = *(gint16 *)evD; break;
- case 4: i = *(gint32 *)evD; break;
- case 8: i = *(gint64 *)evD; break;
- default: i = *(gint64 *)evD;
+ case 1: i = *((gint8*)evD); break;
+ 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 (gint64)i;
+ 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)