Changeset: 77beed0b06a5 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=77beed0b06a5 Modified Files: clients/mapiclient/eventparser.c clients/mapiclient/tachograph.c clients/mapiclient/tomograph.c Branch: default Log Message:
Footnote, defense code, row shifting - footnote for ease reference - avoid leaks and memory limits - shift rows up when less cores are used diffs (truncated from 363 to 300 lines): diff --git a/clients/mapiclient/eventparser.c b/clients/mapiclient/eventparser.c --- a/clients/mapiclient/eventparser.c +++ b/clients/mapiclient/eventparser.c @@ -48,6 +48,10 @@ char * stripQuotes(char *currentquery) { char *q, *c, *qry; q = qry = (char *) malloc(strlen(currentquery) * 2); + if( q == NULL){ + fprintf(stderr,"Could not allocate query buffer of size "SZFMT"\n", strlen(currentquery) * 2); + exit(-1); + } for (c= currentquery; *c; ){ if ( strncmp(c,"\\\\t",3) == 0){ *q++ = '\t'; @@ -98,6 +102,10 @@ parseArguments(char *call, int m) break; *c = 0; malvariables[malvartop++] = strdup(v); + if( malvariables[malvartop-1] == NULL){ + fprintf(stderr,"Could not allocate memory\n"); + exit(-1); + } *c = '='; c++; } @@ -114,6 +122,10 @@ parseArguments(char *call, int m) } *l= 0; malarguments[malargc] = strdup(c); + if( malarguments[malargc] == NULL){ + fprintf(stderr,"Could not allocate memory\n"); + exit(-1); + } c= l+1; // we skip to the type or end of term while( *c && *c != ':' && *c !=',' && *c !=')' && *c != ';') c++; @@ -124,6 +136,10 @@ parseArguments(char *call, int m) c++; *c =0; malarguments[malargc] = strdup(l); + if( malarguments[malargc] == NULL){ + fprintf(stderr,"Could not allocate memory\n"); + exit(-1); + } *c = '['; malcount[malargc]=atoi(c+1); while( *c && *c != ':' && *c !=',' && *c !=')' && *c != ';') c++; @@ -134,6 +150,10 @@ parseArguments(char *call, int m) ch = *c; *c=0; malarguments[malargc] = strdup(l); + if( malarguments[malargc] == NULL){ + fprintf(stderr,"Could not allocate memory\n"); + exit(-1); + } *c = ch; if( ch == ';') break; } @@ -152,6 +172,10 @@ parseArguments(char *call, int m) malpc[malargc] = argc; argc+= m; maltypes[malargc++] = strdup(w); + if( malarguments[malargc-1] == NULL){ + fprintf(stderr,"Could not allocate memory\n"); + exit(-1); + } *c = ch; if( ch == ';') break; } else malargc++; @@ -230,6 +254,10 @@ eventparser(char *row, EventRecord *ev) return -4; *c = 0; ev->blk= strdup(nme); + if( ev->blk == NULL){ + fprintf(stderr,"Could not allocate blk memory\n"); + exit(-1); + } *c = '['; ev->pc = atoi(c+1); c= strchr(c+1,']'); @@ -298,6 +326,10 @@ eventparser(char *row, EventRecord *ev) return -1; *c = 0; ev->numa= strdup(numa); + if( ev->num == NULL){ + fprintf(stderr,"Could not allocate numa memory\n"); + exit(-1); + } *c = '"'; #endif @@ -337,10 +369,22 @@ eventparser(char *row, EventRecord *ev) return -15; c++; ev->fcn = strdup(c); + if( ev->fcn == NULL){ + fprintf(stderr,"Could not allocate fcn memory\n"); + exit(-1); + } ev->stmt = strdup(ev->fcn); + if( ev->stmt == NULL){ + fprintf(stderr,"Could not allocate stmt memory\n"); + exit(-1); + } c= ev->fcn; if( ev->state == MDB_SYSTEM){ monetdb_characteristics = strdup(ev->stmt); + if( ev->stmt == NULL){ + fprintf(stderr,"Could not allocate monetdb_characteristics memory\n"); + exit(-1); + } } else if( *c != '[') { diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c --- a/clients/mapiclient/tachograph.c +++ b/clients/mapiclient/tachograph.c @@ -511,25 +511,25 @@ initFiles(void) tachojson= fopen(buf,"w"); if( tachojson == NULL){ fprintf(stderr,"Could not create %s\n",buf); - exit(0); + exit(-1); } 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); + exit(-1); } 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); + exit(-1); } 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); - exit(0); + exit(-1); } } @@ -971,8 +971,10 @@ main(int argc, char **argv) snprintf(buf,BUFSIZ,"%s%s_%s.trace", cachebuf, basefilename,dbname); // keep a trace of the events received trace = fopen(buf,"w"); - if( trace == NULL) + if( trace == NULL){ fprintf(stderr,"Could not create trace file\n"); + exit(-1); + } len = 0; while ((n = mnstr_read(conn, buf + len, 1, BUFSIZ - len)) > 0) { diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c --- a/clients/mapiclient/tomograph.c +++ b/clients/mapiclient/tomograph.c @@ -414,7 +414,7 @@ showNumaHeatmap(void){ f= fopen(buf,"a"); if( f == NULL){ fprintf(stderr,"Can not create %s\n",buf); - return; + exit(-1); } for( i=0; i< MAXTHREADS; i++){ if( target[i]) @@ -557,10 +557,15 @@ static void resetTomograph(void){ snprintf(buf,BUFSIZ,"%s%s_%s_%02d.trace", cachebuf, basefilename,DBNAME,atlaspage); - if( inputfile == 0 || strcmp(inputfile,buf) ){ + if( inputfile && strcmp(inputfile,buf) == 0 ){ + fprintf(stderr,"Should not overwrite existing trace file '%s'\n",buf); + exit(-1); + } + if( inputfile == 0 ){ tracefd = fopen(buf,"w"); if( tracefd == NULL) - fprintf(stderr,"Could not create file %s\n",buf); + fprintf(stderr,"Could not create trace file '%s'\n",buf); + exit(-1); } if (debug) fprintf(stderr, "RESET tomograph %d\n", atlaspage); @@ -574,6 +579,12 @@ static void resetTomograph(void){ events = 0; for (i = 0; i < MAXTHREADS; i++) threads[i] = topbox++; + for ( i=MAXTHREADS; i< maxbox; i++){ + if( box[i].fcn ){ + free(box[i].fcn); + box[i].fcn=0; + } + } memset((char*) box, 0, sizeof(Box) * maxbox); totalclkticks = 0; @@ -718,8 +729,8 @@ dumpboxes(void) snprintf(buf, BUFSIZ, "%s%s_%s_%02d.dat", cachebuf, basefilename,DBNAME, atlaspage); f = fopen(buf, "w"); if(f == NULL){ - fprintf(stderr,"Could not create %s\n",buf); - exit(0); + fprintf(stderr,"Could not create file '%s'\n",buf); + exit(-1); } for (i = 0; i < topbox; i++) @@ -997,12 +1008,12 @@ showcolormap(char *filename, int all) for (nl=0, c= currentquery; c && *c; c++) nl += *c == '\n'; + snprintf(buf, BUFSIZ, "%s%s_%s_%02d.gpl", cachebuf, basefilename, DBNAME, atlaspage); if (all) { - snprintf(buf, BUFSIZ, "%s%s_%s_%02d.gpl", cachebuf, basefilename, DBNAME, atlaspage); f = fopen(buf, "w"); if (f == NULL) { - fprintf(stderr, "Creating file %s failed\n", buf); - exit(1); + fprintf(stderr, "Could not create file '%s'\n", buf); + exit(-1); } fprintf(f, "set terminal pdfcairo noenhanced color solid size 8.3, 11.7\n"); fprintf(f, "set output \"%s.pdf\"\n", filename); @@ -1102,6 +1113,7 @@ showcolormap(char *filename, int all) h-= 17; } fprintf(f, "set label %d \"%d\" at 1750.0, 100.00\n", object++, atlaspage + 1); + fprintf(f, "set label %d \"%s\" at 500.0, 100.00\n", object++, buf); fprintf(f, "set label %d \"%s\" at 0.0, 100.00\n", object++, date); fprintf(f, "plot 0 notitle with lines linecolor rgb \"white\"\n"); if (all) { @@ -1182,7 +1194,7 @@ createTomogram(void) { char buf[BUFSIZ]; int rows[MAXTHREADS] = {0}; - int top = 0; + int top = 0, rowoffset = 0; int i, j; int h, prevobject = 1; lng w = lastclktick - starttime; @@ -1196,7 +1208,7 @@ createTomogram(void) snprintf(buf, BUFSIZ, "%s%s_%s_%02d.gpl", cachebuf, basefilename,DBNAME,atlaspage); gnudata = fopen(buf, "w"); if (gnudata == 0) { - printf("Could not create of %s\n", buf); + printf("Could not create file '%s'\n", buf); exit(-1); } if( strrchr(buf,'.')) @@ -1234,7 +1246,9 @@ createTomogram(void) } - height = (top < cpus? cpus : top) * 20; + h = 10; /* unit height of bars */ + height = (top < cpus? cpus : top) * 2 * h; + rowoffset = top<cpus ? cpus-top:0; fprintf(gnudata, "set yrange [0:%d]\n", height); fprintf(gnudata, "set ylabel \"threads\"\n"); fprintf(gnudata, "set key right \n"); @@ -1245,19 +1259,21 @@ createTomogram(void) /* calculate the effective use of parallelism */ totalticks = 0; + if( top < cpus) + for(i=0; i < topbox; i++) + box[i].row += rowoffset; for (i = 0; i < top; i++) totalticks += lastclk[rows[i]]; - h = 10; /* unit height of bars */ fprintf(gnudata, "set ytics ("); for (i = 0; i < top; i++) - fprintf(gnudata, "\"%d\" %d%c", rows[i], i * 2 * h + h / 2, (i < top - 1 ? ',' : ' ')); + fprintf(gnudata, "\"%d\" %d%c", rows[i], (rowoffset + i) * 2 * h + h / 2, (i < top - 1 ? ',' : ' ')); fprintf(gnudata, ")\n"); /* mark duration of each thread */ for (i = 0; i < top; i++) fprintf(gnudata, "set object %d rectangle from %d, %d to "LLFMT".0, %d\n", - object++, 0, i * 2 * h + h/3, lastclk[rows[i]], i * 2 * h + h - h/3); + object++, 0, (rowoffset + i) * 2 * h + h/3, lastclk[rows[i]], (rowoffset + i) * 2 * h + h - h/3); /* fill the duration of each instruction encountered that fit our range constraint */ for (i = 0; i < topbox; i++) @@ -1339,14 +1355,15 @@ update(char *line, EventRecord *ev) if (topbox == maxbox || maxbox < topbox) { - if( box == 0) + if( box == 0){ box = (Box*) malloc(MAXBOX * sizeof(Box)); - else + memset((char*) box, 0, sizeof(Box) * MAXBOX); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list