From 2fef3d3e1a0425e9aeedbf4b7c2e7af5d13869ef Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 15 Mar 2007 00:08:20 +0000 Subject: [PATCH] adding compact data git-svn-id: http://ltt.polymtl.ca/svn@2422 04897980-b3bd-0310-b5e0-8ef037075253 --- genevent/genevent.c | 87 ++++++++++++++++++++++++++++------------ genevent/parser.c | 98 +++++++++++++++++++++++++++------------------ genevent/parser.h | 42 +++++++++++-------- 3 files changed, 145 insertions(+), 82 deletions(-) diff --git a/genevent/genevent.c b/genevent/genevent.c index fb564597..220cbd70 100644 --- a/genevent/genevent.c +++ b/genevent/genevent.c @@ -489,7 +489,10 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, fprintf(fd, "%s", field->name); fprintf(fd, ";\n"); } - fprintf(fd, "} LTT_ALIGN;\n"); + if(td->fac->align) + fprintf(fd, "} LTT_ALIGN;\n"); + else + fprintf(fd, "};\n"); fprintf(fd, "\n"); break; case UNION: @@ -513,7 +516,10 @@ int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, fprintf(fd, "%s", field->name); fprintf(fd, ";\n"); } - fprintf(fd, "} LTT_ALIGN;\n"); + if(td->fac->align) + fprintf(fd, "} LTT_ALIGN;\n"); + else + fprintf(fd, "};\n"); fprintf(fd, "\n"); break; default: @@ -719,7 +725,10 @@ int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs, case ENUM: print_tabs(tabs, fd); fprintf(fd, "align = "); - if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; + if(td->fac->align) { + if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; + } else + fprintf(fd, "0"); fprintf(fd, ";\n"); fprintf(fd, "\n"); print_tabs(tabs, fd); @@ -842,6 +851,7 @@ int print_type_alignment_fct(type_descriptor_t * td, FILE *fd, unsigned int basename_len = 0; if(td->custom_write) return 0; /* Does print custom type */ + if(td->fac->align == 0) return 0; strncpy(basename, nest_name, PATH_MAX); basename_len = strlen(basename); @@ -1185,7 +1195,10 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "align = "); - if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; + if(td->fac->align) { + if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; + } else + fprintf(fd, "0"); fprintf(fd, ";\n"); fprintf(fd, "\n"); print_tabs(1, fd); @@ -1278,7 +1291,8 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n"); print_tabs(1, fd); - fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); + if(td->fac->align) + fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); print_tabs(1, fd); fprintf(fd, "*to_base = *to_base+*to;\n"); print_tabs(1, fd); @@ -1302,7 +1316,8 @@ int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, print_tabs(1, fd); fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n"); print_tabs(1, fd); - fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); + if(td->fac->align) + fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); print_tabs(1, fd); fprintf(fd, "*to_base = *to_base+*to;\n"); print_tabs(1, fd); @@ -1464,11 +1479,13 @@ int print_event_logging_function(char *basename, facility_t *fac, fprintf(fd, "size_t before_hdr_pad, after_hdr_pad, header_size;\n"); fprintf(fd, "\n"); - print_tabs(1, fd); - fprintf(fd, "if (ltt_traces.num_active_traces == 0)\n"); - print_tabs(2, fd); - fprintf(fd, "return;\n"); - fprintf(fd, "\n"); + if(!event->force) { + print_tabs(1, fd); + fprintf(fd, "if (ltt_traces.num_active_traces == 0)\n"); + print_tabs(2, fd); + fprintf(fd, "return;\n"); + fprintf(fd, "\n"); + } /* Calculate event variable len + event data alignment offset. * Assume that the padding for alignment starts at a void* @@ -1535,10 +1552,12 @@ int print_event_logging_function(char *basename, facility_t *fac, /* For each trace */ print_tabs(1, fd); fprintf(fd, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n"); - print_tabs(2, fd); - fprintf(fd, "if (!trace->active)\n"); - print_tabs(3, fd); - fprintf(fd, "continue;\n\n"); + if(!event->force) { + print_tabs(2, fd); + fprintf(fd, "if (!trace->active)\n"); + print_tabs(3, fd); + fprintf(fd, "continue;\n\n"); + } if(event->per_trace) { print_tabs(2, fd); @@ -1576,13 +1595,23 @@ int print_event_logging_function(char *basename, facility_t *fac, fprintf(fd, "\n"); /* Write event header */ - print_tabs(2, fd); - fprintf(fd, "ltt_write_event_header(trace, channel, buffer,\n"); - print_tabs(3, fd); - fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, - fac->name, event->name); - print_tabs(3, fd); - fprintf(fd, "reserve_size, before_hdr_pad, tsc);\n"); + if(strcmp("compact", fac->name) != 0) { + print_tabs(2, fd); + fprintf(fd, "ltt_write_event_header(trace, channel, buffer,\n"); + print_tabs(3, fd); + fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, + fac->name, event->name); + print_tabs(3, fd); + fprintf(fd, "reserve_size, before_hdr_pad, tsc);\n"); + } else { + print_tabs(2, fd); + fprintf(fd, "ltt_write_compact_header(trace, channel, buffer,\n"); + print_tabs(3, fd); + fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, + fac->name, event->name); + print_tabs(3, fd); + fprintf(fd, "reserve_size, before_hdr_pad, tsc, compact_data);\n"); + } print_tabs(2, fd); fprintf(fd, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n"); fprintf(fd, "\n"); @@ -2224,7 +2253,8 @@ int print_log_header_types(facility_t *fac, FILE *fd) if(print_type_declaration(types->array[i], fd, 0, "", "")) return 1; /* Print also the align function */ - if(print_type_alignment_fct(types->array[i], fd, + if(((type_descriptor_t*)types->array[i])->fac->align) + if(print_type_alignment_fct(types->array[i], fd, 0, "", "")) return 1; /* Print also the write function */ if(print_type_write_fct(types->array[i], fd, @@ -2258,7 +2288,9 @@ int print_log_header_events(facility_t *fac, FILE *fd) if(t->type_name == NULL) { if((print_type_declaration(t, fd, 0, basename, f->name))) return 1; /* Print also the align function */ - if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1; + if(fac->align) { + if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1; + } /* Print also the write function */ if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1; } @@ -2528,6 +2560,8 @@ int print_loader_header(facility_t *fac) fprintf(fd,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac->name); fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n", fac->name); + fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t%u\n\n", + fac->align); fprintf(fd, "#endif //CONFIG_LTT\n\n"); fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname); @@ -2590,6 +2624,8 @@ int print_loader_header_user(facility_t *fac) fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name); fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n", fac->name); + fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t\t\t\t%u\n\n", + fac->align); fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname); fclose(fd); @@ -2671,6 +2707,7 @@ int print_loader_c(facility_t *fac) fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n"); fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n"); fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n"); + fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT,\n"); fprintf(fd, "};\n"); fprintf(fd, "\n"); fprintf(fd, "static int __init facility_init(void)\n"); @@ -2771,7 +2808,7 @@ int print_loader_c_user(facility_t *fac) fprintf(fd, "\t.name = LTT_FACILITY_NAME,\n"); fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n"); fprintf(fd, "#ifndef LTT_PACK\n"); - fprintf(fd, "\t.alignment = sizeof(void*),\n"); + fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,\n"); fprintf(fd, "#else\n"); fprintf(fd, "\t.alignment = 0,\n"); fprintf(fd, "#endif //LTT_PACK\n"); diff --git a/genevent/parser.c b/genevent/parser.c index 0ac6f545..2a7dd1e5 100644 --- a/genevent/parser.c +++ b/genevent/parser.c @@ -195,7 +195,7 @@ char *allocAndCopy(char *str) **************************************************************************/ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, - sequence_t * unnamed_types, table_t * named_types) + sequence_t * unnamed_types, table_t * named_types) { char * token; int car; @@ -203,7 +203,7 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, t->fmt = NULL; t->size = 0; t->custom_write = 0; - t->network = 0; + t->network = 0; while(1) { token = getToken(in); @@ -226,26 +226,26 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, t->size = getSize(in); } else if(!strcmp("custom_write", token)) { t->custom_write = 1; - } else if(!strcmp("byte_order",token)) { - getEqual(in); - car = seekNextChar(in); - if(car == EOF) in->error(in,"byte order was expected (network?)"); - else if(car == '\"') token = getQuotedString(in); - else token = getName(in); - if(!strcmp("network", token)) { - t->network = 1; - } - } else if(!strcmp("write",token)) { - getEqual(in); - car = seekNextChar(in); - if(car == EOF) in->error(in,"write type was expected (custom?)"); - else if(car == '\"') token = getQuotedString(in); - else token = getName(in); - if(!strcmp("custom", token)) { - t->custom_write = 1; - } - } - } + } else if(!strcmp("byte_order",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"byte order was expected (network?)"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp("network", token)) { + t->network = 1; + } + } else if(!strcmp("write",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"write type was expected (custom?)"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp("custom", token)) { + t->custom_write = 1; + } + } + } } /************************************************************************** @@ -271,6 +271,8 @@ void getEventAttributes(parse_file_t *in, event_t *ev) ev->param_buffer = 0; ev->no_instrument_function = 0; ev->high_priority = 0; + ev->force = 0; + ev->compact_data = 0; while(1) { token = getToken(in); @@ -310,6 +312,10 @@ void getEventAttributes(parse_file_t *in, event_t *ev) ev->no_instrument_function = 1; else if(!strcmp(token, "high_priority")) ev->high_priority = 1; + else if(!strcmp(token, "force")) + ev->force = 1; + else if(!strcmp(token, "compact_data")) + ev->compact_data = 1; } } } @@ -333,7 +339,8 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) fac->name = NULL; fac->arch = NULL; - fac->user = 0; + fac->align = 1; + fac->user = 0; while(1) { token = getToken(in); @@ -354,8 +361,12 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) getEqual(in); car = seekNextChar(in); if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in)); - else fac->arch = allocAndCopy(getName(in)); - } + else fac->arch = allocAndCopy(getName(in)); + } else if(!strcmp("align", token)) { + getEqual(in); + fac->align = getSize(in); + } + } } @@ -530,9 +541,9 @@ void parseFacility(parse_file_t *in, facility_t * fac) if(strcmp("event",token) == 0){ ev = (event_t*) memAlloc(sizeof(event_t)); sequence_push(&(fac->events),ev); - parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types)); + parseEvent(fac, in, ev, &(fac->unnamed_types), &(fac->named_types)); }else if(strcmp("type",token) == 0){ - parseTypeDefinition(in, &(fac->unnamed_types), &(fac->named_types)); + parseTypeDefinition(fac, in, &(fac->unnamed_types), &(fac->named_types)); }else if(in->type == FORWARDSLASH){ break; }else in->error(in,"event or type token expected\n"); @@ -546,7 +557,8 @@ void parseFacility(parse_file_t *in, facility_t * fac) /***************************************************************************** *Function name * parseEvent : generate event from event definition - *Input params + *Input params + * fac : facility holding the event * in : input file handle * ev : new event * unnamed_types : array of unamed types @@ -555,12 +567,13 @@ void parseFacility(parse_file_t *in, facility_t * fac) * ev : new event (parameters are passed to it) ****************************************************************************/ -void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, +void parseEvent(facility_t *fac, parse_file_t *in, event_t * ev, sequence_t * unnamed_types, table_t * named_types) { char *token; field_t *f; + ev->fac = fac; sequence_init(&(ev->fields)); // getEventAttributes(in, ev); @@ -588,7 +601,7 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, 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, 1); + parseFields(fac, in, f, unnamed_types, named_types, 1); break; default: in->error(in, "expecting or "); @@ -621,6 +634,7 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, *Function name * parseField : get field infomation from buffer *Input params + * fac : facility holding the field * in : input file handle * f : field * unnamed_types : array of unamed types @@ -628,12 +642,13 @@ void parseEvent(parse_file_t *in, event_t * ev, sequence_t * unnamed_types, * tag : is field surrounded by a tag ? ****************************************************************************/ -void parseFields(parse_file_t *in, field_t *f, +void parseFields(facility_t *fac, parse_file_t *in, field_t *f, sequence_t * unnamed_types, table_t * named_types, int tag) { char * token; + f->fac = fac; if(tag) { // getFieldAttributes(in, f); @@ -647,7 +662,7 @@ void parseFields(parse_file_t *in, field_t *f, // getLAnglebracket(in); - f->type = parseType(in,NULL, unnamed_types, named_types); + f->type = parseType(fac, in,NULL, unnamed_types, named_types); if(tag) { getLAnglebracket(in); @@ -671,6 +686,7 @@ void parseFields(parse_file_t *in, field_t *f, * type name: * type(name,type) *Input params + * fac : facility * in : input file handle * inType : a type descriptor * unnamed_types : array of unamed types @@ -679,7 +695,7 @@ void parseFields(parse_file_t *in, field_t *f, * type_descriptor* : a type descriptor ****************************************************************************/ -type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, +type_descriptor_t *parseType(facility_t *fac, parse_file_t *in, type_descriptor_t *inType, sequence_t * unnamed_types, table_t * named_types) { char *token; @@ -694,6 +710,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, sequence_push(unnamed_types,t); } else t = inType; + t->fac = fac; token = getName(in); @@ -708,7 +725,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, f = (field_t *)memAlloc(sizeof(field_t)); sequence_push(&(t->fields),f); - parseFields(in, f, unnamed_types, named_types, 1); + parseFields(fac, in, f, unnamed_types, named_types, 1); //next field getLAnglebracket(in); @@ -731,7 +748,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, while(strcmp("field",token) == 0){ f = (field_t *)memAlloc(sizeof(field_t)); sequence_push(&(t->fields),f); - parseFields(in, f, unnamed_types, named_types, 1); + parseFields(fac, in, f, unnamed_types, named_types, 1); //next field getLAnglebracket(in); @@ -757,7 +774,7 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, f->name = NULL; sequence_push(&(t->fields),f); - parseFields(in, f, unnamed_types, named_types, 0); + parseFields(fac, in, f, unnamed_types, named_types, 0); //getLAnglebracket(in); // //t->nested_type = parseType(in, NULL, unnamed_types, named_types); @@ -780,14 +797,14 @@ type_descriptor_t *parseType(parse_file_t *in, type_descriptor_t *inType, f = (field_t *)memAlloc(sizeof(field_t)); f->name = NULL; sequence_push(&(t->fields),f); - parseFields(in, f, unnamed_types, named_types, 0); + parseFields(fac, in, f, unnamed_types, named_types, 0); //getLAnglebracket(in); // /* subfield */ f = (field_t *)memAlloc(sizeof(field_t)); f->name = NULL; sequence_push(&(t->fields),f); - parseFields(in, f, unnamed_types, named_types, 0); + parseFields(fac, in, f, unnamed_types, named_types, 0); //getLAnglebracket(in); // //t->length_type = parseType(in, NULL, unnamed_types, named_types); @@ -1023,12 +1040,13 @@ type_descriptor_t * create_named_type(char *name, table_t * named_types) *Function name * parseTypeDefinition : get type information from type definition *Input params + * fac : facility * in : input file handle * unnamed_types : array of unamed types * named_types : array of named types *****************************************************************************/ -void parseTypeDefinition(parse_file_t * in, sequence_t * unnamed_types, +void parseTypeDefinition(facility_t *fac, parse_file_t * in, sequence_t * unnamed_types, table_t * named_types) { char *token; @@ -1044,7 +1062,7 @@ void parseTypeDefinition(parse_file_t * in, sequence_t * unnamed_types, token = getName(in); //MD ??if(strcmp("struct",token))in->error(in,"not a valid type definition"); ungetToken(in); - parseType(in,t, unnamed_types, named_types); + parseType(fac, in,t, unnamed_types, named_types); // getLAnglebracket(in); diff --git a/genevent/parser.h b/genevent/parser.h index 8fd75743..a4b3723b 100644 --- a/genevent/parser.h +++ b/genevent/parser.h @@ -101,7 +101,11 @@ typedef enum _data_type { NONE } data_type_t; +typedef struct _facility facility_t; +typedef struct _event event_t; + typedef struct _type_descriptor { + facility_t *fac; char * type_name; //used for named type data_type_t type; char *fmt; @@ -116,9 +120,9 @@ typedef struct _type_descriptor { } type_descriptor_t; - /* Fields within types or events */ typedef struct _field{ + facility_t *fac; char *name; char *description; type_descriptor_t *type; @@ -127,42 +131,46 @@ typedef struct _field{ /* Events definitions */ -typedef struct _event { +struct _event { + facility_t *fac; char *name; char *description; //type_descriptor_t *type; - sequence_t fields; /* event fields */ + 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 ? */ - int param_buffer; /* For userspace tracing : takes a buffer as parameter? */ - int no_instrument_function; - int high_priority; -} event_t; + int param_buffer; /* For userspace tracing : takes a buffer as parameter? */ + int no_instrument_function; + int high_priority; + int force; + int compact_data; +}; -typedef struct _facility { +struct _facility { char * name; - char * capname; - char * arch; + char * capname; + char * arch; + int align; /* Alignment : default 1, 0 no alignment. */ char * description; sequence_t events; sequence_t unnamed_types; //FIXME : remove table_t named_types; - unsigned int checksum; - int user; /* Is this a userspace facility ? */ -} facility_t; + unsigned int checksum; + int user; /* Is this a userspace facility ? */ +}; int getSizeindex(unsigned int value); unsigned long long int getSize(parse_file_t *in); unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor_t * type); void parseFacility(parse_file_t *in, facility_t * fac); -void parseEvent(parse_file_t *in, event_t *ev, sequence_t * unnamed_types, +void parseEvent(facility_t *fac, parse_file_t *in, event_t *ev, sequence_t * unnamed_types, table_t * named_types); -void parseTypeDefinition(parse_file_t *in, +void parseTypeDefinition(facility_t *fac, parse_file_t *in, sequence_t * unnamed_types, table_t * named_types); -type_descriptor_t *parseType(parse_file_t *in, +type_descriptor_t *parseType(facility_t *fac, parse_file_t *in, type_descriptor_t *t, sequence_t * unnamed_types, table_t * named_types); -void parseFields(parse_file_t *in, field_t *f, +void parseFields(facility_t *fac, parse_file_t *in, field_t *f, sequence_t * unnamed_types, table_t * named_types, int tag); -- 2.34.1