/* compare two time (LttTime), 0:t1=t2, -1:t1<t2, 1:t1>t2 */
int timecmp(LttTime * t1, LttTime * t2);
-/* get an integer number */
-int getIntNumber(int size1, void *evD);
-
-
-/* Time operation macros for LttTime (struct timespec) */
-/* (T3 = T2 - T1) */
-#define TimeSub(T3, T2, T1) \
-do \
-{\
- (T3).tv_sec = (T2).tv_sec - (T1).tv_sec; \
- (T3).tv_nsec = (T2).tv_nsec - (T1).tv_nsec; \
- if((T3).tv_nsec < 0)\
- {\
- (T3).tv_sec--;\
- (T3).tv_nsec += 1000000000;\
- }\
-} while(0)
-
-/* (T3 = T2 + T1) */
-#define TimeAdd(T3, T2, T1) \
-do \
-{\
- (T3).tv_sec = (T2).tv_sec + (T1).tv_sec; \
- (T3).tv_nsec = (T2).tv_nsec + (T1).tv_nsec; \
- if((T3).tv_nsec >= 1000000000)\
- {\
- (T3).tv_sec += (T3).tv_nsec / 1000000000;\
- (T3).tv_nsec = (T3).tv_nsec % 1000000000;\
- }\
-} while(0)
-
/*****************************************************************************
// Is the file large enough to contain a trace
if(lTDFStat.st_size < sizeof(BlockStart) + EVENT_HEADER_SIZE){
- g_error("The input data file %s does not contain a trace\n", fileName);
+ g_print("The input data file %s does not contain a trace\n", fileName);
+ g_free(tf->name);
+ close(tf->fd);
+ g_free(tf);
+ return NULL;
}
//store the size of the file
{
LttTracefile * tf;
tf = ltt_tracefile_open(t,tracefile_name);
+ if(!tf) return;
t->per_cpu_tracefile_number++;
g_ptr_array_add(t->per_cpu_tracefiles, tf);
}
int i;
tf = ltt_tracefile_open(t,control_name);
+ if(!tf) return;
t->control_tracefile_number++;
g_ptr_array_add(t->control_tracefiles,tf);
//parse facilities tracefile to get base_id
- if(strcmp(control_name,"facilities") ==0){
+ if(strcmp(&control_name[strlen(control_name)-10],"facilities") ==0){
while(1){
ev = ltt_tracefile_read(tf);
if(!ev)return; // end of file
if(ev->event_id == TRACE_FACILITY_LOAD){
pos = ev->data;
fLoad.name = (char*)pos;
- fLoad.checksum = *(LttChecksum*)(pos + sizeof(pos));
- fLoad.base_code = *(uint32_t*)(pos + sizeof(pos) + sizeof(LttChecksum));
+ fLoad.checksum = *(LttChecksum*)(pos + strlen(fLoad.name));
+ fLoad.base_code = *(uint32_t*)(pos + strlen(fLoad.name) + sizeof(LttChecksum));
for(i=0;i<t->facility_number;i++){
f = (LttFacility*)g_ptr_array_index(t->facilities,i);
}else if(ev->event_id == TRACE_BLOCK_END){
break;
}else g_error("Not valid facilities trace file\n");
+ g_free(ev);
}
}
}
{
g_free(t->name);
g_free(t->buffer);
+ close(t->fd);
g_free(t);
}
for(i=0;i<entry_number;i++){
if(fgets(buf,DIR_NAME_SIZE, fp)== NULL)
g_error("Not a valid file: %s\n", pathname);
+ buf[strlen(buf)-1] = '\0';
ptr = buf;
while(isspace(*ptr)) ptr++;
switch(i){
if(strncmp("ltt_major_version=",ptr,18)!=0)
g_error("Not a valid file: %s\n", pathname);
ptr += 18;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
+ // ptr++;//skip begining "
+ // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
des->ltt_major_version = (unsigned)atoi(ptr);
break;
case 13:
if(strncmp("ltt_minor_version=",ptr,18)!=0)
g_error("Not a valid file: %s\n", pathname);
ptr += 18;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
+ // ptr++;//skip begining "
+ // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
des->ltt_minor_version = (unsigned)atoi(ptr);
break;
case 14:
if(strncmp("ltt_block_size=",ptr,15)!=0)
g_error("Not a valid file: %s\n", pathname);
ptr += 15;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
+ // ptr++;//skip begining "
+ // ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
des->ltt_block_size = (unsigned)atoi(ptr);
break;
default:
int i,j;
LttFacility * f;
LttEventType * et;
+ char name[DIR_NAME_SIZE];
dir = opendir(eventdefs);
if(!dir) g_error("Can not open directory: %s\n", eventdefs);
while((entry = readdir(dir)) != NULL){
ptr = &entry->d_name[strlen(entry->d_name)-4];
if(strcmp(ptr,".xml") != 0) continue;
- ltt_facility_open(t,entry->d_name);
+ strcpy(name,eventdefs);
+ strcat(name,entry->d_name);
+ ltt_facility_open(t,name);
}
closedir(dir);
for(j=0;j<t->facility_number;j++){
- f = (LttFacility*)g_ptr_array_index(t->facilities, i);
+ f = (LttFacility*)g_ptr_array_index(t->facilities, j);
for(i=0; i<f->event_number; i++){
et = f->events[i];
setFieldsOffset(NULL, et, NULL, t);
{
DIR * dir;
struct dirent *entry;
+ char name[DIR_NAME_SIZE];
dir = opendir(control);
if(!dir) g_error("Can not open directory: %s\n", control);
while((entry = readdir(dir)) != NULL){
- if(strcmp(entry->d_name,"facilities") != 0 ||
- strcmp(entry->d_name,"interrupts") != 0 ||
+ if(strcmp(entry->d_name,"facilities") != 0 &&
+ strcmp(entry->d_name,"interrupts") != 0 &&
strcmp(entry->d_name,"processes") != 0) continue;
- ltt_tracefile_open_control(t,entry->d_name);
+ strcpy(name,control);
+ strcat(name,entry->d_name);
+ ltt_tracefile_open_control(t,name);
}
closedir(dir);
}
{
DIR * dir;
struct dirent *entry;
+ char name[DIR_NAME_SIZE];
dir = opendir(cpu);
if(!dir) g_error("Can not open directory: %s\n", cpu);
while((entry = readdir(dir)) != NULL){
- if(strcmp(entry->d_name,".") != 0 ||
+ if(strcmp(entry->d_name,".") != 0 &&
strcmp(entry->d_name,"..") != 0 ){
- ltt_tracefile_open_cpu(t,entry->d_name);
+ strcpy(name,cpu);
+ strcat(name,entry->d_name);
+ ltt_tracefile_open_cpu(t,name);
}else continue;
}
closedir(dir);
strcat(tmp,"system.xml");
getSystemInfo(sys_description, tmp);
+ //get facilities info
+ getFacilityInfo(t,eventdefs);
+
//get control tracefile info
getControlFileInfo(t,control);
//get cpu tracefile info
getCpuFileInfo(t,cpu);
- //get facilities info
- getFacilityInfo(t,eventdefs);
-
return t;
}
tf = (LttTracefile*)g_ptr_array_index(t->control_tracefiles,i);
ltt_tracefile_close(tf);
}
- g_ptr_array_free(t->control_tracefiles, FALSE);
+ g_ptr_array_free(t->control_tracefiles, TRUE);
//free per_cpu_tracefiles
for(i=0;i<t->per_cpu_tracefile_number;i++){
tf = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles,i);
ltt_tracefile_close(tf);
}
- g_ptr_array_free(t->per_cpu_tracefiles, FALSE);
+ g_ptr_array_free(t->per_cpu_tracefiles, TRUE);
//free facilities
for(i=0;i<t->facility_number;i++){
f = (LttFacility*)g_ptr_array_index(t->facilities,i);
ltt_facility_close(f);
}
- g_ptr_array_free(t->facilities, FALSE);
+ g_ptr_array_free(t->facilities, TRUE);
g_free(t);
+
+ g_blow_chunks();
}
{
int i, count=0;
LttFacility * f;
- for(i=0;i=t->facility_number;i++){
+ for(i=0;i<t->facility_number;i++){
f = (LttFacility*)g_ptr_array_index(t->facilities, i);
if(strcmp(f->name,name)==0){
count++;
LttTime lttTime;
int headTime = timecmp(&(t->a_block_start->time), &time);
int tailTime = timecmp(&(t->a_block_end->time), &time);
-
+ LttEvent * ev;
+
if(headTime < 0 && tailTime > 0){
lttTime = getEventTime(t);
err = timecmp(<tTime, &time);
return ltt_tracefile_seek_time(t, time);
}
}else if(err < 0){
- err = t->which_block;
- if(ltt_tracefile_read(t) == NULL){
- g_printf("End of file\n");
- return;
+ while(1){
+ ev = ltt_tracefile_read(t);
+ if(ev == NULL){
+ g_print("End of file\n");
+ return;
+ }
+ g_free(ev);
+ lttTime = getEventTime(t);
+ err = timecmp(<tTime, &time);
+ if(err >= 0)return;
}
- if(t->which_block == err)
- return ltt_tracefile_seek_time(t,time);
}else return;
}else if(headTime > 0){
if(t->which_block == 1){
err=readBlock(t,t->which_block+1);
if(err) g_error("Can not read tracefile: %s\n", t->name);
}else {
- g_printf("End of file\n");
+ g_print("End of file\n");
return;
}
if(tailTime < 0) return ltt_tracefile_seek_time(t, time);
updateTracefile(t);
}else if(tailTime == 0){
t->cur_event_pos = t->a_block_end - EVENT_HEADER_SIZE;
+ t->current_event_time = time;
+ t->cur_heart_beat_number = 0;
+ t->prev_event_time.tv_sec = 0;
+ t->prev_event_time.tv_nsec = 0;
return;
}
}
LttEvent * lttEvent = (LttEvent *)g_new(LttEvent, 1);
int err;
+ if(t->cur_event_pos == t->buffer + t->block_size){
+ if(t->which_block == t->block_number){
+ g_free(lttEvent);
+ return NULL;
+ }
+ err = readBlock(t, t->which_block + 1);
+ if(err)g_error("Can not read tracefile");
+ }
+
lttEvent->event_id = (int)(*(uint16_t *)(t->cur_event_pos));
if(lttEvent->event_id == TRACE_TIME_HEARTBEAT)
t->cur_heart_beat_number++;
t->prev_event_time = t->current_event_time;
- t->current_event_time = getEventTime(t);
+ // t->current_event_time = getEventTime(t);
lttEvent->time_delta = *(uint32_t*)(t->cur_event_pos + EVENT_ID_SIZE);
lttEvent->event_time = t->current_event_time;
lttEvent->tracefile = t;
lttEvent->data = t->cur_event_pos + EVENT_HEADER_SIZE;
+ lttEvent->which_block = t->which_block;
+ lttEvent->which_event = t->which_event;
//update the fields of the current event and go to the next event
err = skipEvent(t);
- if(err == ENOENT) return NULL;
if(err == ERANGE) g_error("event id is out of range\n");
- if(err)g_error("Can not read tracefile\n");
return lttEvent;
}
if(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->current_event_time = tf->a_block_end->time;
}else{
tf->prev_block_end_time.tv_sec = 0;
tf->prev_block_end_time.tv_nsec = 0;
tf->prev_event_time.tv_sec = 0;
tf->prev_event_time.tv_nsec = 0;
- tf->current_event_time.tv_sec = 0;
- tf->current_event_time.tv_nsec = 0;
}
nbBytes=lseek(tf->fd,(off_t)((whichBlock-1)*tf->block_size), SEEK_SET);
getCyclePerNsec(tf);
- // tf->current_event_time = getEventTime(tf);
+ tf->current_event_time = getEventTime(tf);
return 0;
}
{
tf->which_event = 1;
tf->cur_event_pos = tf->buffer;
- // tf->current_event_time = getEventTime(tf);
- tf->current_event_time.tv_sec = 0;
- tf->current_event_time.tv_nsec = 0;
+ tf->current_event_time = getEventTime(tf);
tf->cur_heart_beat_number = 0;
tf->prev_event_time.tv_sec = 0;
* t : tracefile
*return value
* 0 : success
- * EINVAL : lseek fail
- * EIO : can not read from the file
- * ENOENT : end of file
* ERANGE : event id is out of range
****************************************************************************/
evId = (int)(*(uint16_t *)(t->cur_event_pos));
evData = t->cur_event_pos + EVENT_HEADER_SIZE;
- evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
+ evT = ltt_trace_eventtype_get(t->trace,(unsigned)evId);
+
if(evT) rootFld = evT->root_field;
else return ERANGE;
- //event has string/sequence or the last event is not the same event
- if((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
- && rootFld->field_fixed == 0){
- setFieldsOffset(t, evT, evData, t->trace);
- }
- t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
-
+ if(rootFld){
+ //event has string/sequence or the last event is not the same event
+ if((evT->latest_block!=t->which_block || evT->latest_event!=t->which_event)
+ && rootFld->field_fixed == 0){
+ setFieldsOffset(t, evT, evData, t->trace);
+ }
+ t->cur_event_pos += EVENT_HEADER_SIZE + rootFld->field_size;
+ }else t->cur_event_pos += EVENT_HEADER_SIZE;
+
evT->latest_block = t->which_block;
evT->latest_event = t->which_event;
-
+
//the next event is in the next block
if(evId == TRACE_BLOCK_END){
- if(t->which_block == t->block_number) return ENOENT;
- err = readBlock(t, t->which_block + 1);
- if(err) return err;
+ t->cur_event_pos = t->buffer + t->block_size;
}else{
t->which_event++;
+ t->current_event_time = getEventTime(t);
}
return 0;
LttField * rootFld = evT->root_field;
// rootFld->base_address = evD;
- rootFld->field_size = getFieldtypeSize(tf, evT, 0,0,rootFld, evD,t);
+ if(rootFld)
+ rootFld->field_size = getFieldtypeSize(tf, evT, 0,0,rootFld, evD,t);
}
/*****************************************************************************
int size, size1, element_number, i, offset1, offset2;
LttType * type = fld->field_type;
- if(!t){
+ if(t){
if(evT->latest_block==t->which_block && evT->latest_event==t->which_event){
return fld->field_size;
}
}else if(type->type_class == LTT_SEQUENCE){
size1 = (int) ltt_type_size(trace, type);
if(fld->field_fixed == -1){
+ fld->sequ_number_size = size1;
fld->field_fixed = 0;
size = getFieldtypeSize(t, evT, offsetRoot,0,fld->child[0], NULL, trace);
fld->element_size = size;
if(fld->field_fixed == -1){
fld->field_fixed = 0;
}else{//0: string
- size = sizeof((char*)evD) + 1; //include end : '\0'
+ size = strlen((char*)evD) + 1; //include end : '\0'
}
}else if(type->type_class == LTT_STRUCT){