From 47299663f9a2f077317b95f7e669e8373052364b Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 9 Nov 2005 04:14:14 +0000 Subject: [PATCH] logging functions parameters git-svn-id: http://ltt.polymtl.ca/svn@1313 04897980-b3bd-0310-b5e0-8ef037075253 --- genevent-new/genevent.c | 80 ++++++++++++++++++++++++++++--- genevent-new/parser.c | 103 +++++++++++++++++++++++++--------------- genevent-new/parser.h | 5 +- genevent-new/test.xml | 60 ++++++++++------------- 4 files changed, 166 insertions(+), 82 deletions(-) diff --git a/genevent-new/genevent.c b/genevent-new/genevent.c index 92342a66..118298ce 100644 --- a/genevent-new/genevent.c +++ b/genevent-new/genevent.c @@ -255,7 +255,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, } fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %llu\n", basename, td->size); - print_type(td->nested_type, fd, tabs, basename, ""); + if(print_type(td->nested_type, fd, tabs, basename, "")) return 1; fprintf(fd, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename, basename); fprintf(fd, "\n"); @@ -274,7 +274,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "unsigned int len;\n"); print_tabs(1, fd); - print_type(td->nested_type, fd, tabs, basename, ""); + if(print_type(td->nested_type, fd, tabs, basename, "")) return 1; fprintf(fd, " *array;\n"); fprintf(fd, "};\n"); fprintf(fd, "\n"); @@ -296,7 +296,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, field_t *field = (field_t*)(td->fields.array[i]); type_descriptor_t *type = field->type; print_tabs(1, fd); - print_type(type, fd, tabs, basename, field->name); + if(print_type(type, fd, tabs, basename, field->name)) return 1; fprintf(fd, " "); fprintf(fd, "%s", field->name); fprintf(fd, ";\n"); @@ -311,8 +311,8 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, type_descriptor_t *type = field->type; if(type->type_name == NULL) { /* Not a named nested type : we must print its declaration first */ - //if(print_type_declaration(type, - // fd, 0, basename, field->name)) return 1; + if(print_type_declaration(type, + fd, 0, basename, field->name)) return 1; } } fprintf(fd, "union lttng_%s", basename); @@ -321,7 +321,7 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, field_t *field = (field_t*)(td->fields.array[i]); type_descriptor_t *type = field->type; print_tabs(1, fd); - print_type(type, fd, tabs, basename, field->name); + if(print_type(type, fd, tabs, basename, field->name)) return 1; fprintf(fd, " "); fprintf(fd, "%s", field->name); fprintf(fd, ";\n"); @@ -337,7 +337,38 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, return 0; } +/* Print the logging function of an event. This is the core of genevent */ +int print_event_logging_function(char *basename, event_t *event, FILE *fd) +{ + fprintf(fd, "static inline void trace_%s(\n", basename); + for(unsigned int j = 0; j < event->fields.position; j++) { + /* For each field, print the function argument */ + field_t *f = (field_t*)event->fields.array[j]; + type_descriptor_t *t = f->type; + print_tabs(2, fd); + if(print_type(t, fd, 0, basename, f->name)) return 1; + fprintf(fd, " %s", f->name); + if(j < event->fields.position-1) { + fprintf(fd, ","); + fprintf(fd, "\n"); + } + } + if(event->fields.position == 0) { + print_tabs(2, fd); + fprintf(fd, "void"); + } + fprintf(fd,")\n"); + fprintf(fd, "#ifndef CONFIG_LTT\n"); + fprintf(fd, "{\n"); + fprintf(fd, "}\n"); + fprintf(fd,"#else\n"); + fprintf(fd, "{\n"); + + fprintf(fd, "}\n"); + fprintf(fd, "#endif //CONFIG_LTT\n\n"); + return 0; +} /* ltt-facility-name.h : main logging header. @@ -347,11 +378,13 @@ void print_log_header_head(facility_t *fac, FILE *fd) { fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname); fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname); + fprintf(fd, "\n"); + fprintf(fd, "/* Facility activation at compile time. */\n"); + fprintf(fd, "#ifdef CONFIG_LTT_FACILITY_%s\n\n", fac->capname); } - int print_log_header_types(facility_t *fac, FILE *fd) { sequence_t *types = &fac->named_types.values; @@ -368,13 +401,46 @@ int print_log_header_types(facility_t *fac, FILE *fd) int print_log_header_events(facility_t *fac, FILE *fd) { + sequence_t *events = &fac->events; + char basename[PATH_MAX]; + unsigned int facname_len; + + strncpy(basename, fac->name, PATH_MAX); + facname_len = strlen(basename); + strncat(basename, "_", PATH_MAX-facname_len); + facname_len = strlen(basename); + + for(unsigned int i = 0; i < events->position; i++) { + event_t *event = (event_t*)events->array[i]; + strncpy(&basename[facname_len], event->name, PATH_MAX-facname_len); + + /* For each event, print structure, and then logging function */ + fprintf(fd, "/* Event %s structures */\n", + event->name); + for(unsigned int j = 0; j < event->fields.position; j++) { + /* For each unnamed type, print the definition */ + field_t *f = (field_t*)event->fields.array[j]; + type_descriptor_t *t = f->type; + if(t->type_name == NULL) + if((print_type_declaration(t, fd, 0, basename, f->name))) return 1; + } + fprintf(fd, "\n"); + + fprintf(fd, "/* Event %s logging function */\n", + event->name); + + if(print_event_logging_function(basename, event, fd)) return 1; + fprintf(fd, "\n"); + } + return 0; } void print_log_header_tail(facility_t *fac, FILE *fd) { + fprintf(fd, "#endif //CONFIG_LTT_FACILITY_%s\n\n", fac->capname); fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname); } diff --git a/genevent-new/parser.c b/genevent-new/parser.c index 638aa5ab..ce416ed9 100644 --- a/genevent-new/parser.c +++ b/genevent-new/parser.c @@ -468,36 +468,62 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, table_t * named_types) { char *token; + field_t *f; + sequence_init(&(ev->fields)); // getEventAttributes(in, ev); if(ev->name == NULL) in->error(in, "Event not named"); getRAnglebracket(in); - //... + //... ev->description = getDescription(in); - //event can have STRUCT, TYPEREF or NOTHING - getLAnglebracket(in); - - token = getToken(in); - if(in->type == FORWARDSLASH){ // NOTHING - ev->type = NULL; - }else if(in->type == NAME){ - if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){ - ungetToken(in); - ev->type = parseType(in,NULL, unnamed_types, named_types); - if(ev->type->type != STRUCT && ev->type->type != NONE) - in->error(in,"type must be a struct"); - }else in->error(in, "not a valid type"); - - getLAnglebracket(in); - getForwardslash(in); - }else in->error(in,"not a struct type"); - - token = getName(in); - if(strcmp("event",token))in->error(in,"not an event definition"); - getRAnglebracket(in); // + int got_end = 0; + /* Events can have multiple fields. each field form at least a function + * parameter of the logging function. */ + while(!got_end) { + getLAnglebracket(in); + token = getToken(in); + + switch(in->type) { + case FORWARDSLASH: /* */ + token = getName(in); + if(strcmp("event",token))in->error(in,"not an event definition"); + getRAnglebracket(in); // + got_end = 1; + break; + case NAME: /* a field */ + if(strcmp("field",token))in->error(in,"expecting a field"); + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(ev->fields),f); + parseFields(in, f, unnamed_types, named_types); + break; + default: + in->error(in, "expecting or "); + break; + } + } +#if 0 + if(in->type == FORWARDSLASH){ // NOTHING + ev->type = NULL; + }else if(in->type == NAME){ + if(strcmp("struct",token)==0 || strcmp("typeref",token)==0){ + ungetToken(in); + ev->type = parseType(in,NULL, unnamed_types, named_types); + if(ev->type->type != STRUCT && ev->type->type != NONE) + in->error(in,"type must be a struct"); + }else in->error(in, "not a valid type"); + + getLAnglebracket(in); + getForwardslash(in); + }else in->error(in,"not a struct type"); + getLAnglebracket(in); + getForwardslash(in); + token = getName(in); + if(strcmp("event",token))in->error(in,"not an event definition"); + getRAnglebracket(in); // +#endif //0 } /***************************************************************************** @@ -505,20 +531,16 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, * parseField : get field infomation from buffer *Input params * in : input file handle - * t : type descriptor + * f : field * unnamed_types : array of unamed types * named_types : array of named types ****************************************************************************/ -void parseFields(parse_file_t *in, type_descriptor_t *t, +void parseFields(parse_file_t *in, field_t *f, sequence_t * unnamed_types, table_t * named_types) { char * token; - field_t *f; - - f = (field_t *)memAlloc(sizeof(field_t)); - sequence_push(&(t->fields),f); // getFieldAttributes(in, f); @@ -564,6 +586,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, { char *token; type_descriptor_t *t; + field_t *f; if(inType == NULL) { t = (type_descriptor_t *) memAlloc(sizeof(type_descriptor_t)); @@ -584,7 +607,10 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, token = getToken(in); sequence_init(&(t->fields)); while(strcmp("field",token) == 0){ - parseFields(in,t, unnamed_types, named_types); + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(t->fields),f); + + parseFields(in, f, unnamed_types, named_types); //next field getLAnglebracket(in); @@ -605,7 +631,9 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, token = getToken(in); sequence_init(&(t->fields)); while(strcmp("field",token) == 0){ - parseFields(in,t, unnamed_types, named_types); + f = (field_t *)memAlloc(sizeof(field_t)); + sequence_push(&(t->fields),f); + parseFields(in, f, unnamed_types, named_types); //next field getLAnglebracket(in); @@ -1159,18 +1187,16 @@ void generateChecksum(char* facName, unsigned long crc ; int pos; event_t * ev; - char str[256]; crc = crc32(facName); for(pos = 0; pos < events->position; pos++){ ev = (event_t *)(events->array[pos]); - crc = partial_crc32(ev->name,crc); - if(!ev->type) continue; //event without type - if(ev->type->type != STRUCT){ - sprintf(str,"event '%s' has a type other than STRUCT",ev->name); - error_callback(NULL, str); - } - crc = getTypeChecksum(crc, ev->type); + crc = partial_crc32(ev->name, crc); + for(unsigned int i = 0; i < ev->fields.position; i++) { + field_t *f = (field_t*)ev->fields.array[i]; + crc = partial_crc32(f->name, crc); + crc = getTypeChecksum(crc, f->type); + } } *checksum = crc; } @@ -1362,6 +1388,7 @@ void freeEvents(sequence_t *t) ev = (event_t *) t->array[pos]; free(ev->name); free(ev->description); + sequence_dispose(&ev->fields); free(ev); } diff --git a/genevent-new/parser.h b/genevent-new/parser.h index 482e16d0..e19dc93d 100644 --- a/genevent-new/parser.h +++ b/genevent-new/parser.h @@ -131,7 +131,8 @@ typedef struct _field{ typedef struct _event { char *name; char *description; - type_descriptor_t *type; + //type_descriptor_t *type; + sequence_t fields; /* event fields */ int per_trace; /* Is the event able to be logged to a specific trace ? */ int per_tracefile; /* Must we log this event in a specific tracefile ? */ } event_t; @@ -156,7 +157,7 @@ void parseTypeDefinition(parse_file_t *in, sequence_t * unnamed_types, table_t * named_types); type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types); -void parseFields(parse_file_t *in, type_descriptor_t *t, +void parseFields(parse_file_t *in, field_t *f, sequence_t * unnamed_types, table_t * named_types); void checkNamedTypesImplemented(table_t * namedTypes); type_descriptor_t * find_named_type(char *name, table_t * named_types); diff --git a/genevent-new/test.xml b/genevent-new/test.xml index 835d6b9a..a71ad8b9 100644 --- a/genevent-new/test.xml +++ b/genevent-new/test.xml @@ -3,10 +3,8 @@ System call entry - - Syscall entry number in entry.S - Address from which call was made - + Syscall entry number in entry.S + Address from which call was made @@ -15,60 +13,52 @@ Entry in a trap - - Trap number - Address where trap occured - + Trap number + Address where trap occured - Exit from a trap + Exit from a trap - Soft IRQ entry - - Soft IRQ number - + Soft IRQ entry + Soft IRQ number - Soft IRQ exit - - Soft IRQ number - + Soft IRQ exit + Soft IRQ number - Tasklet entry - - Tasklet priority - Tasklet function address - Tasklet data address - + Tasklet entry + Tasklet priority + Tasklet function address + Tasklet data address - Tasklet exit - - Tasklet priority - Tasklet function address - Tasklet data address - + Tasklet exit + Tasklet priority + Tasklet function address + Tasklet data address - Entry in an irq - - IRQ number - Are we executing kernel code - + Entry in an irq + IRQ number + Are we executing kernel code - Exit from an IRQ + Exit from an IRQ + + + +