Changeset: 797efa17cc37 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/797efa17cc37 Modified Files: clients/Tests/exports.stable.out monetdb5/mal/mal_client.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/optimizer/opt_fastpath.c monetdb5/optimizer/opt_profiler.c sql/backends/monet5/sql.c sql/backends/monet5/sql_scenario.c sql/server/sql_mvc.c Branch: sql_profiler Log Message:
Add minimal profiler mode feature. diffs (truncated from 667 to 300 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 @@ -1111,7 +1111,8 @@ str malIncludeModules(Client c, char *mo str malIncludeString(Client c, const char *name, str mal, int listing, MALfcn address); int malLibraryEnabled(const char *name); char *malLibraryHowToEnable(const char *name); -int malProfileMode; +int profilerMode; +int profilerStatus; const char *malRef; void mal_atom_reset(void); ClientRec *mal_clients; diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c --- a/monetdb5/mal/mal_client.c +++ b/monetdb5/mal/mal_client.c @@ -183,7 +183,9 @@ MCresetProfiler(stream *fdout) if (fdout != maleventstream) return; MT_lock_set(&mal_profileLock); - maleventstream = 0; + maleventstream = NULL; + profilerStatus = 0; + profilerMode = 0; MT_lock_unset(&mal_profileLock); } @@ -208,7 +210,7 @@ MCexitClient(Client c) c->fdin = NULL; } assert(c->query == NULL); - if(malProfileMode > 0) { + if(profilerStatus > 0) { lng Tend = GDKusec(); profilerEvent((struct MalEvent) {0}, (struct NonMalEvent) 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 @@ -447,7 +447,7 @@ DFLOWworker(void *T) #endif q_enqueue(flow->done, fe); - if ( fnxt == 0 && malProfileMode) { + if ( fnxt == 0 && profilerStatus) { profilerHeartbeatEvent("wait"); } } 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 @@ -40,8 +40,9 @@ static const char *myname = 0; // avoid * also the term rendering to be set to '' */ -int malProfileMode = 0; /* global flag to indicate profiling mode */ -static oid malprofileruser; /* keep track on who has claimed the channel */ +int profilerStatus = 0; /* global flag profiler status */ +int profilerMode = 0; /* global flag profiler mode, minimal or detailed */ +static oid profilerUser; /* keep track on who has claimed the channel */ static struct timeval startup_time; @@ -282,7 +283,7 @@ prepareMalEvent(Client cntxt, MalBlkPtr /* The stream of events can be complete read by the DBA, * all other users can only see events assigned to their account */ - if(malprofileruser!= MAL_ADMIN && malprofileruser != cntxt->user) + if(profilerUser!= MAL_ADMIN && profilerUser != cntxt->user) return NULL; /* align the variable namings with EXPLAIN and TRACE */ @@ -329,171 +330,173 @@ prepareMalEvent(Client cntxt, MalBlkPtr if (mb && pci->modname && pci->fcnname) { int j; - if (!logadd(&logbuf, ",\"args\":[")) - goto cleanup_and_exit; - for(j=0; j< pci->argc; j++){ - int tpe = getVarType(mb, getArg(pci,j)); - str tname = 0, cv; - lng total = 0; - BUN cnt = 0; - bat bid=0; - - if (j == 0) { - // No comma at the beginning - if (!logadd(&logbuf, "{")) - goto cleanup_and_exit; - } - else { - if (!logadd(&logbuf, ",{")) - goto cleanup_and_exit; - } - if (!logadd(&logbuf, "\"%s\":%d,\"var\":\"%s\"", - j < pci->retc ? "ret" : "arg", j, - getVarName(mb, getArg(pci,j)))) + if (profilerMode == 0) { + if (!logadd(&logbuf, ",\"args\":[")) goto cleanup_and_exit; - c =getVarName(mb, getArg(pci,j)); - if(getVarSTC(mb,getArg(pci,j))){ - InstrPtr stc = getInstrPtr(mb, getVarSTC(mb,getArg(pci,j))); - if (stc && getModuleId(stc) && - strcmp(getModuleId(stc),"sql") ==0 && - strncmp(getFunctionId(stc),"bind",4)==0 && - !logadd(&logbuf, ",\"alias\":\"%s.%s.%s\"", - getVarConstant(mb, getArg(stc,stc->retc +1)).val.sval, - getVarConstant(mb, getArg(stc,stc->retc +2)).val.sval, - getVarConstant(mb, getArg(stc,stc->retc +3)).val.sval)) + for(j=0; j< pci->argc; j++){ + int tpe = getVarType(mb, getArg(pci,j)); + str tname = 0, cv; + lng total = 0; + BUN cnt = 0; + bat bid=0; + + if (j == 0) { + // No comma at the beginning + if (!logadd(&logbuf, "{")) + goto cleanup_and_exit; + } + else { + if (!logadd(&logbuf, ",{")) + goto cleanup_and_exit; + } + if (!logadd(&logbuf, "\"%s\":%d,\"var\":\"%s\"", + j < pci->retc ? "ret" : "arg", j, + getVarName(mb, getArg(pci,j)))) goto cleanup_and_exit; - } - if(isaBatType(tpe)){ - BAT *d= BATdescriptor(bid = stk->stk[getArg(pci,j)].val.bval); - tname = getTypeName(getBatType(tpe)); - ok = logadd(&logbuf, ",\"type\":\"bat[:%s]\"", tname); - GDKfree(tname); - if (!ok) { - if (d) - BBPunfix(d->batCacheid); - goto cleanup_and_exit; + c =getVarName(mb, getArg(pci,j)); + if(getVarSTC(mb,getArg(pci,j))){ + InstrPtr stc = getInstrPtr(mb, getVarSTC(mb,getArg(pci,j))); + if (stc && getModuleId(stc) && + strcmp(getModuleId(stc),"sql") ==0 && + strncmp(getFunctionId(stc),"bind",4)==0 && + !logadd(&logbuf, ",\"alias\":\"%s.%s.%s\"", + getVarConstant(mb, getArg(stc,stc->retc +1)).val.sval, + getVarConstant(mb, getArg(stc,stc->retc +2)).val.sval, + getVarConstant(mb, getArg(stc,stc->retc +3)).val.sval)) + goto cleanup_and_exit; } - if(d) { - MT_lock_set(&d->theaplock); - BATiter di = bat_iterator_nolock(d); - /* outside the lock we cannot dereference di.h or di.vh, - * but we can use all values without dereference and - * without further locking */ - MT_lock_unset(&d->theaplock); - cnt = di.count; - if(isVIEW(d)){ - BAT *v= BBP_cache(VIEWtparent(d)); - bool vtransient = true; - if (v) { - MT_lock_set(&v->theaplock); - vtransient = v->batTransient; - MT_lock_unset(&v->theaplock); + if(isaBatType(tpe)){ + BAT *d= BATdescriptor(bid = stk->stk[getArg(pci,j)].val.bval); + tname = getTypeName(getBatType(tpe)); + ok = logadd(&logbuf, ",\"type\":\"bat[:%s]\"", tname); + GDKfree(tname); + if (!ok) { + if (d) + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + if(d) { + MT_lock_set(&d->theaplock); + BATiter di = bat_iterator_nolock(d); + /* outside the lock we cannot dereference di.h or di.vh, + * but we can use all values without dereference and + * without further locking */ + MT_lock_unset(&d->theaplock); + cnt = di.count; + if(isVIEW(d)){ + BAT *v= BBP_cache(VIEWtparent(d)); + bool vtransient = true; + if (v) { + MT_lock_set(&v->theaplock); + vtransient = v->batTransient; + MT_lock_unset(&v->theaplock); + } + if (!logadd(&logbuf, + ",\"view\":\"true\"" + ",\"parent\":%d" + ",\"seqbase\":"BUNFMT + ",\"mode\":\"%s\"", + VIEWtparent(d), + d->hseqbase, + vtransient ? "transient" : "persistent")) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + } else { + if (!logadd(&logbuf, ",\"mode\":\"%s\"", (di.transient ? "transient" : "persistent"))) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } } if (!logadd(&logbuf, - ",\"view\":\"true\"" - ",\"parent\":%d" - ",\"seqbase\":"BUNFMT - ",\"mode\":\"%s\"", - VIEWtparent(d), - d->hseqbase, - vtransient ? "transient" : "persistent")) { - BBPunfix(d->batCacheid); - goto cleanup_and_exit; - } - } else { - if (!logadd(&logbuf, ",\"mode\":\"%s\"", (di.transient ? "transient" : "persistent"))) { + ",\"sorted\":%d" + ",\"revsorted\":%d" + ",\"nonil\":%d" + ",\"nil\":%d" + ",\"key\":%d", + di.sorted, + di.revsorted, + di.nonil, + di.nil, + di.key)) { BBPunfix(d->batCacheid); goto cleanup_and_exit; } + if ((di.minpos != BUN_NONE && + !logadd(&logbuf, ",\"minpos\":\""BUNFMT"\"", di.minpos)) || + (di.maxpos != BUN_NONE && + !logadd(&logbuf, ",\"maxpos\":\""BUNFMT"\"", di.maxpos)) || + (di.unique_est != 0 && + !logadd(&logbuf, ",\"nestimate\":\"%g\"", di.unique_est))) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + + cv = VALformat(&stk->stk[getArg(pci,j)]); + c = strchr(cv, '>'); + if (c) /* unlikely that this isn't true */ + *c = 0; + ok = logadd(&logbuf, ",\"file\":\"%s\"", cv + 1); + GDKfree(cv); + if (!ok) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + total += cnt << di.shift; + if (!logadd(&logbuf, ",\"width\":%d", di.width)) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + /* keeping information about the individual auxiliary heaps is helpful during analysis. */ + MT_rwlock_rdlock(&d->thashlock); + if( d->thash && !logadd(&logbuf, ",\"hash\":" LLFMT, (lng) hashinfo(d->thash, d->batCacheid))) { + MT_rwlock_rdunlock(&d->thashlock); + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + MT_rwlock_rdunlock(&d->thashlock); + if( di.vh && !logadd(&logbuf, ",\"vheap\":" BUNFMT, di.vhfree)) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + if( d->timprints && !logadd(&logbuf, ",\"imprints\":" LLFMT, (lng) IMPSimprintsize(d))) { + BBPunfix(d->batCacheid); + goto cleanup_and_exit; + } + /* if (!logadd(&logbuf, "\"debug\":\"%s\",", d->debugmessages)) goto cleanup_and_exit; */ + BBPunfix(d->batCacheid); } if (!logadd(&logbuf, - ",\"sorted\":%d" - ",\"revsorted\":%d" - ",\"nonil\":%d" - ",\"nil\":%d" - ",\"key\":%d", - di.sorted, - di.revsorted, - di.nonil, - di.nil, - di.key)) { - BBPunfix(d->batCacheid); - goto cleanup_and_exit; - } - if ((di.minpos != BUN_NONE && - !logadd(&logbuf, ",\"minpos\":\""BUNFMT"\"", di.minpos)) || - (di.maxpos != BUN_NONE && - !logadd(&logbuf, ",\"maxpos\":\""BUNFMT"\"", di.maxpos)) || - (di.unique_est != 0 && - !logadd(&logbuf, ",\"nestimate\":\"%g\"", di.unique_est))) { _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org