Changeset: 7977634f6a54 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7977634f6a54 Modified Files: clients/mapiclient/stethoscope.c monetdb5/mal/mal_dataflow.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.mal monetdb5/optimizer/opt_evaluate.c Branch: default Log Message:
Removed rendering option from openstream. Generate heartbeat at start of function call. Include access control to eventstream. MAL_ADMIN can always grab it. Others may have to wait for the free channel and only see events of their own queries. diffs (222 lines): diff --git a/clients/mapiclient/stethoscope.c b/clients/mapiclient/stethoscope.c --- a/clients/mapiclient/stethoscope.c +++ b/clients/mapiclient/stethoscope.c @@ -71,7 +71,6 @@ static char hostname[128]; static char *filename = NULL; static int beat = 0; static int json = 0; -static int stream_mode = 1; static Mapi dbh; static MapiHdl hdl = NULL; static FILE *trace = NULL; @@ -346,7 +345,6 @@ main(int argc, char **argv) break; case 'j': json = 1; - stream_mode = 1; break; case 'o': filename = strdup(optarg); @@ -422,7 +420,7 @@ main(int argc, char **argv) fprintf(stderr,"-- %s\n",buf); doQ(buf); - snprintf(buf, BUFSIZ, "profiler.openstream(%d);", stream_mode); + snprintf(buf, BUFSIZ, "profiler.openstream();"); if( debug) fprintf(stderr,"--%s\n",buf); doQ(buf); diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c --- a/monetdb5/mal/mal_dataflow.c +++ b/monetdb5/mal/mal_dataflow.c @@ -460,14 +460,6 @@ DFLOWworker(void *T) MT_lock_unset(&flow->flowlock); q_enqueue(flow->done, fe); - if ( fnxt == 0 && malProfileMode) { - int last; - MT_lock_set(&todo->l); - last = todo->last; - MT_lock_unset(&todo->l); - if (last == 0) - profilerHeartbeatEvent("wait"); - } } GDKfree(GDKerrbuf); GDKsetbuf(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 @@ -44,7 +44,7 @@ static str myname = 0; // avoid tracing int malProfileMode = 0; /* global flag to indicate profiling mode */ -static Client malprofileruser; +static oid malprofileruser; /* keep track on who has claimed the channel */ static struct timeval startup_time; @@ -152,7 +152,7 @@ renderProfilerEvent(Client cntxt, MalBlk /* The stream of events can be complete read by the DBA, * all other users can only see events assigned to their account */ - if( malprofileruser->user != MAL_ADMIN && malprofileruser->user != cntxt->user) + if( malprofileruser!= MAL_ADMIN && malprofileruser != cntxt->user) return; usec= GDKusec(); @@ -474,11 +474,13 @@ profilerHeartbeatEvent(char *alter) char cpuload[BUFSIZ]; char logbuffer[LOGLEN], *logbase; int loglen; - lng usec = GDKusec(); - uint64_t microseconds = (uint64_t)startup_time.tv_sec*1000000 + (uint64_t)startup_time.tv_usec + (uint64_t)usec; + lng usec; + uint64_t microseconds; - if (ATOMIC_GET(&hbdelay) == 0 || malprofileruser == NULL) + if (ATOMIC_GET(&hbdelay) == 0 || maleventstream == 0) return; + usec = GDKusec(); + microseconds = (uint64_t)startup_time.tv_sec*1000000 + (uint64_t)startup_time.tv_usec + (uint64_t)usec; /* get CPU load on beat boundaries only */ if ( getCPULoad(cpuload) ) @@ -521,6 +523,7 @@ profilerHeartbeatEvent(char *alter) void profilerEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int start) { + (void) cntxt; if (stk == NULL) return; if (pci == NULL) return; if (getModuleId(pci) == myname) // ignore profiler commands from monitoring @@ -537,10 +540,8 @@ profilerEvent(Client cntxt, MalBlkPtr mb /* The first scheme dumps the events on a stream (and in the pool) */ -#define PROFSHOWRUNNING 1 -#define PROFSINGLELINE 2 str -openProfilerStream(Client cntxt, int mode) +openProfilerStream(Client cntxt) { int j; @@ -561,21 +562,18 @@ openProfilerStream(Client cntxt, int mod } malProfileMode = -1; maleventstream = cntxt->fdout; - malprofileruser = cntxt; - (void) mode; + malprofileruser = cntxt->user; + // Ignore the JSON rendering mode, use compiled time version - // prettify = (mode & PROFSINGLELINE) ? "": "\n"; /* show all in progress instructions for stethoscope startup */ /* this code is not thread safe, because the inprogress administration may change concurrently */ - if( (mode & PROFSHOWRUNNING) > 0){ - MT_lock_set(&mal_delayLock); - for(j = 0; j <THREADS; j++) - if( workingset[j].mb) - /* show the event */ - profilerEvent(workingset[j].cntxt, workingset[j].mb, workingset[j].stk, workingset[j].pci, 1); - MT_lock_unset(&mal_delayLock); - } + MT_lock_set(&mal_delayLock); + for(j = 0; j <THREADS; j++) + if( workingset[j].mb) + /* show the event */ + profilerEvent(workingset[j].cntxt, workingset[j].mb, workingset[j].stk, workingset[j].pci, 1); + MT_lock_unset(&mal_delayLock); return MAL_SUCCEED; } @@ -890,8 +888,10 @@ static void profilerHeartbeat(void *dumm return; MT_sleep_ms(t > timeout ? timeout : t); } + if (GDKexiting() || !ATOMIC_GET(&hbrunning)) + return; MT_thread_setworking("pinging"); - profilerHeartbeatEvent("ping"); + profilerHeartbeatEvent( "ping"); } } 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 @@ -23,7 +23,7 @@ typedef struct rusage Rusage; mal_export int malProfileMode; mal_export void initProfiler(void); -mal_export str openProfilerStream(Client cntxt, int mode); +mal_export str openProfilerStream(Client cntxt); mal_export str closeProfilerStream(Client cntxt); mal_export void profilerEvent(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int start); 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 @@ -108,6 +108,8 @@ runtimeProfileInit(Client cntxt, MalBlkP stk->tag = QRYqueue[i].tag; qtop += i == qtop; MT_lock_unset(&mal_delayLock); + /* When you start a routine, also emit a heartbeat */ + profilerHeartbeatEvent("wait"); } /* We should keep a short list of previously executed queries/client for inspection */ 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 @@ -42,7 +42,7 @@ CMDopenProfilerStream(Client cntxt, MalB (void) mb; (void) stk; (void) pc; - return openProfilerStream(cntxt, *getArgReference_int(stk,pc,1)); + return openProfilerStream(cntxt); } str 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 @@ -30,7 +30,7 @@ command setheartbeat(b:int):void address CMDsetHeartbeat comment "Set heart beat performance tracing"; -pattern openstream(mode:int):void +pattern openstream():void address CMDopenProfilerStream comment "Start profiling the events, send to output stream"; diff --git a/monetdb5/optimizer/opt_evaluate.c b/monetdb5/optimizer/opt_evaluate.c --- a/monetdb5/optimizer/opt_evaluate.c +++ b/monetdb5/optimizer/opt_evaluate.c @@ -120,7 +120,7 @@ OPTevaluateImplementation(Client cntxt, InstrPtr p; int i, k, limit, *alias = 0, barrier; MalStkPtr env = NULL; - int profiler; + int profiler, sqlprofiler; int debugstate = cntxt->itrace, actions = 0, constantblock = 0; int *assigned = 0, use; char buf[256]; @@ -179,6 +179,7 @@ OPTevaluateImplementation(Client cntxt, barrier = p->barrier; p->barrier = 0; profiler = malProfileMode; /* we don't trace it */ + sqlprofiler = cntxt->sqlprofiler; malProfileMode = 0; if ( env == NULL) { env = prepareMALstack(mb, 2 * mb->vsize); @@ -190,6 +191,7 @@ OPTevaluateImplementation(Client cntxt, } msg = reenterMAL(cntxt, mb, i, i + 1, env); malProfileMode= profiler; + cntxt->sqlprofiler = sqlprofiler; p->barrier = barrier; if( OPTdebug & OPTevaluate){ fprintf(stderr, "#retc var %s\n", getVarName(mb, getArg(p, 0))); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list