Changeset: ed361d6584e4 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ed361d6584e4
Modified Files:
        clients/mapiclient/tomograph.c
Branch: Feb2013
Log Message:

Recognize wait events and cleanup trace file
The trace file has become more readable


diffs (220 lines):

diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -265,6 +265,12 @@ stop_disconnect:
 #define MAXTHREADS 2048
 #define MAXBOX 32678
 
+#define START 0
+#define DONE 1
+#define ACTION 2
+#define PING 4
+#define WAIT 5
+
 typedef struct BOX {
        int row;
        int color;
@@ -593,7 +599,7 @@ static void dumpboxes(void)
 
        for (i = 0; i < topbox; i++)
                if (box[i].clkend && box[i].fcn) {
-                       if (box[i].state != 4) {
+                       if (box[i].state < PING) {
                                //io counters are zero at start of instruction !
                                //fprintf(f,"%ld %3.2f 0 0 \n", 
box[i].clkstart, (box[i].memstart/1024.0));
                                fprintf(f, "%ld %3.2f 0 0\n", box[i].clkend, 
(box[i].memend / 1024.0));
@@ -695,7 +701,7 @@ static void showio(void)
        long max = 0;
 
        for (i = 0; i < topbox; i++)
-               if (box[i].clkend && box[i].state == 4) {
+               if (box[i].clkend && box[i].state >= PING) {
                        if (box[i].reads > max)
                                max = box[i].reads;
                        if (box[i].writes > max)
@@ -844,11 +850,11 @@ static void keepdata(char *filename)
                        //if ( debug)
                        //fprintf(stderr,"%3d\t%8ld\t%5ld\t%s\n", 
box[i].thread, box[i].clkstart, box[i].clkend-box[i].clkstart, box[i].fcn);
 
-                       fprintf(f, "%d\t%ld\t%ld\n", box[i].thread, 
box[i].clkstart, box[i].clkend);
-                       fprintf(f, "%ld\t%ld\t%ld\n", box[i].ticks, 
box[i].memstart, box[i].memend);
-                       fprintf(f, "%d\t%ld\t%ld\n", box[i].state, 
box[i].reads, box[i].writes);
+                       fprintf(f, "%d\t%ld\t%ld\t", box[i].thread, 
box[i].clkstart, box[i].clkend);
+                       fprintf(f, "%ld\t%ld\t%ld\t", box[i].ticks, 
box[i].memstart, box[i].memend);
+                       fprintf(f, "%d\t%ld\t%ld\t", box[i].state, 
box[i].reads, box[i].writes);
+                       fprintf(f, "%s\t", box[i].fcn);
                        fprintf(f, "%s\n", box[i].stmt ? box[i].stmt : 
box[i].fcn);
-                       fprintf(f, "%s\n", box[i].fcn);
                }
 
        (void) fclose(f);
@@ -857,8 +863,8 @@ static void keepdata(char *filename)
 static void scandata(char *filename)
 {
        FILE *f;
-       char buf[BUFSIZ];
-       int i = 0;
+       char line[2*BUFSIZ], buf[BUFSIZ], buf2[BUFSIZ];
+       int cnt, i = 0;
 
        f = fopen(filename, "r");
        if (f == 0) {
@@ -872,20 +878,20 @@ static void scandata(char *filename)
        starttime = 0;
 
        while (!feof(f)) {
-               if (fscanf(f, "%d\t%ld\t%ld\n", &box[i].thread, 
&box[i].clkstart, &box[i].clkend) != 3 ||
-                       fscanf(f, "%ld\t%ld\t%ld\n", &box[i].ticks, 
&box[i].memstart, &box[i].memend) != 3 ||
-                       fscanf(f, "%d\t%ld\t%ld\n", &box[i].state, 
&box[i].reads, &box[i].writes) != 3 ||
-                       fgets(buf, BUFSIZ, f) == NULL ||
-                       (box[i].stmt = strdup(buf)) == NULL ||
-                       fgets(buf, BUFSIZ, f) == NULL) {
-                       fprintf(stderr, "scandata error '%s'\n", buf);
+               if ( fgets(line,2 * BUFSIZ,f) == NULL) {
+                       fprintf(stderr, "scandata read error\n");
+               }
+               if ( (cnt =sscanf(line, 
"%d\t%ld\t%ld\t%ld\t%ld\t%ld\t%d\t%ld\t%ld\t%s\t%s\n", 
+                                       &box[i].thread, &box[i].clkstart, 
&box[i].clkend,
+                                       &box[i].ticks, &box[i].memstart, 
&box[i].memend,
+                                       &box[i].state, &box[i].reads, 
&box[i].writes, buf, buf2)) != 11){
+                       fprintf(stderr, "scandata error %d\n",cnt);
                        dumpbox(i);
                        topbox = i;
                        return;
                }
-               if (strchr(buf, (int) '\n'))
-                       *(strchr(buf, (int) '\n')) = 0;
-               box[i].fcn = strdup(buf);
+               box[i].stmt = strdup(buf);
+               box[i].fcn = strdup(buf2);
                /* focus on part of the time frame */
                if (endrange) {
                        if (box[i].clkend < startrange || box[i].clkstart 
>endrange)
@@ -965,7 +971,7 @@ static void createTomogram(void)
 
        /* detect all different threads and assign them a row */
        for (i = 0; i < topbox; i++)
-               if (box[i].clkend && box[i].state != 4) {
+               if (box[i].clkend && box[i].state < PING) {
                        for (j = 0; j < top; j++)
                                if (rows[j] == box[i].thread)
                                        break;
@@ -1023,13 +1029,21 @@ static void createTomogram(void)
 
        /* fill the duration of each instruction encountered that fit our range 
constraint */
        for (i = 0; i < topbox; i++)
-               if (box[i].clkend && box[i].state != 4) {
+               switch (box[i].clkend && box[i].state ) {
+               default:
                        if (debug)
                                dumpbox(i);
                        fprintf(gnudata, "set object %d rectangle from %ld, %d 
to %ld, %d fillcolor rgb \"%s\" fillstyle solid 0.6\n",
                                        object++, box[i].clkstart, box[i].row * 
2 * h, box[i].clkend, box[i].row * 2 * h + h, colors[box[i].color].col);
+                       break;
+               case PING:
+                       break;
+               case WAIT:
+                       fprintf(gnudata, "set object %d rectangle from %ld, %d 
to %ld, %d fillcolor rgb \"%s\" fillstyle solid 0.6\n",
+                                       object++, box[i].clkstart, box[i].row * 
2 * h+h, box[i].clkend, box[i].row * 2 * h + h +h/5, colors[box[i].color].col);
                }
 
+
        fprintf(gnudata, "plot 0 notitle with lines\n");
        fprintf(gnudata, "unset for[i=%d:%d] object i\n", prevobject, object - 
1);
        prevobject = object - 1;
@@ -1065,13 +1079,13 @@ static void update(int state, int thread
                return;
        if (starttime == 0) {
                /* ignore all instructions up to the first function call */
-               if (state == 4 || fcn == 0 || strncmp(fcn, "function", 8) != 0)
+               if (state >= PING || fcn == 0 || strncmp(fcn, "function", 8) != 
0)
                        return;
                starttime = clkticks;
                return;
        }
 
-       if (state == 1 && fcn && (strncmp(fcn, "function", 8) == 0 || 
strncmp(fcn, "profiler.tomograph", 18) == 0)) {
+       if (state == DONE && fcn && (strncmp(fcn, "function", 8) == 0 || 
strncmp(fcn, "profiler.tomograph", 18) == 0)) {
                if (debug)
                        fprintf(stderr, "Batch %d\n", batch);
                if (strncmp(fcn, "function", 8) == 0 && batch-- > 1)
@@ -1089,10 +1103,10 @@ static void update(int state, int thread
        clkticks -= starttime;
 
        /* handle a ping event, keep the current instruction in focus */
-       if (state == 4) {
+       if (state >= PING) {
                idx = threads[thread];
                b = box[idx];
-               box[idx].state = 4;
+               box[idx].state = state;
                box[idx].thread = thread;
                lastclk[thread] = clkticks;
                box[idx].clkend = box[idx].clkstart = clkticks;
@@ -1103,7 +1117,7 @@ static void update(int state, int thread
                if (s)
                        *s = 0;
                box[idx].stmt = stmt;
-               box[idx].fcn = fcn ? strdup(fcn) : "";
+               box[idx].fcn = state == PING? "profiler.ping":"profiler.wait";
                threads[thread] = ++topbox;
                idx = threads[thread];
                box[idx] = b;
@@ -1115,7 +1129,7 @@ static void update(int state, int thread
        }
        idx = threads[thread];
        /* start of instruction box */
-       if (state == 0 && thread < MAXTHREADS) {
+       if (state == START && thread < MAXTHREADS) {
                box[idx].state = state;
                box[idx].thread = thread;
                box[idx].clkstart = clkticks;
@@ -1124,12 +1138,12 @@ static void update(int state, int thread
                box[idx].fcn = fcn ? strdup(fcn) : "";
        }
        /* end the instruction box */
-       if (state == 1 && thread < MAXTHREADS && fcn && box[idx].fcn && 
strcmp(fcn, box[idx].fcn) == 0) {
+       if (state == DONE && thread < MAXTHREADS && fcn && box[idx].fcn && 
strcmp(fcn, box[idx].fcn) == 0) {
                lastclk[thread] = clkticks;
                box[idx].clkend = clkticks;
                box[idx].memend = memory;
                box[idx].ticks = ticks;
-               box[idx].state = state;
+               box[idx].state = ACTION;
                box[idx].reads = reads;
                box[idx].writes = writes;
                /* focus on part of the time frame */
@@ -1173,13 +1187,16 @@ static int parser(char *row)
        if (c == 0)
                return -2;
        if (strncmp(c + 1, "start", 5) == 0) {
-               state = 0;
+               state = START;
                c += 6;
        } else if (strncmp(c + 1, "done", 4) == 0) {
-               state = 1;
+               state = DONE;
                c += 5;
        } else if (strncmp(c + 1, "ping", 4) == 0) {
-               state = 4;
+               state = PING;
+               c += 5;
+       } else if (strncmp(c + 1, "wait", 4) == 0) {
+               state = WAIT;
                c += 5;
        } else {
                state = 0;
@@ -1218,10 +1235,10 @@ static int parser(char *row)
                return -6;
        memory = atol(c + 1);
        c = strchr(c + 1, (int) ',');
-       if (debug && state != 4)
+       if (debug && state < PING)
                fprintf(stderr, "%s\n", row);
-       if (c == 0)
-               return state == 4 ? 0 : -7;
+       if (c == 0) 
+               return state >= PING ? 0 : -7;
        reads = atol(c + 1);
        c = strchr(c + 1, (int) ',');
        if (c == 0)
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to