Changeset: d81137983b22 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d81137983b22
Modified Files:
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        monetdb5/modules/mal/profiler.c
        monetdb5/modules/mal/profiler.h
        monetdb5/modules/mal/profiler.mal
        sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:

Keep a collection of full traces
Each time the SQL user applies the TRACE option, the full json
trace is retained within the <dbpath>/<dbname>/sql_traces


diffs (159 lines):

diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -527,9 +527,28 @@ startProfiler(void)
 }
 
 /* SQL queries can be traced without obstructing the stream */
+/* A hard limit is currently imposed */
+#define MAXTRACEFILES 50
+static int offlinestore = 0;
+static int tracecounter = 0;
 str
-startTrace(void)
+startTrace(str path)
 {
+       char buf[PATHLENGTH];
+
+       if( path && eventstream == NULL){
+               // create a file to keep the events, unless we
+               // already have a profiler stream
+               MT_lock_set(&mal_profileLock );
+               if(eventstream == NULL && offlinestore ==0){
+                       
snprintf(buf,PATHLENGTH,"%s%c%s",GDKgetenv("gdk_dbname"), DIR_SEP, path);
+                       (void) mkdir(buf,0755);
+                       
snprintf(buf,PATHLENGTH,"%s%c%s%ctrace_%d",GDKgetenv("gdk_dbname"), DIR_SEP, 
path,DIR_SEP,tracecounter++ % MAXTRACEFILES);
+                       eventstream = open_wastream(buf);
+                       offlinestore++;
+               }
+               MT_lock_unset(&mal_profileLock );
+       }
        malProfileMode = 1;
        sqlProfiling = TRUE;
        clearTrace();
@@ -537,8 +556,16 @@ startTrace(void)
 }
 
 str
-stopTrace(void)
+stopTrace(str path)
 {
+       MT_lock_set(&mal_profileLock );
+       if( path &&  offlinestore){
+               (void) close_stream(eventstream);
+               eventstream = 0;
+               offlinestore =0;
+       }
+       MT_lock_unset(&mal_profileLock );
+       
        malProfileMode = eventstream != NULL;
        sqlProfiling = FALSE;
        return MAL_SUCCEED;
diff --git a/monetdb5/mal/mal_profiler.h b/monetdb5/mal/mal_profiler.h
--- a/monetdb5/mal/mal_profiler.h
+++ b/monetdb5/mal/mal_profiler.h
@@ -31,8 +31,8 @@ mal_export void profilerEvent(MalBlkPtr 
 
 mal_export str startProfiler(void);
 mal_export str stopProfiler(void);
-mal_export str startTrace(void);
-mal_export str stopTrace(void);
+mal_export str startTrace(str path);
+mal_export str stopTrace(str path);
 mal_export void setHeartbeat(int delay);
 mal_export str setprofilerpoolsize(int size);
 mal_export void initHeartbeat(void);
diff --git a/monetdb5/modules/mal/profiler.c b/monetdb5/modules/mal/profiler.c
--- a/monetdb5/modules/mal/profiler.c
+++ b/monetdb5/modules/mal/profiler.c
@@ -74,18 +74,35 @@ CMDstopProfiler(Client cntxt, MalBlkPtr 
        return stopProfiler();
 }
 
+// called by the SQL front end.
 str
 CMDstartTrace(void *res)
 {
        (void) res;
-       return startTrace();
+       return startTrace(0);
+}
+
+// if you haven't started the stethoscope
+// then the output is saved in a file 
+str
+CMDstartTracePath(void *res, str *path)
+{
+       (void) res;
+       return startTrace(*path);
 }
 
 str
 CMDstopTrace(void *res)
 {
        (void) res;
-       return stopTrace();
+       return stopTrace(0);
+}
+
+str
+CMDstopTracePath(void *res, str *path)
+{
+       (void) res;
+       return stopTrace(*path);
 }
 
 str
diff --git a/monetdb5/modules/mal/profiler.h b/monetdb5/modules/mal/profiler.h
--- a/monetdb5/modules/mal/profiler.h
+++ b/monetdb5/modules/mal/profiler.h
@@ -41,7 +41,9 @@
 profiler_export str CMDstartProfiler(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
 profiler_export str CMDstopProfiler(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 profiler_export str CMDstartTrace(void *res);
+profiler_export str CMDstartTracePath(void *res, str *path);
 profiler_export str CMDstopTrace(void *res);
+profiler_export str CMDstopTracePath(void *res, str *path);
 profiler_export str CMDnoopProfiler(void *res);
 profiler_export str CMDsetHeartbeat(void *res, int *ev);
 profiler_export str CMDopenProfilerStream(Client cntxt, MalBlkPtr mb, 
MalStkPtr stk, InstrPtr pci);
diff --git a/monetdb5/modules/mal/profiler.mal 
b/monetdb5/modules/mal/profiler.mal
--- a/monetdb5/modules/mal/profiler.mal
+++ b/monetdb5/modules/mal/profiler.mal
@@ -18,10 +18,18 @@ command starttrace()
 address CMDstartTrace
 comment "Start collecting trace information";
 
+command starttrace(path:str)
+address CMDstartTracePath
+comment "Start collecting trace information and keep around in 'path' 
directory";
+
 command stoptrace():void
 address CMDstopTrace
 comment "Stop collecting trace information";
 
+command stoptrace(path:str):void
+address CMDstopTracePath
+comment "Stop collecting trace information";
+
 command setheartbeat(b:int):void
 address CMDsetHeartbeat
 comment "Set heart beat performance tracing";
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -906,10 +906,12 @@ SQLsetTrace(backend *be, Client cntxt, b
 
        (void) be;
        if (onoff) {
-               (void) newStmt(mb, "profiler", "starttrace");
+               q= newStmt(mb, "profiler", "starttrace");
+               q= pushStr(mb,q,"sql_traces");
                initTrace();
        } else {
-               (void) newStmt(mb, "profiler", "stoptrace");
+               q= newStmt(mb, "profiler", "stoptrace");
+               q= pushStr(mb,q,"sql_traces");
                /* cook a new resultSet instruction */
                resultset = newInstruction(mb,ASSIGNsymbol);
                setModuleId(resultset, sqlRef);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to