From: yangxx Date: Wed, 16 Jul 2003 19:18:48 +0000 (+0000) Subject: new version of the reading API X-Git-Tag: v0.12.20~3385 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=963b5f2df23dc1c70bdc70d4aecb76f50651997b;p=lttv.git new version of the reading API git-svn-id: http://ltt.polymtl.ca/svn@104 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/include/ltt/trace.h b/ltt/branches/poly/include/ltt/trace.h index be0311fb..e96e73e4 100644 --- a/ltt/branches/poly/include/ltt/trace.h +++ b/ltt/branches/poly/include/ltt/trace.h @@ -1,5 +1,5 @@ -#ifndef TRACEFILE_H -#define TRACEFILE_H +#ifndef TRACE_H +#define TRACE_H #include @@ -18,10 +18,10 @@ void ltt_trace_close(LttTrace *t); /* The characteristics of the system on which the trace was obtained is described in a LttSystemDescription structure. */ -typedef struct _LttSystemDescription { +struct _LttSystemDescription { char *description; char *node_name; - char *domainname; + char *domain_name; unsigned nb_cpu; LttArchSize size; LttArchEndian endian; @@ -37,9 +37,9 @@ typedef struct _LttSystemDescription { unsigned ltt_block_size; LttTime trace_start; LttTime trace_end; -} LttSystemDescription; +}; -LttSystemDescription *ltt_trace_system_description(LttTrace *t) +LttSystemDescription *ltt_trace_system_description(LttTrace *t); /* Functions to discover the facilities in the trace. Once the number diff --git a/ltt/branches/poly/include/ltt/type.h b/ltt/branches/poly/include/ltt/type.h index dd53c096..e43a1fd6 100644 --- a/ltt/branches/poly/include/ltt/type.h +++ b/ltt/branches/poly/include/ltt/type.h @@ -1,8 +1,6 @@ #ifndef TYPE_H #define TYPE_H -#include - /* Different types allowed */ @@ -11,6 +9,8 @@ typedef enum _LttTypeEnum LTT_SEQUENCE, LTT_STRUCT, LTT_UNION } LttTypeEnum; +#include + /* All event types, data types and fields belong to their trace and are released at the same time. */ @@ -41,7 +41,7 @@ char *ltt_type_name(LttType *t); LttTypeEnum ltt_type_class(LttType *t); -unsigned ltt_type_size(LttTracefile *tf, LttType *t); +unsigned ltt_type_size(LttTrace *trace, LttType *t); /* The type of nested elements for arrays and sequences. */ diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index 791dabcc..ed605b9f 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -1,22 +1,21 @@ #include #include #include - #include #include "parser.h" #include /***************************************************************************** *Function name - * ltt_facility_eventtype_id: get event type id - * (base id + position of the event) + * ltt_event_eventtype_id: get event type id + * (base id + position of the event) *Input params - * e : an instance of an event type + * e : an instance of an event type *Return value - * unsigned : event type id + * unsigned : event type id ****************************************************************************/ -unsigned ltt_event_eventtype_id(ltt_event *e) +unsigned ltt_event_eventtype_id(LttEvent *e) { return (unsigned) e->event_id; } @@ -27,19 +26,14 @@ unsigned ltt_event_eventtype_id(ltt_event *e) *Input params * e : an instance of an event type *Return value - * ltt_facility * : the facility of the event + * LttFacility * : the facility of the event ****************************************************************************/ -ltt_facility *ltt_event_facility(ltt_event *e) +LttFacility *ltt_event_facility(LttEvent *e) { - ltt_eventtype * evT; - ptr_wrap * ptr; - ptr = (ptr_wrap*)g_ptr_array_index(e->tracefile->eventtype_event_id, - (gint)(e->event_id)); - evT = (ltt_eventtype*)(ptr->ptr); - - if(!evT) return NULL; - return evT->facility; + LttTrace * trace = e->tracefile->trace; + unsigned id = e->event_id; + return ltt_trace_facility_by_id(trace,id); } /***************************************************************************** @@ -48,71 +42,72 @@ ltt_facility *ltt_event_facility(ltt_event *e) *Input params * e : an instance of an event type *Return value - * ltt_eventtype * : the event type of the event + * LttEventType * : the event type of the event ****************************************************************************/ -ltt_eventtype *ltt_event_eventtype(ltt_event *e) +LttEventType *ltt_event_eventtype(LttEvent *e) { - ptr_wrap * ptr; - ptr = (ptr_wrap*)g_ptr_array_index(e->tracefile->eventtype_event_id, - (gint)(e->event_id)); - return (ltt_eventtype*)(ptr->ptr); + LttFacility* facility = ltt_event_facility(e); + if(!facility) return NULL; + return facility->events[e->event_id - facility->base_id]; } /***************************************************************************** *Function name - * ltt_event_time : get the time of the event + * ltt_event_field : get the root field of the event *Input params - * e : an instance of an event type + * e : an instance of an event type *Return value - * ltt_time : the time of the event + * LttField * : the root field of the event ****************************************************************************/ -ltt_time ltt_event_time(ltt_event *e) +LttField *ltt_event_field(LttEvent *e) { - return getEventTime(e->tracefile); + LttEventType * event_type = ltt_event_eventtype(e); + if(!event_type) return NULL; + return event_type->root_field; } /***************************************************************************** *Function name - * ltt_event_time : get the cycle count of the event + * ltt_event_time : get the time of the event *Input params * e : an instance of an event type *Return value - * ltt_time : the cycle count of the event + * LttTime : the time of the event ****************************************************************************/ -ltt_cycle_count ltt_event_cycle_count(ltt_event *e) +LttTime ltt_event_time(LttEvent *e) { - return e->cycle_count; + return e->event_time; } /***************************************************************************** *Function name - * ltt_event_cpu_i: get the cpu id where the event happens + * ltt_event_time : get the cycle count of the event *Input params * e : an instance of an event type *Return value - * unsigned : the cpu id + * LttCycleCount : the cycle count of the event ****************************************************************************/ -unsigned ltt_event_cpu_id(ltt_event *e) +LttCycleCount ltt_event_cycle_count(LttEvent *e) { - return e->tracefile->trace_header->cpu_id; + return e->event_cycle_count; } /***************************************************************************** *Function name - * ltt_event_cpu_i: get the name of the system where the event happens + * ltt_event_cpu_i: get the cpu id where the event happens *Input params * e : an instance of an event type *Return value - * char * : the name of the system + * unsigned : the cpu id ****************************************************************************/ -char *ltt_event_system_name(ltt_event *e) -{ - return e->tracefile->trace_header->system_name; +unsigned ltt_event_cpu_id(LttEvent *e) +{ + return (unsigned)atoi(e->tracefile->name); } /***************************************************************************** @@ -124,7 +119,7 @@ char *ltt_event_system_name(ltt_event *e) * void * : pointer to the raw data for the event ****************************************************************************/ -void *ltt_event_data(ltt_event *e) +void *ltt_event_data(LttEvent *e) { return e->data; } @@ -142,7 +137,7 @@ void *ltt_event_data(ltt_event *e) * unsigned : the number of elements for an array/sequence field ****************************************************************************/ -unsigned ltt_event_field_element_number(ltt_event *e, ltt_field *f) +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) @@ -160,20 +155,17 @@ unsigned ltt_event_field_element_number(ltt_event *e, ltt_field *f) * e : an instance of an event type ???? * f : a field of the instance * i : the ith element - *Return value - * int : ???? error number ****************************************************************************/ -int ltt_event_field_element_select(ltt_event *e, ltt_field *f, unsigned i) +void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) { if(f->field_type->type_class != LTT_ARRAY && f->field_type->type_class != LTT_SEQUENCE) - return -1; //????? + return ; - if(f->field_type->element_number < i || i == 0) return -1; //???? + if(f->field_type->element_number < i || i == 0) return; f->current_element = i - 1; - return 0; } /***************************************************************************** @@ -181,12 +173,12 @@ int ltt_event_field_element_select(ltt_event *e, ltt_field *f, unsigned i) * conversions ****************************************************************************/ -unsigned ltt_event_get_unsigned(ltt_event *e, ltt_field *f) +unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f) { - ltt_arch_size rSize = e->tracefile->trace_header->arch_size; - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; - ltt_type_enum t = f->field_type->type_class; + LttArchSize rSize = e->tracefile->trace->system_description->size; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; + LttTypeEnum t = f->field_type->type_class; if(t != LTT_UINT || t != LTT_ENUM) g_error("The type of the field is not unsigned int\n"); @@ -215,11 +207,11 @@ unsigned ltt_event_get_unsigned(ltt_event *e, ltt_field *f) } } -int ltt_event_get_int(ltt_event *e, ltt_field *f) +int ltt_event_get_int(LttEvent *e, LttField *f) { - ltt_arch_size rSize = e->tracefile->trace_header->arch_size; - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; + LttArchSize rSize = e->tracefile->trace->system_description->size; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; if(f->field_type->type_class != LTT_INT) g_error("The type of the field is not int\n"); @@ -248,12 +240,12 @@ int ltt_event_get_int(ltt_event *e, ltt_field *f) } } -unsigned long ltt_event_get_long_unsigned(ltt_event *e, ltt_field *f) +unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) { - ltt_arch_size rSize = e->tracefile->trace_header->arch_size; - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; - ltt_type_enum t = f->field_type->type_class; + LttArchSize rSize = e->tracefile->trace->system_description->size; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; + LttTypeEnum t = f->field_type->type_class; if(t != LTT_UINT || t != LTT_ENUM) g_error("The type of the field is not unsigned long\n"); @@ -275,11 +267,11 @@ unsigned long ltt_event_get_long_unsigned(ltt_event *e, ltt_field *f) } } -long int ltt_event_get_long_int(ltt_event *e, ltt_field *f) +long int ltt_event_get_long_int(LttEvent *e, LttField *f) { - ltt_arch_size rSize = e->tracefile->trace_header->arch_size; - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; + LttArchSize rSize = e->tracefile->trace->system_description->size; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; if( f->field_type->type_class != LTT_INT) g_error("The type of the field is not long int\n"); @@ -301,10 +293,10 @@ long int ltt_event_get_long_int(ltt_event *e, ltt_field *f) } } -float ltt_event_get_float(ltt_event *e, ltt_field *f) +float ltt_event_get_float(LttEvent *e, LttField *f) { - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; if(f->field_type->type_class != LTT_FLOAT || (f->field_type->type_class == LTT_FLOAT && f->field_size != 4)) @@ -319,10 +311,10 @@ float ltt_event_get_float(ltt_event *e, ltt_field *f) } } -double ltt_event_get_double(ltt_event *e, ltt_field *f) +double ltt_event_get_double(LttEvent *e, LttField *f) { - int revFlag = e->tracefile->my_arch_endian == - e->tracefile->trace_header->arch_endian ? 0:1; + int revFlag = e->tracefile->trace->my_arch_endian == + e->tracefile->trace->system_description->endian ? 0:1; if(f->field_type->type_class != LTT_FLOAT || (f->field_type->type_class == LTT_FLOAT && f->field_size != 8)) @@ -342,7 +334,7 @@ double ltt_event_get_double(ltt_event *e, ltt_field *f) * the same tracefile. ???? ****************************************************************************/ -char *ltt_event_get_string(ltt_event *e, ltt_field *f) +char *ltt_event_get_string(LttEvent *e, LttField *f) { if(f->field_type->type_class != LTT_STRING) g_error("The field contains no string\n"); diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index 5ededcaa..1c31f019 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -8,102 +8,92 @@ /* search for the (named) type in the table, if it does not exist create a new one */ -ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td); +LttType * lookup_named_type(LttFacility *fac, type_descriptor * td); /* construct directed acyclic graph for types, and tree for fields */ -void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, - ltt_field * fld); +void constructTypeAndFields(LttFacility * fac,type_descriptor * td, + LttField * fld); /* generate the facility according to the events belongin to it */ -void generateFacility(ltt_facility * facility, char * pathname, - ltt_checksum checksum, sequence * events); +void generateFacility(LttFacility * f, facility * fac, + LttChecksum checksum); /* functions to release the memory occupied by a facility */ -void freeFacility(ltt_facility * facility); -void freeEventtype(ltt_eventtype * evType); +void freeFacility(LttFacility * facility); +void freeEventtype(LttEventType * evType); void freeAllNamedTypes(table * named_types); void freeAllUnamedTypes(sequence * unnamed_types); void freeAllFields(sequence * all_fields); -void freeLttType(ltt_type * type); -void freeLttField(ltt_field * fld); +void freeLttType(LttType * type); +void freeLttField(LttField * fld); /***************************************************************************** *Function name - * ltt_facility_open : open a facility + * ltt_facility_open : open facilities *Input params + * t : the trace containing the facilities * pathname : the path name of the facility - * c : checksum of the facility registered in kernal - *Return value - * ltt_facility* : return a ltt_facility ****************************************************************************/ -ltt_facility * ltt_facility_open(char * pathname, ltt_checksum c) +void ltt_facility_open(LttTrace * t, char * pathname) { char *token; parse_file in; char buffer[BUFFER_SIZE]; - ltt_checksum checksum; - event *ev; - sequence events; - table namedTypes; - sequence unnamedTypes; - ltt_facility * aFacility = NULL; - - sequence_init(&events); - table_init(&namedTypes); - sequence_init(&unnamedTypes); + facility * fac; + LttFacility * f; + LttChecksum checksum; in.buffer = buffer; in.lineno = 0; in.error = error_callback; - in.name = appendString(pathname,".event"); + in.name = pathname; in.fp = fopen(in.name, "r"); - if(!in.fp )g_error("cannot open input file: %s\n", in.name); - + if(!in.fp ) in.error(&in,"cannot open input file"); + while(1){ token = getToken(&in); if(in.type == ENDFILE) break; - if(strcmp("event",token) == 0) { - ev = g_new(event,1); - sequence_push(&events,ev); - parseEvent(&in,ev, &unnamedTypes, &namedTypes); - } - else if(strcmp("type",token) == 0) { - parseTypeDefinition(&in, &unnamedTypes, &namedTypes); + if(strcmp(token, "<")) in.error(&in,"not a facility file"); + token = getName(&in); + + if(strcmp("facility",token) == 0) { + fac = g_new(facility, 1); + fac->name = NULL; + fac->description = NULL; + sequence_init(&(fac->events)); + table_init(&(fac->named_types)); + sequence_init(&(fac->unnamed_types)); + + parseFacility(&in, fac); + + //check if any namedType is not defined + checkNamedTypesImplemented(&fac->named_types); + + generateChecksum(fac->name, &checksum, &fac->events); + + f = g_new(LttFacility,1); + generateFacility(f, fac, checksum); + + t->facility_number++; + g_ptr_array_add(t->facilities,f); + + free(fac->name); + free(fac->description); + freeEvents(&fac->events); + sequence_dispose(&fac->events); + freeNamedType(&fac->named_types); + table_dispose(&fac->named_types); + freeTypes(&fac->unnamed_types); + sequence_dispose(&fac->unnamed_types); + free(fac); } - else g_error("event or type token expected\n"); + else in.error(&in,"facility token was expected"); } - fclose(in.fp); - - checkNamedTypesImplemented(&namedTypes); - - generateChecksum(pathname, &checksum, &events); - - //yxx disable during the test - aFacility = g_new(ltt_facility,1); - generateFacility(aFacility, pathname, checksum, &events); -/* - if(checksum == c){ - aFacility = g_new(ltt_facility,1); - generateFacility(aFacility, pathname, checksum, &events); - }else{ - g_error("local facility is different from the one registered in the kernel"); - } -*/ - - free(in.name); - freeEvents(&events); - sequence_dispose(&events); - freeNamedType(&namedTypes); - table_dispose(&namedTypes); - freeTypes(&unnamedTypes); - sequence_dispose(&unnamedTypes); - - return aFacility; } @@ -111,53 +101,46 @@ ltt_facility * ltt_facility_open(char * pathname, ltt_checksum c) *Function name * generateFacility : generate facility, internal function *Input params - * facility : facilty structure - * facName : facility name + * facility : LttFacilty structure + * fac : facility structure * checksum : checksum of the facility - * events : sequence of events belonging to the facility ****************************************************************************/ -void generateFacility(ltt_facility * facility, char * pathname, - ltt_checksum checksum, sequence * events) +void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) { - char * facilityName; + char * facilityName = fac->name; + sequence * events = &fac->events; int i; - ltt_eventtype * evType; - ltt_field * field; - ltt_type * type; - - //get the facility name (strip any leading directory) - facilityName = strrchr(pathname,'/'); - if(facilityName) facilityName++; - else facilityName = pathname; + LttEventType * evType; + LttField * field; + LttType * type; - facility->name = g_strdup(facilityName); - facility->event_number = events->position; - facility->checksum = checksum; - facility->usage_count = 0; + f->name = g_strdup(facilityName); + f->event_number = events->position; + f->checksum = checksum; //initialize inner structures - facility->events = g_new(ltt_eventtype*,facility->event_number); - sequence_init(&(facility->all_fields)); - sequence_init(&(facility->all_unnamed_types)); - table_init(&(facility->all_named_types)); + f->events = g_new(LttEventType*,f->event_number); + sequence_init(&(f->all_fields)); + sequence_init(&(f->all_unnamed_types)); + table_init(&(f->all_named_types)); //for each event, construct field tree and type graph for(i=0;iposition;i++){ - evType = g_new(ltt_eventtype,1); - facility->events[i] = evType; + evType = g_new(LttEventType,1); + f->events[i] = evType; evType->name = g_strdup(((event*)(events->array[i]))->name); evType->description=g_strdup(((event*)(events->array[i]))->description); - field = g_new(ltt_field, 1); - sequence_push(&(facility->all_fields), field); + field = g_new(LttField, 1); + sequence_push(&(f->all_fields), field); evType->root_field = field; - evType->facility = facility; + evType->facility = f; evType->index = i; field->field_pos = 0; - type = lookup_named_type(facility,((event*)(events->array[i]))->type); + type = lookup_named_type(f,((event*)(events->array[i]))->type); field->field_type = type; field->offset_root = 0; field->fixed_root = 1; @@ -171,7 +154,7 @@ void generateFacility(ltt_facility * facility, char * pathname, field->current_element = 0; //construct field tree and type graph - constructTypeAndFields(facility,((event*)(events->array[i]))->type,field); + constructTypeAndFields(f,((event*)(events->array[i]))->type,field); } } @@ -186,8 +169,8 @@ void generateFacility(ltt_facility * facility, char * pathname, * root_field : root field of the event ****************************************************************************/ -void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, - ltt_field * fld) +void constructTypeAndFields(LttFacility * fac,type_descriptor * td, + LttField * fld) { int i; type_descriptor * tmpTd; @@ -206,11 +189,11 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, }else if(td->type == LTT_ARRAY || td->type == LTT_SEQUENCE){ if(td->type == LTT_ARRAY) fld->field_type->element_number = (unsigned)td->size; - fld->field_type->element_type = g_new(ltt_type*,1); + fld->field_type->element_type = g_new(LttType*,1); tmpTd = td->nested_type; fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); - fld->child = g_new(ltt_field*, 1); - fld->child[0] = g_new(ltt_field, 1); + fld->child = g_new(LttField*, 1); + fld->child[0] = g_new(LttField, 1); sequence_push(&(fac->all_fields), fld->child[0]); fld->child[0]->field_pos = 0; @@ -228,12 +211,12 @@ void constructTypeAndFields(ltt_facility * 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(ltt_type*, td->fields.position); - fld->child = g_new(ltt_field*, td->fields.position); + fld->field_type->element_type = g_new(LttType*, td->fields.position); + 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); - fld->child[i] = g_new(ltt_field,1); + fld->child[i] = g_new(LttField,1); sequence_push(&(fac->all_fields), fld->child[i]); fld->child[i]->field_pos = i; @@ -264,26 +247,26 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, * fac : facility struct * td : type descriptor *Return value - * : either find the named type, or create a new ltt_type + * : either find the named type, or create a new LttType ****************************************************************************/ -ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td) +LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) { - ltt_type * lttType = NULL; + LttType * lttType = NULL; int i; char * name; if(td->type_name){ for(i=0;iall_named_types.keys.position;i++){ name = (char *)(fac->all_named_types.keys.array[i]); if(strcmp(name, td->type_name)==0){ - lttType = (ltt_type*)(fac->all_named_types.values.array[i]); + lttType = (LttType*)(fac->all_named_types.values.array[i]); break; } } } if(!lttType){ - lttType = g_new(ltt_type,1); + lttType = g_new(LttType,1); lttType->type_class = td->type; if(td->fmt) lttType->fmt = g_strdup(td->fmt); else lttType->fmt = NULL; @@ -316,11 +299,8 @@ ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td) * int : usage count ?? status ****************************************************************************/ -int ltt_facility_close(ltt_facility *f) +int ltt_facility_close(LttFacility *f) { - // f->usage_count--; - if(f->usage_count > 0) return f->usage_count; - //release the memory it occupied freeFacility(f); @@ -331,7 +311,7 @@ int ltt_facility_close(ltt_facility *f) * Functions to release the memory occupied by the facility ****************************************************************************/ -void freeFacility(ltt_facility * fac) +void freeFacility(LttFacility * fac) { int i; g_free(fac->name); //free facility name @@ -340,6 +320,7 @@ void freeFacility(ltt_facility * fac) for(i=0;ievent_number;i++){ freeEventtype(fac->events[i]); } + g_free(fac->events); //free all named types freeAllNamedTypes(&(fac->all_named_types)); @@ -354,7 +335,7 @@ void freeFacility(ltt_facility * fac) g_free(fac); } -void freeEventtype(ltt_eventtype * evType) +void freeEventtype(LttEventType * evType) { g_free(evType->name); if(evType->description) @@ -370,7 +351,7 @@ void freeAllNamedTypes(table * named_types) g_free((char*)(named_types->keys.array[i])); //free type - freeLttType((ltt_type*)(named_types->values.array[i])); + freeLttType((LttType*)(named_types->values.array[i])); } table_dispose(named_types); } @@ -379,7 +360,7 @@ void freeAllUnamedTypes(sequence * unnamed_types) { int i; for(i=0;iposition;i++){ - freeLttType((ltt_type*)(unnamed_types->array[i])); + freeLttType((LttType*)(unnamed_types->array[i])); } sequence_dispose(unnamed_types); } @@ -388,25 +369,33 @@ void freeAllFields(sequence * all_fields) { int i; for(i=0;iposition;i++){ - freeLttField((ltt_field*)(all_fields->array[i])); + freeLttField((LttField*)(all_fields->array[i])); } sequence_dispose(all_fields); } -void freeLttType(ltt_type * type) +//only free current type, not child types +void freeLttType(LttType * type) { + int i; if(type->element_name) g_free(type->element_name); if(type->fmt) g_free(type->fmt); - if(type->enum_strings) + if(type->enum_strings){ + for(i=0;ielement_number;i++) + g_free(type->enum_strings[i]); g_free(type->enum_strings); - if(type->element_type) + } + + if(type->element_type){ g_free(type->element_type); + } g_free(type); } -void freeLttField(ltt_field * fld) +//only free the current field, not child fields +void freeLttField(LttField * fld) { if(fld->child) g_free(fld->child); @@ -422,7 +411,7 @@ void freeLttField(ltt_field * fld) * char * : the facility's name ****************************************************************************/ -char *ltt_facility_name(ltt_facility *f) +char *ltt_facility_name(LttFacility *f) { return f->name; } @@ -433,14 +422,28 @@ char *ltt_facility_name(ltt_facility *f) *Input params * f : the facility that will be closed *Return value - * ltt_checksum : the checksum of the facility + * LttChecksum : the checksum of the facility ****************************************************************************/ -ltt_checksum ltt_facility_checksum(ltt_facility *f) +LttChecksum ltt_facility_checksum(LttFacility *f) { return f->checksum; } +/***************************************************************************** + *Function name + * ltt_facility_base_id : obtain the facility base id + *Input params + * f : the facility + *Return value + * : the base id of the facility + ****************************************************************************/ + +unsigned ltt_facility_base_id(LttFacility *f) +{ + return f->base_id; +} + /***************************************************************************** *Function name * ltt_facility_eventtype_number: obtain the number of the event types @@ -450,7 +453,7 @@ ltt_checksum ltt_facility_checksum(ltt_facility *f) * unsigned : the number of the event types ****************************************************************************/ -unsigned ltt_facility_eventtype_number(ltt_facility *f) +unsigned ltt_facility_eventtype_number(LttFacility *f) { return (unsigned)(f->event_number); } @@ -462,10 +465,10 @@ unsigned ltt_facility_eventtype_number(ltt_facility *f) *Input params * f : the facility that will be closed *Return value - * ltt_eventtype * : the event type required + * LttEventType * : the event type required ****************************************************************************/ -ltt_eventtype *ltt_facility_eventtype_get(ltt_facility *f, unsigned i) +LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i) { return f->events[i]; } @@ -479,13 +482,13 @@ ltt_eventtype *ltt_facility_eventtype_get(ltt_facility *f, unsigned i) * f : the facility that will be closed * name : the name of the event *Return value - * ltt_eventtype * : the event type required + * LttEventType * : the event type required ****************************************************************************/ -ltt_eventtype *ltt_facility_eventtype_get_by_name(ltt_facility *f, char *name) +LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name) { int i; - ltt_eventtype * ev; + LttEventType * ev; for(i=0;ievent_number;i++){ ev = f->events[i]; if(strcmp(ev->name, name) == 0)break; diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 2851188f..31e89a51 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -19,9 +19,8 @@ This program is distributed in the hope that it will be useful, Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This program reads the ".event" event definitions input files - specified as command line arguments and generates corresponding - ".c" and ".h" files required to trace such events in the kernel. +/* This program reads the ".xml" event definitions input files + and constructs structure for each event. The program uses a very simple tokenizer, called from a hand written recursive descent parser to fill a data structure describing the events. @@ -31,7 +30,7 @@ This program is distributed in the hope that it will be useful, A table of named types is maintained to allow refering to types by name when the same type is used at several places. Finally a sequence of all types is maintained to facilitate the freeing of all type - information when the processing of an ".event" file is finished. */ + information when the processing of an ".xml" file is finished. */ #include #include @@ -100,7 +99,9 @@ void error_callback(parse_file *in, char *msg) void * memAlloc(int size) { - void *addr = malloc(size); + void * addr; + if(size == 0) return NULL; + addr = malloc(size); if(!addr){ printf("Failed to allocate memory"); exit(1); @@ -119,11 +120,173 @@ void * memAlloc(int size) char *allocAndCopy(char *str) { - char *addr = (char *)memAlloc(strlen(str)+1); + char * addr; + if(str == NULL) return NULL; + addr = (char *)memAlloc(strlen(str)+1); strcpy(addr,str); return addr; } +/************************************************************************** + * Function : + * getNameAttribute,getFormatAttribute,getSizeAttribute,getValueAttribute + * getValueStrAttribute + * Description : + * Read the attribute from the input file. + * + * Parameters : + * in , input file handle. + * + * Return values : + * address of the attribute. + * + **************************************************************************/ + +char * getNameAttribute(parse_file *in) +{ + char * token, car; + token = getName(in); + if(strcmp("name",token))in->error(in,"name was expected"); + getEqual(in); + + car = seekNextChar(in); + if(car == EOF)in->error(in,"name was expected"); + else if(car == '\"')token = getQuotedString(in); + else token = getName(in); + return token; +} + +char * getFormatAttribute(parse_file *in) +{ + char * token; + + //format is an option + token = getToken(in); + if(strcmp("/",token) == 0){ + ungetToken(in); + return NULL; + } + + if(strcmp("format",token))in->error(in,"format was expected"); + getEqual(in); + token = getQuotedString(in); + return token; +} + +int getSizeAttribute(parse_file *in) +{ + char * token; + getName(in); + getEqual(in); + + return getSize(in); +} + +int getValueAttribute(parse_file *in) +{ + char * token; + getName(in); + getEqual(in); + + return getNumber(in); +} + +//for