X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=genevent%2Fgenevent.c;h=d39fd02711ca9e5e17a0fda44e221bf41f4ba04f;hb=25fba83632ff8e52e801b57189379803d70a228b;hp=9c96d81f93fdf2b53a9add70f42187a8913ddc5e;hpb=e8907e117020373fbc1ba5c995ff81d9db4b9261;p=lttv.git diff --git a/genevent/genevent.c b/genevent/genevent.c index 9c96d81f..d39fd027 100644 --- a/genevent/genevent.c +++ b/genevent/genevent.c @@ -49,14 +49,14 @@ This program is distributed in the hope that it will be useful, /* Named types may be referenced from anywhere */ -facility * fac; +facility_t * fac; unsigned alignment = 0; int main(int argc, char** argv) { char *token; - parse_file in; + parse_file_t in; char buffer[BUFFER_SIZE]; int i; @@ -98,7 +98,7 @@ int main(int argc, char** argv) token = getName(&in); if(strcmp("facility",token) == 0) { - fac = memAlloc(sizeof(facility)); + fac = memAlloc(sizeof(facility_t)); fac->name = NULL; fac->description = NULL; sequence_init(&(fac->events)); @@ -139,7 +139,8 @@ int main(int argc, char** argv) *Input Params * name : name of event definition file ****************************************************************************/ -void generateFile(char *name){ +void generateFile(char *name) +{ char *loadName, *hName, *hIdName, *cName, *tmp, *tmp2; FILE * lFp, *hFp, *iFp, *cFp; int nbEvent; @@ -245,7 +246,8 @@ void generateFile(char *name){ *Output Params * nbEvent : number of events in the facility ****************************************************************************/ -void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long checksum) { +void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, + unsigned long checksum) { int pos = 0; fprintf(fp,"#include \n\n"); @@ -258,7 +260,7 @@ void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long che fprintf(fp,"enum %s_event {\n",facName); for(pos = 0; pos < fac->events.position;pos++) { - fprintf(fp,"\tevent_%s", ((event *)(fac->events.array[pos]))->name); + fprintf(fp,"\tevent_%s", ((event_t *)(fac->events.array[pos]))->name); if(pos != fac->events.position-1) fprintf(fp,",\n"); } fprintf(fp,"\n};\n\n\n"); @@ -286,26 +288,22 @@ void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long che static void printStruct(FILE * fp, int len, void ** array, char * name, char * facName, int * whichTypeFirst, int * hasStrSeq, int * structCount, - type_descriptor *type) + type_descriptor_t *type) { int flag = 0; int pos; - field * fld; - type_descriptor * td; + field_t * fld; + type_descriptor_t * td; for (pos = 0; pos < len; pos++) { - fld = (field *)array[pos]; + fld = (field_t *)array[pos]; td = fld->type; if( td->type == STRING || td->type == SEQUENCE || td->type == ARRAY) { (*hasStrSeq)++; - } -// if (*whichTypeFirst == 0) { -// *whichTypeFirst = 1; //struct first -// } + } else { if (flag == 0) { flag = 1; - fprintf(fp,"struct %s_%s",name, facName); if (structCount) { fprintf(fp, "_%d {\n",++*structCount); @@ -315,19 +313,7 @@ printStruct(FILE * fp, int len, void ** array, char * name, char * facName, } fprintf(fp, "\t%s %s; /* %s */\n", getTypeStr(td),fld->name,fld->description ); -#if 0 - } else { - if (*whichTypeFirst == 0) { - //string or sequence or array first - *whichTypeFirst = 2; - } - (*hasStrSeq)++; - if(flag) { - fprintf(fp,"} __attribute__ ((packed));\n\n"); - } - flag = 0; } -#endif //0 } if(flag) { @@ -385,7 +371,7 @@ generateTypeDefs(FILE * fp, char *facName) * fp : file to be written to * fHead : enum type ****************************************************************************/ -void generateEnumDefinition(FILE * fp, type_descriptor * type){ +void generateEnumDefinition(FILE * fp, type_descriptor_t * type){ int pos; if(type->already_printed) return; @@ -412,14 +398,15 @@ void generateEnumDefinition(FILE * fp, type_descriptor * type){ * facName : name of facility ****************************************************************************/ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ - event * ev; - field * fld; - type_descriptor * td; + event_t * ev; + field_t * fld; + type_descriptor_t * td; int pos, pos1; int hasStrSeq, flag, structCount, seqCount,strCount, whichTypeFirst=0; + int args_empty; for(pos = 0; pos < fac->events.position; pos++){ - ev = (event *) fac->events.array[pos]; + ev = (event_t *) fac->events.array[pos]; //yxx if(ev->nested)continue; fprintf(fp,"/**** structure and trace function for event: %s ****/\n\n", ev->name); @@ -436,7 +423,7 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ //twice. if(ev->type != 0) for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; + fld = (field_t *)ev->type->fields.array[pos1]; if(fld->type->type == ENUM) generateEnumDefinition(fp, fld->type); } @@ -457,23 +444,46 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ strCount = 0; fprintf(fp, "#ifndef CONFIG_LTT\n"); fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name); - if(ev->type == 0) - fprintf(fp, "void"); - else + + args_empty = 1; + + /* Does it support per trace tracing ? */ + if(ev->per_trace) { + fprintf(fp, "struct ltt_trace_struct *dest_trace"); + args_empty = 0; + } + + /* Does it support per tracefile tracing ? */ + if(ev->per_tracefile) { + if(!args_empty) fprintf(fp, ", "); + fprintf(fp, "unsigned int tracefile_index"); + args_empty = 0; + } + + if(ev->type != 0) { for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; + fld = (field_t *)ev->type->fields.array[pos1]; td = fld->type; + if(!args_empty) fprintf(fp, ", "); if(td->type == ARRAY ){ fprintf(fp,"%s * %s",getTypeStr(td), fld->name); + args_empty = 0; }else if(td->type == STRING){ fprintf(fp,"short int strlength_%d, %s * %s", ++strCount, getTypeStr(td), fld->name); - }else if(td->type == SEQUENCE){ + args_empty = 0; + }else if(td->type == SEQUENCE){ fprintf(fp,"%s seqlength_%d, %s * %s", uintOutputTypes[td->size], ++seqCount,getTypeStr(td), fld->name); - }else fprintf(fp,"%s %s",getTypeStr(td), fld->name); - if(pos1 != ev->type->fields.position - 1) fprintf(fp,", "); + args_empty = 0; + }else { + fprintf(fp,"%s %s",getTypeStr(td), fld->name); + args_empty = 0; + } } + } + if(args_empty) fprintf(fp, "void"); + fprintf(fp,")\n{\n"); fprintf(fp,"}\n"); fprintf(fp,"#else\n"); @@ -482,26 +492,47 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ seqCount = 0; strCount = 0; fprintf(fp,"static inline void trace_%s_%s(",facName,ev->name); - if(ev->type == 0) - fprintf(fp, "void"); - else + + args_empty = 1; + + /* Does it support per trace tracing ? */ + if(ev->per_trace) { + fprintf(fp, "struct ltt_trace_struct *dest_trace"); + args_empty = 0; + } + + /* Does it support per tracefile tracing ? */ + if(ev->per_tracefile) { + if(!args_empty) fprintf(fp, ", "); + fprintf(fp, "unsigned int tracefile_index"); + args_empty = 0; + } + + if(ev->type != 0) { for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; + fld = (field_t *)ev->type->fields.array[pos1]; td = fld->type; + if(!args_empty) fprintf(fp, ", "); if(td->type == ARRAY ){ fprintf(fp,"%s * %s",getTypeStr(td), fld->name); + args_empty = 0; }else if(td->type == STRING){ fprintf(fp,"short int strlength_%d, %s * %s", ++strCount, getTypeStr(td), fld->name); - }else if(td->type == SEQUENCE){ + args_empty = 0; + }else if(td->type == SEQUENCE){ fprintf(fp,"%s seqlength_%d, %s * %s", uintOutputTypes[td->size], ++seqCount,getTypeStr(td), fld->name); - }else fprintf(fp,"%s %s",getTypeStr(td), fld->name); - if(pos1 != ev->type->fields.position - 1) fprintf(fp,", "); + args_empty = 0; + }else { + fprintf(fp,"%s %s",getTypeStr(td), fld->name); + args_empty = 0; + } } - fprintf(fp,")\n{\n"); - + } + if(args_empty) fprintf(fp, "void"); + fprintf(fp,")\n{\n"); //allocate buffer // MD no more need. fprintf(fp,"\tchar buff[buflength];\n"); @@ -540,16 +571,23 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ fprintf(fp, "\tif(ltt_nesting[smp_processor_id()] > 1) goto unlock;\n"); fprintf(fp, "\tspin_lock(<t_traces.locks[smp_processor_id()]);\n\n"); - fprintf(fp, + if(ev->per_tracefile) { + fprintf(fp, "\tindex = tracefile_index;\n"); + } else { + fprintf(fp, "\tindex = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\ "\t\t\t\tevent_%s);\n", facName, checksum, ev->name); + } fprintf(fp,"\n"); /* For each trace */ fprintf(fp, "\tlist_for_each_entry(trace, <t_traces.head, list) {\n"); fprintf(fp, "\t\tif(!trace->active) continue;\n\n"); + if(ev->per_trace) { + fprintf(fp, "\t\tif(dest_trace != trace) continue;\n\n"); + } //length of buffer : length of all structures // if(ev->type == 0) fprintf(fp, "0"); @@ -593,7 +631,7 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ flag = 0; if(ev->type != 0) for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; + fld = (field_t *)ev->type->fields.array[pos1]; td = fld->type; if(td->type == SEQUENCE || td->type==STRING || td->type==ARRAY){ if(td->type == SEQUENCE) { @@ -673,84 +711,17 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ fprintf(fp, "\n"); if(ev->type != 0) - fprintf(fp, "\t\tchar *ptr = (char*)buff + _offset + header_length;\n"); - - - //declare a char pointer if needed : starts at the end of the structs. - //if(structCount + hasStrSeq > 1) { - // fprintf(fp,"\t\tchar * ptr = (char*)buff + header_length"); - // for(pos1=0;pos1name, facName,pos1+1); - // } - // if(structCount + hasStrSeq > 1) fprintf(fp,";\n"); - //} - - // Declare an alias pointer of the struct type to the beginning - // of the reserved area, just after the event header. - if(ev->type != 0) { - unsigned align = max(alignment, td->alignment); - if(align > 1) { - fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", - align, align, align); - } - - fprintf(fp, "\t\t__1 = (struct %s_%s_1 *)(ptr);\n", - ev->name, facName); - } - //allocate memory for new struct and initialize it - //if(whichTypeFirst == 1){ //struct first - //for(pos1=0;pos1name, facName,ev->name, facName); - //MD disabled else fprintf(fp, - // "\tstruct %s_%s_%d __%d;\n", - // ev->name, facName,pos1+1,pos1+1); - //} - //}else if(whichTypeFirst == 2){ - // for(pos1=0;pos1name, facName,pos1+1,pos1+1); - //} - fprintf(fp,"\n"); - - if(structCount) fprintf(fp,"\t\t//initialize structs\n"); - //flag = 0; - //structCount = 0; - if(ev->type != 0) - for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; - td = fld->type; - if(td->type != ARRAY && td->type != SEQUENCE && td->type != STRING){ - //if(flag == 0){ - // flag = 1; - // structCount++; - // if(structCount > 1) fprintf(fp,"\n"); - //} - fprintf(fp, "\t\t__1->%s = %s;\n", fld->name, fld->name ); - - //if(structCount == 1 && whichTypeFirst == 1) - // fprintf(fp, "\t__1->%s = %s;\n",fld->name,fld->name ); - //else - // fprintf(fp, "\t__%d.%s = %s;\n",structCount ,fld->name,fld->name); - } - //else flag = 0; - } - if(structCount) fprintf(fp,"\n"); - //set ptr to the end of first struct if needed; - //if(structCount + hasStrSeq > 1){ - // fprintf(fp,"\n\t\t//set ptr to the end of the first struct\n"); - // fprintf(fp,"\t\tptr += sizeof(struct %s_%s_1);\n\n",ev->name, facName); - //} + fprintf(fp, "\t\tptr = (char*)buff + _offset + header_length;\n"); //copy struct, sequence and string to buffer + //FIXME : they always come before the structs. seqCount = 0; strCount = 0; flag = 0; structCount = 0; if(ev->type != 0) for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ - fld = (field *)ev->type->fields.array[pos1]; + fld = (field_t *)ev->type->fields.array[pos1]; td = fld->type; // if(td->type != STRING && td->type != SEQUENCE && td->type != ARRAY){ // if(flag == 0) structCount++; @@ -816,6 +787,76 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ } if(structCount + seqCount > 1) fprintf(fp,"\n"); + + + + //declare a char pointer if needed : starts at the end of the structs. + //if(structCount + hasStrSeq > 1) { + // fprintf(fp,"\t\tchar * ptr = (char*)buff + header_length"); + // for(pos1=0;pos1name, facName,pos1+1); + // } + // if(structCount + hasStrSeq > 1) fprintf(fp,";\n"); + //} + + // Declare an alias pointer of the struct type to the beginning + // of the reserved area, just after the event header. + if(ev->type != 0) { + unsigned align = max(alignment, td->alignment); + if(align > 1) { + fprintf(fp,"\t\tptr+=(%u - ((unsigned int)ptr&(%u-1)))&(%u-1);\n", + align, align, align); + } + + fprintf(fp, "\t\t__1 = (struct %s_%s_1 *)(ptr);\n", + ev->name, facName); + } + //allocate memory for new struct and initialize it + //if(whichTypeFirst == 1){ //struct first + //for(pos1=0;pos1name, facName,ev->name, facName); + //MD disabled else fprintf(fp, + // "\tstruct %s_%s_%d __%d;\n", + // ev->name, facName,pos1+1,pos1+1); + //} + //}else if(whichTypeFirst == 2){ + // for(pos1=0;pos1name, facName,pos1+1,pos1+1); + //} + fprintf(fp,"\n"); + + if(structCount) fprintf(fp,"\t\t//initialize structs\n"); + //flag = 0; + //structCount = 0; + if(ev->type != 0) + for(pos1 = 0; pos1 < ev->type->fields.position; pos1++){ + fld = (field_t *)ev->type->fields.array[pos1]; + td = fld->type; + if(td->type != ARRAY && td->type != SEQUENCE && td->type != STRING){ + //if(flag == 0){ + // flag = 1; + // structCount++; + // if(structCount > 1) fprintf(fp,"\n"); + //} + fprintf(fp, "\t\t__1->%s = %s;\n", fld->name, fld->name ); + + //if(structCount == 1 && whichTypeFirst == 1) + // fprintf(fp, "\t__1->%s = %s;\n",fld->name,fld->name ); + //else + // fprintf(fp, "\t__%d.%s = %s;\n",structCount ,fld->name,fld->name); + } + //else flag = 0; + } + if(structCount) fprintf(fp,"\n"); + //set ptr to the end of first struct if needed; + //if(structCount + hasStrSeq > 1){ + // fprintf(fp,"\n\t\t//set ptr to the end of the first struct\n"); + // fprintf(fp,"\t\tptr += sizeof(struct %s_%s_1);\n\n",ev->name, facName); + //} + fprintf(fp,"\n"); fprintf(fp, "\t\t/* Commit the work */\n"); fprintf(fp, "\t\trelay_commit(channel->rchan->buf[smp_processor_id()],\n" @@ -857,8 +898,8 @@ void generateStructFunc(FILE * fp, char * facName, unsigned long checksum){ *Return Values * char * : type string ****************************************************************************/ -char * getTypeStr(type_descriptor * td){ - type_descriptor * t ; +char * getTypeStr(type_descriptor_t * td){ + type_descriptor_t * t ; switch(td->type){ case INT: