Changeset: 34f447dbf911 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/34f447dbf911
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: Jul2021_prof_ext
Log Message:

Add minimal profiler mode feature.


diffs (truncated from 823 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
@@ -1101,7 +1101,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
@@ -181,7 +181,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);
 }
 
@@ -203,7 +205,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
@@ -449,15 +449,33 @@ 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");
-        }
+                       q_enqueue(flow->done, fe);
+                       if ( fnxt == 0 && profilerStatus) {
+                               profilerHeartbeatEvent("wait");
+                       }
+               }
+               MT_lock_set(&dataflowLock);
+               if (GDKexiting() || ATOMIC_GET(&exiting)) {
+                       MT_lock_unset(&dataflowLock);
+                       break;
+               }
+               if (free_count >= free_max) {
+                       t->flag = EXITED;
+                       t->next = exited_workers;
+                       exited_workers = t->self;
+                       MT_lock_unset(&dataflowLock);
+                       break;
+               }
+               free_count++;
+               t->flag = FREE;
+               assert(free_workers != t->self);
+               t->next = free_workers;
+               free_workers = t->self;
+               MT_lock_unset(&dataflowLock);
+               MT_sema_down(&t->s);
+               if (GDKexiting() || ATOMIC_GET(&exiting))
+                       break;
+               assert(t->flag == WAITING);
        }
        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
@@ -39,8 +39,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;
 
@@ -279,8 +280,12 @@ 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)
-               return;
+       if(profilerUser!= MAL_ADMIN && profilerUser != cntxt->user)
+               return NULL;
+
+       /* align the variable namings with EXPLAIN and TRACE */
+       if(pci->pc == 1)
+               renameVariables(mb);
 
        logbuf = (struct logbuf) {0};
 
@@ -322,160 +327,173 @@ prepareMalEvent(Client cntxt, MalBlkPtr 
        if (mb && pci->modname && pci->fcnname) {
                int j;
 
-               if (!logadd(&logbuf, ",\"args\":["))
-                       return;
-               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 (profilerMode == 0) {
+                       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, "{"))
-                                       return;
-                       }
-                       else {
-                               if (!logadd(&logbuf, ",{"))
-                                       return;
-                       }
-                       if (!logadd(&logbuf, "\"%s\":%d,\"var\":\"%s\"",
-                                               j < pci->retc ? "ret" : "arg", 
j,
-                                               getVarName(mb, getArg(pci,j))))
-                               return;
-                       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))
-                                       return;
-                       }
-                       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);
-                                       return;
+                               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;
+                               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) {
-                                       BAT *v;
-                                       cnt = BATcount(d);
-                                       if(isVIEW(d)){
-                                               v= BBP_cache(VIEWtparent(d));
+                               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,
-                                                                       v && 
!v->batTransient ? "persistent" : "transient")) {
-                                                                               
BBPunfix(d->batCacheid);
-                                                                               
return;
+                                                                       
",\"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;
                                                }
-                                       } else {
-                                               if (!logadd(&logbuf, 
",\"mode\":\"%s\"", (d->batTransient ? "transient" : "persistent"))) {
+
+                                               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)) {
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to