summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/ChangeLog8
-rw-r--r--runtime/lket/b2a/lket_b2a.c217
-rw-r--r--runtime/lket/b2a/lket_b2a.h9
-rw-r--r--tapset/LKET/Changelog8
-rwxr-xr-xtapset/LKET/lket_trace.stp6
-rwxr-xr-xtapset/LKET/process.stp6
-rwxr-xr-xtapset/LKET/register_event.stp6
7 files changed, 157 insertions, 103 deletions
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 <guanglei@cn.ibm.com>
+
+ * 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 <joshua.i.stone@intel.com>
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 <string.h>
#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;
@@ -259,18 +298,11 @@ void destroyAppName(gpointer 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; i<total_infiles; i++) {
- if(skip_sequence_id(infps[i]))
- continue;
if(fread(&magic, 1, sizeof(magic), infps[i]) < sizeof(magic))
continue;
if(magic == (int32_t)LKET_MAGIC) {
@@ -334,8 +364,6 @@ void find_init_header(FILE **infps, const int total_infiles, FILE *outfp)
for(k = 0; k < MAX_CPUS; k++)
cpufreq[k].timebase = init_timebase;
}
- // skip the null terminater
- fseek(infps[i], 1LL, SEEK_CUR);
break;
}
}
@@ -347,11 +375,9 @@ void find_init_header(FILE **infps, const int total_infiles, FILE *outfp)
/*
* read the lket_pkt_header structure at the begining of the input file
*/
+///FIXME: MySQL
int get_pkt_header(FILE *fp, lket_pkt_header *phdr)
{
- if(skip_sequence_id(fp))
- goto bad;
-
if(fread(phdr, 1, sizeof(lket_pkt_header), fp) < sizeof(lket_pkt_header))
goto bad;
@@ -396,6 +422,7 @@ void print_pkt_header(FILE *fp, lket_pkt_header *phdr)
HDR_HookID(phdr));
}
+///FIXME: MySQL
void register_events(int evt_type, FILE *infp, size_t size)
{
int cnt=0, len=0;
@@ -455,75 +482,87 @@ char *get_fmtstr(char *fmt)
return "";
}
-int ascii_print(lket_pkt_header header, FILE *infp, FILE *outfile, int evt_type)
+///FIXME: MySQL
+int dump_data(lket_pkt_header header, FILE *infp)
{
- int i, c;
+ int i, c, j;
int16_t stemp;
int32_t ntemp;
long long lltemp;
- int readbytes = 0;
+ int readbytes = 0;
+ int total_bytes = 0;
int size;
+ int evt_num = 1;
char *fmt, *name, *buffer;
int grpid = HDR_GroupID(&header);
int hookid = HDR_HookID(&header);
+ print_pkt_header(outfp, &header);
+
+ /* if the data contains user appended extra data */
+ if(header.total_size != header.sys_size)
+ evt_num = 2;
+
+ /* iterate the sys and user event */
+ for(j=1; j<= evt_num; j++) {
+
+ readbytes = 0;
+
+ if(j == 1) /* if current one is a sys event */
+ size = header.sys_size;
+ if(j == 2) /* if current one is a user event */
+ size = header.total_size - header.sys_size;
+
+ if((events_des[j][grpid][hookid] == NULL) ||
+ (events_des[j][grpid][hookid]->count <= 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; i<events_des[evt_type][grpid][hookid]->count; 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; i<events_des[j][grpid][hookid]->count; 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
@@ -158,14 +158,9 @@ typedef struct {
} 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
diff --git a/tapset/LKET/Changelog b/tapset/LKET/Changelog
index 99e8d3ab..7bdae3fa 100644
--- a/tapset/LKET/Changelog
+++ b/tapset/LKET/Changelog
@@ -2,6 +2,14 @@
From Gui Jian <guijian@cn.ibm.com>
+ * lket_trace.stp,process.stp,register_event.stp: Be
+ sync with the runtime printing changes made by Martin
+
+
+2006-09-19 Li Guanglei <guanglei@cn.ibm.com>
+
+ From Gui Jian <guijian@cn.ibm.com>
+
* rpc.stp: New trace hooks for RPC activities on client,
server and scheduler.
* register_event.stp: Add the register_sys_event() calls
diff --git a/tapset/LKET/lket_trace.stp b/tapset/LKET/lket_trace.stp
index 5764892a..57c4c96d 100755
--- a/tapset/LKET/lket_trace.stp
+++ b/tapset/LKET/lket_trace.stp
@@ -183,9 +183,9 @@ static inline int this_event_len(void)
function update_record()
%{
#if !defined(ASCII_TRACE)
- int cpu = smp_processor_id();
- char *total_length = &_stp_pbuf[cpu][STP_PRINT_BUF_START];
- *(int16_t *)total_length = _stp_pbuf_len[cpu] - 4;
+ _stp_pbuf *pb = &__get_cpu_var(Stp_pbuf);
+ char *total_length = &pb->buf[0];
+ *(int16_t *)total_length = pb->len - 4;
#endif
%}
diff --git a/tapset/LKET/process.stp b/tapset/LKET/process.stp
index 238f1b20..84a2bd80 100755
--- a/tapset/LKET/process.stp
+++ b/tapset/LKET/process.stp
@@ -36,6 +36,7 @@ function process_snapshot()
%{
struct task_struct *tsk;
struct list_head *cur, *head;
+ _stp_pbuf *pb;
int cpu = smp_processor_id();
char *total_length;
head = &(current->tasks);
@@ -47,8 +48,9 @@ function process_snapshot()
_lket_trace(_GROUP_PROCESS, _HOOKID_PROCESS_SNAPSHOT, "%4b%4b%4b%0s",
(_FMT_)tsk->pid, (_FMT_)tsk->tgid, (_FMT_)tsk->parent->tgid, tsk->comm);
#if !defined(ASCII_TRACE)
- total_length = &_stp_pbuf[cpu][STP_PRINT_BUF_START];
- *(int16_t *)total_length = _stp_pbuf_len[cpu] - 4;
+ pb = &__get_cpu_var(Stp_pbuf);
+ total_length = &pb->buf[0];
+ *(int16_t *)total_length = pb->len - 4;
#endif
_stp_print_flush();
}
diff --git a/tapset/LKET/register_event.stp b/tapset/LKET/register_event.stp
index 8579e9c3..ac05b71a 100755
--- a/tapset/LKET/register_event.stp
+++ b/tapset/LKET/register_event.stp
@@ -70,6 +70,7 @@ function register_event(grpid:long, hookid:long, evt_type:long, fmt:string, name
char in_fmt[512], in_name[512];
char *p_in_fmt, *p_in_name;
char *fmt, *name;
+ _stp_pbuf * pb;
int cpu = smp_processor_id();
char *total_length;
p_in_fmt = in_fmt;
@@ -112,8 +113,9 @@ function register_event(grpid:long, hookid:long, evt_type:long, fmt:string, name
THIS->hookid, THIS->fmt, THIS->names);
#if !defined(ASCII_TRACE)
- total_length = &_stp_pbuf[cpu][STP_PRINT_BUF_START];
- *(int16_t *)total_length = _stp_pbuf_len[cpu] - 4;
+ pb = &__get_cpu_var(Stp_pbuf);
+ total_length = &pb->buf[0];
+ *(int16_t *)total_length = pb->len - 4;
#endif
_stp_print_flush();