From b96baad9f8f5bf04c3d136ed16fe59270ae947e9 Mon Sep 17 00:00:00 2001 From: guanglei Date: Tue, 19 Sep 2006 08:01:26 +0000 Subject: lket_trace.stp,process.stp,register_event.stp: Be sync with the runtime printing changes made by Martin lket/b2a/lket_b2a.c, lket/b2a/lket_b2a.h: Be sync with the recent runtime printing changes made by Martin. Some clean up work before adding the support of dumping data into MySQL Bug fix of segment fault when an event is not registered. --- runtime/ChangeLog | 8 ++ runtime/lket/b2a/lket_b2a.c | 217 ++++++++++++++++++++++++++------------------ runtime/lket/b2a/lket_b2a.h | 9 +- 3 files changed, 138 insertions(+), 96 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 3738f58d..ff7671af 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,11 @@ +2006-09-19 Li Guanglei + + * lket/b2a/lket_b2a.c, lket/b2a/lket_b2a.h: + Be sync with the recent runtime printing changes made by Martin. + Some clean up work before adding the support of dumping data + into MySQL + Bug fix of segment fault when an event is not registered. + 2006-09-18 Josh Stone PR 3220 diff --git a/runtime/lket/b2a/lket_b2a.c b/runtime/lket/b2a/lket_b2a.c index b6bbc481..0df76207 100644 --- a/runtime/lket/b2a/lket_b2a.c +++ b/runtime/lket/b2a/lket_b2a.c @@ -18,6 +18,13 @@ #include #include "lket_b2a.h" +/* A flag indicate whether to store the trace + data into local file/MySQL database */ +int into_file, into_db; +/* A FILE handle points to a local file used to + store the trace data */ +FILE *outfp; + #define TIMING_GETCYCLES 0x01 #define TIMING_GETTIMEOFDAY 0x02 #define TIMING_SCHEDCLOCK 0x03 @@ -45,19 +52,51 @@ GTree *appNameTree; */ event_desc *events_des[MAX_EVT_TYPES][MAX_GRPID][MAX_HOOKID]; +void usage() +{ +printf("Usage:\n\ + lket-b2a Options INFILE1 [INFILE2...]\n\ + Options:\n\ + -f dump the trace data into a local file named \"lket.out\"\n\ + -m dump the trace data into MySQL\n"); +} + int main(int argc, char *argv[]) { lket_pkt_header *hdrs = NULL; FILE **infps = NULL; - FILE *outfp = NULL; char outfilename[MAX_STRINGLEN]={0}; int i, j, total_infiles = 0; long long min; + into_file = 1; into_db = 0; + if(argc < 2) { printf("Usage: %s inputfile1 [inputfile2...]\n", argv[0]); return 1; } +/* + while (1) { + int c = getopt(argc, argv, "mf"); + if (c < 0) // no more options + break; + switch (c) { + case 'm': + into_file = 0; + into_db = 1; + break; + case 'f': + into_file = 1; + into_db = 0; + default: + printf("Error in options\n"); + usage(); + exit(-1); + break; + } + } +*/ + total_infiles = argc - 1; // open the input files and the output file @@ -75,23 +114,22 @@ int main(int argc, char *argv[]) goto failed; } } -#if !defined(DEBUG_OUTPUT) - if(strnlen(outfilename, MAX_STRINGLEN) == 0) - strncpy(outfilename, DEFAULT_OUTFILE_NAME, MAX_STRINGLEN); - outfp = fopen(outfilename, "w"); - if(outfp == NULL) { - printf("Unable to create %s\n", outfilename); - goto failed; + + if(into_file) { + if(strnlen(outfilename, MAX_STRINGLEN) == 0) + strncpy(outfilename, DEFAULT_OUTFILE_NAME, MAX_STRINGLEN); + outfp = fopen(outfilename, "w"); + if(outfp == NULL) { + printf("Unable to create %s\n", outfilename); + goto failed; + } } -#else - outfp = stdout; -#endif /* create the search tree */ appNameTree = g_tree_new_full(compareFunc, NULL, NULL, destroyAppName); // find the lket header - find_init_header(infps, total_infiles, outfp); + find_init_header(infps, total_infiles); // allocate packet headers array hdrs = malloc(total_infiles * sizeof(lket_pkt_header)); @@ -130,7 +168,6 @@ int main(int argc, char *argv[]) register_events(HDR_HookID(&hdrs[j]), infps[j], hdrs[j].sys_size); } else { - print_pkt_header(outfp, &hdrs[j]); if(HDR_GroupID(&hdrs[j])==_GROUP_PROCESS && (HDR_HookID(&hdrs[j])==_HOOKID_PROCESS_SNAPSHOT @@ -146,7 +183,8 @@ int main(int argc, char *argv[]) int64_t new_timebase; fread(&new_timebase, sizeof(new_timebase), 1, infps[j]); - cpufreq[HDR_CpuID(&hdrs[j])].last_time += (hdrs[j].microsecond + cpufreq[HDR_CpuID(&hdrs[j])].last_time += + (hdrs[j].microsecond - cpufreq[HDR_CpuID(&hdrs[j])].last_cycles) / cpufreq[HDR_CpuID(&hdrs[j])].timebase; cpufreq[j].last_cycles = hdrs[j].microsecond; @@ -155,12 +193,12 @@ int main(int argc, char *argv[]) fseek(infps[j], SEEK_CUR, -sizeof(new_timebase)); } - ascii_print(hdrs[j], infps[j], outfp, EVT_SYS); - if(hdrs[j].total_size != hdrs[j].sys_size) - ascii_print(hdrs[j], infps[j], outfp, EVT_USER); + dump_data(hdrs[j], infps[j]); } - fgetc_unlocked(infps[j]); // update hdr[j] +#ifdef DEBUG_OUTPUT + fprintf(outfp, "File %d, Offset: %ld\n", j, ftell(infps[j])); +#endif get_pkt_header(infps[j], &hdrs[j]); } // recalculate the smallest timestamp @@ -197,6 +235,7 @@ failed: /* register newly found process name for addevent.process.snapshot and addevent.process.execve */ +///FIXME: MySQL?? void register_appname(int i, FILE *fp, lket_pkt_header *phdr) { int pid; @@ -258,19 +297,12 @@ void destroyAppName(gpointer data) free(data); } -/* - * handle the bothering sequence id generated by systemtap - */ -int skip_sequence_id(FILE *fp) -{ - return (fseek(fp, (off_t)SEQID_SIZE, SEEK_CUR) == -1); -} - /* * search the LKET init header in a set of input files, * and the header structure is defined in tapsets/lket_trace.stp */ -void find_init_header(FILE **infps, const int total_infiles, FILE *outfp) +//FIXME: need MySQL support +void find_init_header(FILE **infps, const int total_infiles) { int i, j, k; int32_t magic; @@ -288,8 +320,6 @@ void find_init_header(FILE **infps, const int total_infiles, FILE *outfp) return; j = total_infiles; for(i=0; icount <= 0 || !outfp) || + (events_des[j][grpid][hookid]->evt_fmt[0][0] == '\0')) { + //no format is provided, dump in hex + buffer = malloc(size); + fread(buffer, size, 1, infp); + fwrite(buffer, size, 1, outfp); + total_bytes += size; + continue; + } - if(evt_type == EVT_SYS) - size = header.sys_size; - else - size = header.total_size - header.sys_size; - - if(events_des[evt_type][grpid][hookid] == NULL) - return -1; - - if(events_des[evt_type][grpid][hookid]->count <= 0 || !outfile) - return -1; - - if(events_des[evt_type][grpid][hookid]->evt_fmt[0][0] == '\0') { - //no format is provided, dump in hex - buffer = malloc(size); - fread(buffer, size, 1, infp); - fwrite(buffer, size, 1, outfile); - return -1; - } - - for(i=0; icount; i++) { - fmt = events_des[evt_type][grpid][hookid]->evt_fmt[i]; - name = events_des[evt_type][grpid][hookid]->evt_names[i]; - fwrite(name, strlen(name), 1, outfile); - fwrite(":", 1, 1, outfile); - if(strncmp(fmt, "INT8", 4)==0) { - c = fgetc_unlocked(infp); - fprintf(outfile, "%d,", (int8_t)c); - readbytes+=1; - } else if(strncmp(fmt, "INT16", 5)==0) { - fread(&stemp, 2, 1, infp); - fprintf(outfile, "%d,", (int16_t)stemp); - readbytes+=2; - } else if(strncmp(fmt, "INT32", 5)==0) { - fread(&ntemp, 4, 1, infp); - fprintf(outfile, "%d,", (int32_t)ntemp); - readbytes+=4; - } else if(strncmp(fmt, "INT64", 5)==0) { - fread(&lltemp, 8, 1, infp); - fprintf(outfile, "%lld,",lltemp); - readbytes+=8; - } else if(strncmp(fmt, "STRING", 6)==0) { - c = fgetc_unlocked(infp); - ++readbytes; - while (c && readbytes < size) { - fputc_unlocked(c, outfile); + for(i=0; icount; i++) { + fmt = events_des[j][grpid][hookid]->evt_fmt[i]; + name = events_des[j][grpid][hookid]->evt_names[i]; + fwrite(name, strlen(name), 1, outfp); + fwrite(":", 1, 1, outfp); + if(strncmp(fmt, "INT8", 4)==0) { + c = fgetc_unlocked(infp); + fprintf(outfp, "%d,", (int8_t)c); + readbytes+=1; + } else if(strncmp(fmt, "INT16", 5)==0) { + fread(&stemp, 2, 1, infp); + fprintf(outfp, "%d,", (int16_t)stemp); + readbytes+=2; + } else if(strncmp(fmt, "INT32", 5)==0) { + fread(&ntemp, 4, 1, infp); + fprintf(outfp, "%d,", (int32_t)ntemp); + readbytes+=4; + } else if(strncmp(fmt, "INT64", 5)==0) { + fread(&lltemp, 8, 1, infp); + fprintf(outfp, "%lld,",lltemp); + readbytes+=8; + } else if(strncmp(fmt, "STRING", 6)==0) { c = fgetc_unlocked(infp); ++readbytes; + while (c && readbytes < size) { + fputc_unlocked(c, outfp); + c = fgetc_unlocked(infp); + ++readbytes; + } + if(!c) { + fputc_unlocked(',', outfp); + continue; + } + else + return -1; } - if(!c) { - fputc_unlocked(',', outfile); - continue; - } - else - return -1; } + total_bytes += readbytes; } - return readbytes; + return total_bytes; } diff --git a/runtime/lket/b2a/lket_b2a.h b/runtime/lket/b2a/lket_b2a.h index 10d26dff..abb9eb53 100644 --- a/runtime/lket/b2a/lket_b2a.h +++ b/runtime/lket/b2a/lket_b2a.h @@ -157,15 +157,10 @@ typedef struct { int count; } event_desc; -/* - * handle the bothering sequence id generated by systemtap - */ -static int skip_sequence_id(FILE *fp); - /* * search the lket_init_header structure in a set of input files */ -static void find_init_header(FILE **fp, const int total_infiles, FILE *outfp); +static void find_init_header(FILE **fp, const int total_infiles); /* * read the lket_pkt_header structure at the begining of the input file @@ -182,6 +177,6 @@ gint compareFunc(gconstpointer a, gconstpointer b, gpointer user_data); void destroyAppName(gpointer data); void register_events(int evt_type, FILE *infp, size_t size); -int ascii_print(lket_pkt_header header, FILE *infp, FILE *outfile, int evt_type); +int dump_data(lket_pkt_header header, FILE *infp); char *get_fmtstr(char *fmt); #endif -- cgit