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

Defense code and dynamic grow
- permit larger tomographs to be assembled using dynamic growing box table
- improve error message
- check and defense against failing mkdir


diffs (106 lines):

diff --git a/clients/mapiclient/eventparser.h b/clients/mapiclient/eventparser.h
--- a/clients/mapiclient/eventparser.h
+++ b/clients/mapiclient/eventparser.h
@@ -55,9 +55,6 @@
 #define US_HH (US_MM * 60)
 #define US_DD (US_HH * 24)
 
-#define MAXTHREADS 1048
-#define MAXBOX 32678    /* should be > MAXTHREADS */
-
 #define  MDB_START 1
 #define  MDB_DONE 2
 #define  MDB_PING 3
diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c
--- a/clients/mapiclient/tachograph.c
+++ b/clients/mapiclient/tachograph.c
@@ -959,10 +959,13 @@ main(int argc, char **argv)
        doQ(buf);
        if( cache){
 #ifdef NATIVE_WIN32
-               _mkdir(cache);
+               if( access(cache,F_OK) && _mkdir(cache)){
 #else
-               mkdir(cache,0755);
+               if( access(cache,F_OK) && mkdir(cache,0755) ) {
 #endif
+                       fprintf(stderr,"Failed to create cache '%s'\n",cache);
+                       exit(-1);
+               }
        } 
        snprintf(buf,BUFSIZ,"%s%s_%s.trace", cachebuf, basefilename,dbname);
        // keep a trace of the events received
diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c
--- a/clients/mapiclient/tomograph.c
+++ b/clients/mapiclient/tomograph.c
@@ -493,9 +493,9 @@ stop_disconnect:
                }
 
                if( i < atlaspage)
-                       fprintf(stderr, "To finish the atlas run:\n");
+                       fprintf(stderr, "To finish the atlas make sure gnuplot 
is available and run:\n");
                for (; i< atlaspage;  i++)
-                       fprintf(stderr, "gnuplot %s%s_%s_%02d.gpl;", cachebuf, 
basefilename, dbname,i);
+                       fprintf(stderr, "gnuplot %s%s_%s_%02d.gpl\n", cachebuf, 
basefilename, dbname,i);
 
                if( systemcall && error == 0) {
                        snprintf(buf, BSIZE, "gs -q -dNOPAUSE -sDEVICE=pdfwrite 
-sOUTPUTFILE=%s%s_%s.pdf -dBATCH %s",cachebuf,basefilename,dbname,pages);
@@ -531,8 +531,9 @@ typedef struct BOX {
 
 int threads[MAXTHREADS];
 lng lastclk[MAXTHREADS];
-Box box[MAXBOX];
+Box *box= 0;
 int topbox = 0;
+int maxbox = 0;
 int events = 0;
 
 lng totalclkticks = 0; /* number of clock ticks reported */
@@ -568,7 +569,7 @@ static void resetTomograph(void){
        events = 0;
        for (i = 0; i < MAXTHREADS; i++)
                threads[i] = topbox++;
-       memset((char*) box, 0, sizeof(Box) * MAXBOX);
+       memset((char*) box, 0, sizeof(Box) * maxbox);
 
        totalclkticks = 0; 
        totalexecticks = 0;
@@ -1331,10 +1332,18 @@ update(char *line, EventRecord *ev)
        char *s;
        int uid = 0,qid = 0;
  
-       if (topbox == MAXBOX) {
-               fprintf(stderr, "Out of space for trace");
-               createTomogram();
-               exit(0);
+       if (topbox == maxbox || maxbox < topbox) {
+       
+               if( box == 0)
+                       box = (Box*) malloc(MAXBOX * sizeof(Box)); 
+               else
+                       box = (Box*) realloc((void*)box, (maxbox + MAXBOX) * 
sizeof(Box)); 
+               if( box == NULL){
+                       fprintf(stderr, "Out of space for trace, exceeds max 
entries %d\n", maxbox);
+                       fprintf(stderr, "Restart with a slower beat might help, 
e.g. --beat=5000  or --beat=0\n");
+                       exit(0);
+               }
+               maxbox += MAXBOX;
        }
        /* handle a ping event, keep the current instruction in focus */
        if (ev->state >= MDB_PING ) {
@@ -1714,10 +1723,13 @@ main(int argc, char **argv)
        /* reprocess an existing profiler trace, possibly producing the trace 
split   */
        if (cache) {
 #ifdef NATIVE_WIN32
-               _mkdir(cache);
+               if( access(cache, F_OK) && _mkdir(cache)){
 #else
-               mkdir(cache,0755);
+               if( access(cache, F_OK) &&  mkdir(cache,0755) ) {
 #endif
+                       fprintf(stderr,"Failed to create cache '%s'\n",cache);
+                       exit(-1);
+               }
        }
        snprintf(buf,BUFSIZ,"%s%s_%s_%02d.trace", cachebuf, basefilename, 
dbname, atlaspage);
        if (inputfile==0 || strcmp(buf, inputfile) ){
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to