/* 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_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;
}
{
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);
}
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
}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);
}
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_print("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){
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 == ENOMEM) return NULL;
- if(err == ENOENT) return lttEvent;
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
- * ENOMEM : end of file
- * ENOENT : last event
* ERANGE : event id is out of range
****************************************************************************/
void * evData;
LttEventType * evT;
LttField * rootFld;
- static int evCount = 0;
-
- if(evCount){
- if(t->which_block == t->block_number &&
- evCount == t->which_event){
- return ENOMEM;
- }else evCount = 0;
- }
evId = (int)(*(uint16_t *)(t->cur_event_pos));
evData = t->cur_event_pos + EVENT_HEADER_SIZE;
- //regard BLOCK_START, END and HEARTBEAT as special case, there are buildin events
- if(evId != TRACE_BLOCK_START && evId != TRACE_BLOCK_END && evId != TRACE_TIME_HEARTBEAT){
- 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;
+ if(evT) rootFld = evT->root_field;
+ else return ERANGE;
- 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;
- }else{
- if(evId == TRACE_BLOCK_START || evId == TRACE_BLOCK_END){
- t->cur_event_pos += sizeof(BlockStart) + EVENT_HEADER_SIZE;
- }else{
- t->cur_event_pos += sizeof(TimeHeartbeat) + EVENT_HEADER_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){
- t->which_event++;
- evCount = t->which_event;
- 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;
}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;