Changeset: f908663c92fb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f908663c92fb
Modified Files:
        clients/mapiclient/Tests/tomograph--help.stable.err
        clients/mapiclient/eventparser.c
        clients/mapiclient/eventparser.h
        clients/mapiclient/tachograph.c
        clients/mapiclient/tomograph.c
Branch: default
Log Message:

Fix parsing, rendering, and caching
Tachograph and tomograph should be kept aligned wrt file management.
Some quote parsing juggling.


diffs (truncated from 558 to 300 lines):

diff --git a/clients/mapiclient/Tests/tomograph--help.stable.err 
b/clients/mapiclient/Tests/tomograph--help.stable.err
--- a/clients/mapiclient/Tests/tomograph--help.stable.err
+++ b/clients/mapiclient/Tests/tomograph--help.stable.err
@@ -20,6 +20,7 @@ tomograph [options]
   -r | --range=<starttime>-<endtime>[ms,s] 
   -i | --input=<profiler event file > 
   -o | --output=<file prefix > (default 'tomograph'
+  -c | --cache=<query pool location>
   -s | --system=# (on= 1(default) off=0
   -b | --beat=<delay> in milliseconds (default 5000)
   -A | --atlas=<number> maximum number of queries (default 1)
diff --git a/clients/mapiclient/eventparser.c b/clients/mapiclient/eventparser.c
--- a/clients/mapiclient/eventparser.c
+++ b/clients/mapiclient/eventparser.c
@@ -44,6 +44,29 @@ clearArguments(void)
        malvartop = 0;
 }
 
+char * 
+stripQuotes(char *currentquery)
+{      char *q, *c, *qry;
+                       q = qry = (char *) malloc(strlen(currentquery) * 2);
+                       for (c= currentquery; *c; ){
+                               if ( strncmp(c,"\\\\t",3) == 0){
+                                       *q++ = '\t';
+                                       c+=3;
+                               } else
+                               if ( strncmp(c,"\\\\n",3) == 0){
+                                       *q++ = '\n';
+                                       c+=3;
+                               } else if ( strncmp(c,"\\\"",2) == 0){
+                                       *q++= '"';
+                                       c+=2;
+                               } else if ( strncmp(c,"\\\\",2) == 0){
+                                       c+= 2;
+                               } else *q++ = *c++;
+                       }
+                       *q =0;
+       return qry;
+}
+
 static void
 parseArguments(char *call, int m)
 {
@@ -83,8 +106,11 @@ parseArguments(char *call, int m)
                        c++; c++;
                        // parse string skipping escapes
                        for(l=c; *l; l++){
+                               if( *l =='\\' &&  *(l+1) =='\\' && *(l+2) 
=='\\' &&  *(l+3) =='"') { l+=3; continue;}
+                               if( *l =='\\' &&  *(l+1) =='\\') { l++; 
continue;}
+                               if( *l =='\\' &&  *(l+1) =='n') { l++; 
continue;}
+                               if( *l =='\\' &&  *(l+1) =='t') { l++; 
continue;}
                                if( *l =='\\' &&  *(l+1) =='"') break;
-                               if( *l == '\\') l++;
                        }
                        *l= 0;
                        malarguments[malargc] = strdup(c);
diff --git a/clients/mapiclient/eventparser.h b/clients/mapiclient/eventparser.h
--- a/clients/mapiclient/eventparser.h
+++ b/clients/mapiclient/eventparser.h
@@ -102,4 +102,5 @@ extern char *monetdb_characteristics;
 
 extern void clearArguments(void);
 extern int eventparser(char *row, EventRecord *ev);
+extern char *stripQuotes(char *currentquery);
 #endif /*_EVENT_PARSER_*/
diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c
--- a/clients/mapiclient/tachograph.c
+++ b/clients/mapiclient/tachograph.c
@@ -69,6 +69,7 @@ static stream *conn = NULL;
 static char hostname[128];
 static char *basefilename = "tachograph";
 static char *cache= "cache";
+static char cachebuf[BUFSIZ]={0};
 static char *dbname;
 static int beat = 5000;
 static int delay = 0; // ms
@@ -506,53 +507,25 @@ initFiles(void)
 {
        char buf[BUFSIZ];
 
-       if (cache)
-#ifdef NATIVE_WIN32
-               
snprintf(buf,BUFSIZ,"%s\\%s_%s_%d.json",cache,basefilename,dbname, queryid);
-#else
-               
snprintf(buf,BUFSIZ,"%s/%s_%s_%d.json",cache,basefilename,dbname, queryid);
-#endif
-       else 
-               snprintf(buf,BUFSIZ,"%s_%s_%d.json",basefilename,dbname, 
queryid);
+       snprintf(buf,BUFSIZ,"%s%s_%s_%d.json", cachebuf, basefilename, dbname, 
queryid);
        tachojson= fopen(buf,"w");
        if( tachojson == NULL){
                fprintf(stderr,"Could not create %s\n",buf);
                exit(0);
        }
-       if (cache)
-#ifdef NATIVE_WIN32
-               
snprintf(buf,BUFSIZ,"%s\\%s_%s_%d_mal.csv",cache,basefilename,dbname, queryid);
-#else
-               
snprintf(buf,BUFSIZ,"%s/%s_%s_%d_mal.csv",cache,basefilename,dbname, queryid);
-#endif
-       else 
-               snprintf(buf,BUFSIZ,"%s_%s_%d_mal.csv",basefilename,dbname, 
queryid);
+       snprintf(buf,BUFSIZ,"%s%s_%s_%d_mal.csv",cachebuf, basefilename, 
dbname, queryid);
        tachomal= fopen(buf,"w");
        if( tachomal == NULL){
                fprintf(stderr,"Could not create %s\n",buf);
                exit(0);
        }
-       if (cache)
-#ifdef NATIVE_WIN32
-               
snprintf(buf,BUFSIZ,"%s\\%s_%s_%d_stmt.csv",cache,basefilename,dbname, queryid);
-#else
-               
snprintf(buf,BUFSIZ,"%s/%s_%s_%d_stmt.csv",cache,basefilename,dbname, queryid);
-#endif
-       else 
-               snprintf(buf,BUFSIZ,"%s_%s_%d_stmt.csv",basefilename,dbname, 
queryid);
+       snprintf(buf,BUFSIZ,"%s%s_%s_%d_stmt.csv", cachebuf, basefilename, 
dbname, queryid);
        tachostmt= fopen(buf,"w");
        if( tachostmt == NULL){
                fprintf(stderr,"Could not create %s\n",buf);
                exit(0);
        }
-       if (cache)
-#ifdef NATIVE_WIN32
-               
snprintf(buf,BUFSIZ,"%s\\%s_%s_%d.trace",cache,basefilename,dbname, queryid);
-#else
-               
snprintf(buf,BUFSIZ,"%s/%s_%s_%d.trace",cache,basefilename,dbname, queryid);
-#endif
-       else 
-               snprintf(buf,BUFSIZ,"%s_%s_%d.trace",basefilename,dbname, 
queryid);
+       snprintf(buf,BUFSIZ,"%s%s_%s_%d.trace", cachebuf, basefilename, dbname, 
queryid);
        tachotrace= fopen(buf,"w");
        if( tachotrace == NULL){
                fprintf(stderr,"Could not create %s\n",buf);
@@ -580,7 +553,7 @@ update(EventRecord *ev)
 {
        int progress=0;
        int i,j;
-       char *v, *qry, *q = 0, *c;
+       char *v;
        int uid = 0,qid = 0;
        char line[BUFSIZ];
        char prereq[BUFSIZ]={0};
@@ -656,25 +629,11 @@ update(EventRecord *ev)
                        events = (Event*) malloc(malsize * sizeof(Event));
                        memset((char*)events, 0, malsize * sizeof(Event));
                        // use the truncated query text, beware that the \ is 
already escaped in the call argument.
-                       q = qry = (char *) malloc(strlen(currentquery) * 2);
-                       for (c= currentquery; *c; ){
-                               if ( strncmp(c,"\\\\t",3) == 0){
-                                       *q++ = '\t';
-                                       c+=3;
-                               } else
-                               if ( strncmp(c,"\\\\n",3) == 0){
-                                       *q++ = '\n';
-                                       c+=3;
-                               } else if ( strncmp(c,"\\\\",2) == 0){
-                                       c+= 2;
-                               } else *q++ = *c++;
-                       }
-                       *q =0;
-                       currentquery = qry;
+                       currentquery = stripQuotes(malarguments[malretc]);
                        if( ! (prevquery && strcmp(currentquery,prevquery)== 0) 
&& interactive )
-                               printf("CACHE ID:%d\n%s\n",queryid, qry);
+                               printf("CACHE ID:%d\n%s\n",queryid, 
currentquery);
                        prevquery = currentquery;
-                       progressBarInit(qry);
+                       progressBarInit(currentquery);
                }
                if( ev->tag != currenttag)
                        return; // forget all except one query
@@ -923,6 +882,12 @@ main(int argc, char **argv)
                }
        }
 
+       if (cache)
+#ifdef NATIVE_WIN32
+               snprintf(cachebuf,BUFSIZ,"%s\\",cache);
+#else
+               snprintf(cachebuf,BUFSIZ,"%s/",cache);
+#endif
        if(dbname == NULL){
                usageTachograph();
                exit(-1);
@@ -995,13 +960,11 @@ main(int argc, char **argv)
        if( cache){
 #ifdef NATIVE_WIN32
                _mkdir(cache);
-               
snprintf(buf,BUFSIZ,"%s\\%s_%s.trace",cache,basefilename,dbname);
 #else
                mkdir(cache,0755);
-               snprintf(buf,BUFSIZ,"%s/%s_%s.trace",cache,basefilename,dbname);
 #endif
-       } else
-               snprintf(buf,BUFSIZ,"%s_%s.trace",basefilename,dbname);
+       } 
+       snprintf(buf,BUFSIZ,"%s%s_%s.trace", cachebuf, basefilename,dbname);
        // keep a trace of the events received
        trace = fopen(buf,"w");
        if( trace == NULL)
diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -68,6 +68,9 @@
 static stream *conn = NULL;
 static char hostname[128];
 static char *basefilename = "tomograph";
+static char *dbname = NULL;
+static char *cache= "cache";
+static char cachebuf[BUFSIZ]={0};
 static FILE *tracefd;
 static lng startrange = 0, endrange = 0;
 static int systemcall = 1; // attempt system call
@@ -76,7 +79,7 @@ static char *title = 0;
 static char *query = 0;
 static int beat = 5000;
 static int cpus = 0;
-static int atlas= 1;
+static int atlas= 32;
 static int atlaspage = 0;
 static FILE *gnudata;
 static Mapi dbh;
@@ -384,11 +387,13 @@ showNumaHeatmap(void){
        int i,j =0;
        int max= 0;
        FILE *f;
+       char buf[BUFSIZ];
 
        
-       f= fopen("tomograph_heatmap.csv","a");
+       snprintf(buf,BUFSIZ,"%stomograph_%s_heatmap.csv",cachebuf,dbname);
+       f= fopen(buf,"a");
        if( f == NULL){
-               fprintf(stderr,"Can not create tomograph_heatmap.csv\n");
+               fprintf(stderr,"Can not create %s\n",buf);
                return;
        }
        for( i=0; i< MAXTHREADS; i++){
@@ -427,6 +432,7 @@ usageTomograph(void)
        fprintf(stderr, "  -r | --range=<starttime>-<endtime>[ms,s] \n");
        fprintf(stderr, "  -i | --input=<profiler event file > \n");
        fprintf(stderr, "  -o | --output=<file prefix > (default 
'tomograph'\n");
+    fprintf(stderr, "  -c | --cache=<query pool location>\n");
        fprintf(stderr, "  -s | --system=# (on= 1(default) off=0\n");
        fprintf(stderr, "  -b | --beat=<delay> in milliseconds (default 
5000)\n");
        fprintf(stderr, "  -A | --atlas=<number> maximum number of queries 
(default 1)\n");
@@ -456,28 +462,32 @@ stop_disconnect:
        // show follow up action only once
        if(atlaspage >= 1){
                for (i = 0; systemcall && error == 0 && i< atlaspage;  i++){
-                       snprintf(buf, BUFSIZ, "gnuplot 
%s_%02d.gpl;",basefilename,i);
-                       plen += snprintf(pages, BSIZE 
-plen,"%s_%02d.pdf;",basefilename,i);
+                       snprintf(buf, BUFSIZ, "gnuplot %s%s_%s_%02d.gpl;", 
cachebuf, basefilename, dbname, i);
+                       fprintf(stderr,"-- exec:%s\n",buf);
+                       error = system(buf);
+
+                       snprintf(buf, BUFSIZ, "%s%s_%s_%02d.pdf ", cachebuf, 
basefilename, dbname, i);
+                       plen += snprintf(pages + plen, BSIZE -plen,"%s",buf);
                        if ( plen >= BSIZE-1){
                                error = -1;
                                break;
                        } 
-                       error = system(buf);
                }
 
                if( i < atlaspage)
                        fprintf(stderr, "To finish the atlas run:\n");
                for (; i< atlaspage;  i++)
-                       fprintf(stderr, "gnuplot %s_%02d.gpl;",basefilename,i);
+                       fprintf(stderr, "gnuplot %s%s_%s_%02d.gpl;", cachebuf, 
basefilename, dbname,i);
 
                if( systemcall && error == 0) {
-                       snprintf(buf, BSIZE, "gs -q -dNOPAUSE -sDEVICE=pdfwrite 
-sOUTPUTFILE=%s.pdf -dBATCH %s",basefilename,pages);
+                       snprintf(buf, BSIZE, "gs -q -dNOPAUSE -sDEVICE=pdfwrite 
-sOUTPUTFILE=%s%s_%s.pdf -dBATCH %s",cachebuf,basefilename,dbname,pages);
+                       fprintf(stderr,"-- exec:%s\n",buf);
                        error = system(buf);
                }
                if( error == 0) 
-                       fprintf(stderr,"-- done: %s.pdf\n", basefilename);
+                       fprintf(stderr,"-- done: %s%s_%s.pdf\n", cachebuf, 
basefilename,dbname);
                else
-                       fprintf(stderr, "gs -dNOPAUSE -sDEVICE=pdfwrite 
-sOUTPUTFILE=%s.pdf -dBATCH %s\n",basefilename,pages);
+                       fprintf(stderr, "gs -dNOPAUSE -sDEVICE=pdfwrite 
-sOUTPUTFILE=%s%s_%s.pdf -dBATCH %s\n", cachebuf, basefilename,dbname,pages);
        }
 
        if(dbh)
@@ -520,11 +530,13 @@ int object = 1;
 static void resetTomograph(void){
        static char buf[BUFSIZ];
        int i;
-       snprintf(buf,BUFSIZ,"%s_%02d.trace",basefilename,atlaspage);
+
+       snprintf(buf,BUFSIZ,"%s%s_%s_%02d.trace", cachebuf, 
basefilename,dbname,atlaspage);
+
        if( inputfile == 0 || strcmp(inputfile,buf) ){
                tracefd = fopen(buf,"w");
                if( tracefd == NULL)
-                       fprintf(stderr,"Could not create trace file\n");
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to