Changeset: 96d1f39753b3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=96d1f39753b3
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        monetdb5/mal/mal_runtime.c
        monetdb5/modules/mal/profiler.c
        monetdb5/modules/mal/profiler.h
        monetdb5/modules/mal/profiler.mal
Branch: Jul2015
Log Message:

Limit access to the profiler information
The profiling events are filtered on the user id setting up
the profiling channel. This way there is less leakage from
concurrent user queries.


diffs (209 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1183,11 +1183,11 @@ str CMDsetProfilerStream(Client cntxt, M
 str CMDsetoid(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDstartStethoscope(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 str CMDstartTomograph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
-str CMDstethoscope(void *ret, int *beat);
+str CMDstethoscope(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDstopProfiler(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDstr2qgrams(bat *ret, str *val);
 str CMDstrlength(int *ret, str *v);
-str CMDtomograph(void *ret, int *beat);
+str CMDtomograph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDvarABS(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDvarADD(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 str CMDvarADDsignal(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
@@ -2518,7 +2518,7 @@ str printRef;
 void printSignature(stream *fd, Symbol s, int flg);
 void printStack(stream *f, MalBlkPtr mb, MalStkPtr s);
 str prodRef;
-void profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int 
start);
+void profilerEvent(oid usr, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int 
start);
 void profilerGetCPUStat(lng *user, lng *nice, lng *sys, lng *idle, lng 
*iowait);
 void profilerHeartbeatEvent(char *msg);
 str profilerRef;
@@ -2654,7 +2654,7 @@ int sqlblob_tostr(str *tostr, int *l, co
 int sqlfunctionProp;
 str srvpoolRef;
 int stableProp;
-str startProfiler(int mode, int beat);
+str startProfiler(oid user, int mode, int beat);
 str startRef;
 str stopProfiler(void);
 str stopRef;
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -98,7 +98,7 @@ int mal_init(void){
        /* Use the same shortcuts as stethoscope */
        if ( mal_trace ) {
                openProfilerStream(mal_clients[0].fdout);
-               startProfiler(1,0);
+               startProfiler(mal_clients[0].user,1,0);
        } 
        return 0;
 }
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
@@ -26,6 +26,7 @@ stream *eventstream = 0;
 static int offlineProfiling = FALSE;
 static int cachedProfiling = FALSE;
 static str myname = 0;
+static oid user = 0;
 
 static void offlineProfilerEvent(MalBlkPtr mb, MalStkPtr stk, InstrPtr pc, int 
start, char *alter, char *msg);
 static void cachedProfilerEvent(MalBlkPtr mb, MalStkPtr stk, InstrPtr pc);
@@ -118,9 +119,9 @@ static void logsend(char *logbuffer)
  * Note that the profiler itself should lead to event generations.
  */
 void
-profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int start)
+profilerEvent(oid usr, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int start)
 {
-       (void) idx;
+       if( usr != user) return; // only trace your own commands
        if (stk == NULL) return;
        if (pci == NULL) return;
        if (getModuleId(pci) == myname) // ignore profiler commands from 
monitoring
@@ -338,10 +339,11 @@ closeProfilerStream(void)
 static int TRACE_init = 0;
 
 str
-startProfiler(int mode, int beat)
+startProfiler(oid usr, int mode, int beat)
 {
        Client c;
        int i,j;
+       
 
 #ifdef HAVE_SYS_RESOURCE_H
        getrusage(RUSAGE_SELF, &infoUsage);
@@ -361,6 +363,7 @@ startProfiler(int mode, int beat)
        malProfileMode = mode;
        eventcounter = 0;
        setHeartbeat(beat); 
+       user = usr;
        MT_lock_unset(&mal_profileLock, "startProfiler");
 
        /* show all in progress instructions for stethoscope startup */
@@ -387,6 +390,7 @@ stopProfiler(void)
        cachedProfiling = FALSE;
        setHeartbeat(0); // stop heartbeat
        closeProfilerStream();
+       user = 0;
        MT_lock_unset(&mal_profileLock, "stopProfiler");
        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
@@ -51,7 +51,7 @@ mal_export int getProfileCounter(int idx
 mal_export str openProfilerStream(stream *fd);
 mal_export str closeProfilerStream(void);
 
-mal_export void profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, int start);
+mal_export void profilerEvent(oid usr, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, int start);
 mal_export void profilerHeartbeatEvent(char *msg);
 mal_export str setLogFile(stream *fd, Module cntxt, const char *fname);
 mal_export str setLogStream(Module cntxt, const char *host, int port);
@@ -59,7 +59,7 @@ mal_export str setLogStreamStream(Module
 mal_export str setStartPoint(Module cntxt, const char *mod, const char *fcn);
 mal_export str setEndPoint(Module cntxt, const char *mod, const char *fcn);
 
-mal_export str startProfiler(int mode, int beat);
+mal_export str startProfiler(oid user, int mode, int beat);
 mal_export str stopProfiler(void);
 mal_export void setHeartbeat(int delay);
 mal_export str cleanupProfiler(void);
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -172,7 +172,7 @@ runtimeProfileBegin(Client cntxt, MalBlk
        /* emit the instruction upon start as well */
        
        if(malProfileMode > 0)
-               profilerEvent(cntxt->idx, mb, stk, pci, TRUE);
+               profilerEvent(cntxt->user, mb, stk, pci, TRUE);
 }
 
 void
@@ -198,7 +198,7 @@ runtimeProfileExit(Client cntxt, MalBlkP
                pci->wbytes += getVolume(stk, pci, 1);
                if (pci->recycle)
                        pci->rbytes += getVolume(stk, pci, 0);
-               profilerEvent(cntxt->idx, mb, stk, pci, FALSE);
+               profilerEvent(cntxt->user, mb, stk, pci, FALSE);
        }
        if( malProfileMode < 0){
                /* delay profiling until you encounter start of MAL function */
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
@@ -159,22 +159,25 @@ CMDgetSystemTime(lng *ret)
 }
 
 str
-CMDtomograph(void *ret, int *beat)
+CMDtomograph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pc)
 {
-       (void) ret;
-       if( *beat < 0)
+       int beat = *getArgReference_int(stk,pc,1);
+       (void) mb;
+       if( beat < 0)
                throw(MAL,"profiler.tomograph","negative heart beat not 
allowed");
-       startProfiler(-1, *beat);
+       startProfiler(cntxt->user, -1, beat);
        return MAL_SUCCEED;
 }
 
 str
-CMDstethoscope(void *ret,int *beat)
+CMDstethoscope(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pc)
 {
-       (void) ret;
-       if( *beat < 0)
+       int beat = *getArgReference_int(stk,pc,1);
+
+       (void) mb;
+       if( beat < 0)
                throw(MAL,"profiler.stethoscope","negative heart beat not 
allowed");
-       startProfiler(1, *beat);
+       startProfiler(cntxt->user, 1, beat);
        return MAL_SUCCEED;
 }
 
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
@@ -55,8 +55,8 @@ profiler_export str CMDgetDiskReads(lng 
 profiler_export str CMDgetDiskWrites(lng *ret);
 profiler_export str CMDgetUserTime(lng *ret);
 profiler_export str CMDgetSystemTime(lng *ret);
-profiler_export str CMDstethoscope(void *ret, int *beat);
-profiler_export str CMDtomograph(void *ret, int *beat);
+profiler_export str CMDstethoscope(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
+profiler_export str CMDtomograph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 profiler_export str CMDcpustats(lng *user, lng *nice, lng *sys, lng *idle, lng 
*iowait);
 profiler_export str CMDcpuloadPercentage(int *cycles, int *io, lng *user, lng 
*nice, lng *sys, lng *idle, lng *iowait);
 #endif  /* _PROFILER_*/
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
@@ -6,11 +6,11 @@
 
 module profiler;
 
-command tomograph(b:int)
+pattern tomograph(b:int)
 address CMDtomograph
 comment "Start tomograph profiler with heart beat";
 
-command stethoscope(b:int)
+pattern stethoscope(b:int)
 address CMDstethoscope
 comment "Start stethoscope profiling with heart beat";
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to