From 908f42fafd8d7dc4d1ed17d5b2eede4d7d64a4e3 Mon Sep 17 00:00:00 2001 From: yangxx Date: Thu, 31 Jul 2003 21:10:54 +0000 Subject: [PATCH] git-svn-id: http://ltt.polymtl.ca/svn@152 04897980-b3bd-0310-b5e0-8ef037075253 --- ltt/branches/poly/ltt/event.c | 122 +++++++++++++++++++++++++++--- ltt/branches/poly/ltt/facility.c | 60 +++++++++++---- ltt/branches/poly/ltt/parser.c | 3 +- ltt/branches/poly/ltt/tracefile.c | 43 +++++------ 4 files changed, 177 insertions(+), 51 deletions(-) diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index ed605b9f..0b20c3df 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -5,6 +5,75 @@ #include "parser.h" #include +/***************************************************************************** + *Function name + * ltt_event_refresh_fields : refresh fields of an event + *Input params + * offsetRoot : offset from the root + * offsetParent : offset from the parrent + * fld : field + * evD : event data + *Return value + * int : size of the field + ****************************************************************************/ + +int ltt_event_refresh_fields(int offsetRoot,int offsetParent, + LttField * fld, void *evD) +{ + int size, size1, element_number, i, offset1, offset2; + LttType * type = fld->field_type; + + if(type->type_class != LTT_STRUCT && type->type_class != LTT_ARRAY && + type->type_class != LTT_SEQUENCE && type->type_class != LTT_STRING){ + size = fld->field_size; + }else if(type->type_class == LTT_ARRAY){ + element_number = (int) type->element_number; + if(fld->field_fixed == 0){// has string or sequence + size = 0; + for(i=0;ichild[0], evD+size); + } + }else size = fld->field_size; + }else if(type->type_class == LTT_SEQUENCE){ + size1 = fld->sequ_number_size; + element_number = getIntNumber(size1,evD); + type->element_number = element_number; + if(fld->element_size > 0){ + size = element_number * fld->element_size; + }else{//sequence has string or sequence + size = 0; + for(i=0;ichild[0], evD+size+size1); + } + size += size1; + } + }else if(type->type_class == LTT_STRING){ + size = strlen((char*)evD) + 1; //include end : '\0' + }else if(type->type_class == LTT_STRUCT){ + element_number = (int) type->element_number; + if(fld->field_fixed == 0){ + offset1 = offsetRoot; + offset2 = 0; + for(i=0;ichild[i],evD+offset2); + offset1 += size; + offset2 += size; + } + size = offset2; + }else size = fld->field_size; + } + + fld->offset_root = offsetRoot; + fld->offset_parent = offsetParent; + fld->fixed_root = (offsetRoot==-1) ? 0 : 1; + fld->fixed_parent = (offsetParent==-1) ? 0 : 1; + fld->field_size = size; + + return size; +} + /***************************************************************************** *Function name * ltt_event_eventtype_id: get event type id @@ -63,9 +132,24 @@ LttEventType *ltt_event_eventtype(LttEvent *e) LttField *ltt_event_field(LttEvent *e) { + LttField * field; LttEventType * event_type = ltt_event_eventtype(e); if(!event_type) return NULL; - return event_type->root_field; + field = event_type->root_field; + + //check if the field need refresh + if(e->which_block != event_type->latest_block || + e->which_event != event_type->latest_event){ + + event_type->latest_block = e->which_block; + event_type->latest_event = e->which_event; + + if(field->field_fixed == 1)return field; + + //refresh the field + ltt_event_refresh_fields(0, 0, field, e->data); + } + return field; } /***************************************************************************** @@ -131,7 +215,7 @@ void *ltt_event_data(LttEvent *e) * to each event. This function returns the number of * elements for an array or sequence field in an event. *Input params - * e : an instance of an event type ???? + * e : an instance of an event type * f : a field of the instance *Return value * unsigned : the number of elements for an array/sequence field @@ -142,8 +226,10 @@ unsigned ltt_event_field_element_number(LttEvent *e, LttField *f) if(f->field_type->type_class != LTT_ARRAY && f->field_type->type_class != LTT_SEQUENCE) return 0; - - return f->field_type->element_number; + + 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); } /***************************************************************************** @@ -152,20 +238,34 @@ unsigned ltt_event_field_element_number(LttEvent *e, LttField *f) * : Set the currently selected element for a sequence or * array field *Input params - * e : an instance of an event type ???? + * e : an instance of an event type * f : a field of the instance * i : the ith element ****************************************************************************/ void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) { - if(f->field_type->type_class != LTT_ARRAY && + unsigned element_number; + LttField *fld; + int k, size; + void *evD; + + if(f->field_type->type_class != LTT_ARRAY && f->field_type->type_class != LTT_SEQUENCE) - return ; - - if(f->field_type->element_number < i || i == 0) return; + return ; + + element_number = ltt_event_field_element_number(e,f); + if(element_number < i || i == 0) return; + + fld = f->child[0]; + + evD = e->data + f->offset_root; + size = 0; + for(k=0;koffset_root+size,size, fld, evD+size); + } - f->current_element = i - 1; + f->current_element = i - 1; } /***************************************************************************** @@ -331,7 +431,7 @@ double ltt_event_get_double(LttEvent *e, LttField *f) /***************************************************************************** * The string obtained is only valid until the next read from - * the same tracefile. ???? + * the same tracefile. ****************************************************************************/ char *ltt_event_get_string(LttEvent *e, LttField *f) diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index bd50c198..b1c26baa 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -23,6 +23,7 @@ void freeFacility(LttFacility * facility); void freeEventtype(LttEventType * evType); void freeLttType(LttType ** type); void freeLttField(LttField * fld); +void freeLttNamedType(LttType * type); /***************************************************************************** @@ -173,7 +174,7 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) void constructTypeAndFields(LttFacility * fac,type_descriptor * td, LttField * fld) { - int i; + int i, flag; type_descriptor * tmpTd; // if(td->type == LTT_STRING || td->type == LTT_SEQUENCE) @@ -211,17 +212,30 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, constructTypeAndFields(fac, tmpTd, fld->child[0]); }else if(td->type == LTT_STRUCT){ fld->field_type->element_number = td->fields.position; - fld->field_type->element_type = g_new(LttType*, td->fields.position); + + if(fld->field_type->element_type == NULL){ + fld->field_type->element_type = g_new(LttType*, td->fields.position); + flag = 1; + }else{ + flag = 0; + } + fld->child = g_new(LttField*, td->fields.position); for(i=0;ifields.position;i++){ tmpTd = ((field*)(td->fields.array[i]))->type; - fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); + + if(flag) + fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); fld->child[i] = g_new(LttField,1); fld->child[i]->field_pos = i; fld->child[i]->field_type = fld->field_type->element_type[i]; - fld->child[i]->field_type->element_name - = g_strdup(((field*)(td->fields.array[i]))->name); + + if(flag){ + fld->child[i]->field_type->element_name + = g_strdup(((field*)(td->fields.array[i]))->name); + } + fld->child[i]->offset_root = -1; fld->child[i]->fixed_root = -1; fld->child[i]->offset_parent = -1; @@ -257,9 +271,11 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) if(td->type_name){ for(i=0;inamed_types_number; i++){ if(fac->named_types[i] == NULL) break; - name = fac->named_types[i]->element_name; + name = fac->named_types[i]->type_name; if(strcmp(name, td->type_name)==0){ - lttType = fac->named_types[i]; + lttType = fac->named_types[i]; + // if(lttType->element_name) g_free(lttType->element_name); + // lttType->element_name = NULL; break; } } @@ -274,12 +290,13 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) lttType->enum_strings = NULL; lttType->element_type = NULL; lttType->element_number = 0; + lttType->element_name = NULL; if(td->type_name){ - lttType->element_name = g_strdup(td->type_name); + lttType->type_name = g_strdup(td->type_name); fac->named_types[i] = lttType; } else{ - lttType->element_name = NULL; + lttType->type_name = NULL; } } @@ -321,6 +338,10 @@ void freeFacility(LttFacility * fac) g_free(fac->events); //free all named types + for(i=0;inamed_types_number;i++){ + freeLttNamedType(fac->named_types[i]); + fac->named_types[i] = NULL; + } g_free(fac->named_types); //free the facility itself @@ -329,20 +350,34 @@ void freeFacility(LttFacility * fac) void freeEventtype(LttEventType * evType) { + LttType * root_type; g_free(evType->name); if(evType->description) g_free(evType->description); if(evType->root_field){ + root_type = evType->root_field->field_type; freeLttField(evType->root_field); + freeLttType(&root_type); } g_free(evType); } +void freeLttNamedType(LttType * type) +{ + int i; + g_free(type->type_name); + type->type_name = NULL; + freeLttType(&type); +} + void freeLttType(LttType ** type) { int i; if(*type == NULL) return; + if((*type)->type_name){ + return; //this is a named type + } if((*type)->element_name) g_free((*type)->element_name); if((*type)->fmt) @@ -354,8 +389,8 @@ void freeLttType(LttType ** type) } if((*type)->element_type){ - // for(i=0;i<(*type)->element_number;i++) - // freeLttType(&((*type)->element_type[i])); + for(i=0;i<(*type)->element_number;i++) + freeLttType(&((*type)->element_type[i])); g_free((*type)->element_type); } g_free(*type); @@ -365,7 +400,7 @@ void freeLttType(LttType ** type) void freeLttField(LttField * fld) { int i; - int size; + int size = 0; if(fld->field_type){ if(fld->field_type->type_class == LTT_ARRAY || @@ -374,7 +409,6 @@ void freeLttField(LttField * fld) }else if(fld->field_type->type_class == LTT_STRUCT){ size = fld->field_type->element_number; } - freeLttType(&(fld->field_type)); } if(fld->child){ diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index fa786985..b6561ca5 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -578,7 +578,8 @@ type_descriptor * find_named_type(char *name, table * named_types) t->type_name = allocAndCopy(name); t->type = NONE; t->fmt = NULL; - table_insert(named_types,allocAndCopy(name),t); + table_insert(named_types,t->type_name,t); + // table_insert(named_types,allocAndCopy(name),t); } return t; } diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 8edeb54c..420cb9d0 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -36,9 +36,6 @@ int skipEvent(LttTracefile * t); /* compare two time (LttTime), 0:t1=t2, -1:t1t2 */ int timecmp(LttTime * t1, LttTime * t2); -/* get an integer number */ -int getIntNumber(int size1, void *evD); - /***************************************************************************** @@ -776,6 +773,8 @@ LttEvent *ltt_tracefile_read(LttTracefile *t) 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); @@ -915,32 +914,23 @@ int skipEvent(LttTracefile * t) 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){ @@ -1103,6 +1093,7 @@ int getFieldtypeSize(LttTracefile * t, LttEventType * evT, int offsetRoot, }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; -- 2.34.1