Changeset: 57b414974b08 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=57b414974b08
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_listing.h
        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
        monetdb5/optimizer/opt_prelude.c
        monetdb5/optimizer/opt_prelude.h
        tools/mserver/mserver5.c
Branch: profiler
Log Message:

Profiler_logs director
The profiler upon requests maintains a cache of trace profiles.
One file per query. It will be the bases for the other tools,
e.g. tachograph.js


diffs (truncated from 656 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
@@ -1186,12 +1186,11 @@ str CMDsetHeartbeat(void *res, int *ev);
 str CMDsetProfilerFile(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 str CMDsetProfilerStream(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 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(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 CMDtachograph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 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);
@@ -1688,6 +1687,7 @@ int OPTmultiplexImplementation(Client cn
 str OPTmultiplexSimple(Client cntxt);
 str OPTorcam(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
 int OPTorcamImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
p);
+int OPTprofilerImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 int OPTpushselectImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 int OPTquerylogImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 int OPTrecyclerImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
@@ -1720,6 +1720,7 @@ str PCREquote(str *r, const str *v);
 str PCREreplace_bat_wrap(bat *res, const bat *or, const str *pat, const str 
*repl, const str *flags);
 str PCREreplace_wrap(str *res, const str *or, const str *pat, const str *repl, 
const str *flags);
 str PCREsql2pcre(str *ret, const str *pat, const str *esc);
+str PROFclearcache(void);
 sht PropertyIndex(str name);
 str PropertyName(sht idx);
 prop_op_t PropertyOperator(str s);
@@ -2458,9 +2459,9 @@ int mnstr_writeInt_wrap(Stream *S, int *
 str mnstr_writeIntwrap(void *ret, Stream *S, int *data);
 int mnstr_write_string(Stream *S, str data);
 str mnstr_write_stringwrap(void *ret, Stream *S, str *data);
-char monet_characteristics[PATHLENGTH];
 char monet_cwd[PATHLENGTH];
 size_t monet_memory;
+char monetdb_characteristics[PATHLENGTH];
 void moveInstruction(MalBlkPtr mb, int pc, int target);
 int mtProp;
 str mtimeRef;
@@ -2621,6 +2622,7 @@ void runtimeProfileInit(Client cntxt, Ma
 str safeguardStack(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
 int safetyBarrier(InstrPtr p, InstrPtr q);
 str schedulerRef;
+int schematablecolumnProp;
 str selectNotNilRef;
 str semaRef;
 str seriesRef;
@@ -2641,6 +2643,7 @@ str setStartPoint(Module cntxt, const ch
 void setVarName(MalBlkPtr mb, int i, str nme);
 void setVarType(MalBlkPtr mb, int i, int tpe);
 str setWriteModeRef;
+str shortStmtRendering(MalBlkPtr mb, MalStkPtr stl, InstrPtr p);
 void showAllScenarios(stream *f);
 void showCurrentScenario(void);
 void showErrors(Client cntxt);
@@ -2671,8 +2674,10 @@ int sqlfunctionProp;
 str srvpoolRef;
 int stableProp;
 str startProfiler(oid user, int mode, int beat);
+str startProfilerCache(void);
 str startRef;
 str stopProfiler(void);
+str stopProfilerCache(void);
 str stopRef;
 void strAfterCall(ValPtr v, ValPtr bak);
 void strBeforeCall(ValPtr v, ValPtr bak);
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -237,6 +237,7 @@ instruction2str(MalBlkPtr mb, MalStkPtr 
        base = s = GDKmalloc(len);
        if ( s == NULL)
                return s;
+       *s =0;
        if (flg) {
                if( p->token<0){
                        s[0] = '#';
@@ -383,12 +384,12 @@ instruction2str(MalBlkPtr mb, MalStkPtr 
  * should be shown as well.
  */
 static str
-beautyTerm(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int idx)
+shortRenderingTerm(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int idx)
 {
        str s, nme;
        BAT *b;
        ValRecord *val;
-       //VarPtr v;
+       VarPtr vr;
        char *cv =0;
        int varid = getArg(p,idx);
 
@@ -404,20 +405,25 @@ beautyTerm(MalBlkPtr mb, MalStkPtr stk, 
        } else {
                val = &stk->stk[varid];
                VALformat(&cv, val);
-               //v = varGetProp(mb, varid, PropertyIndex("schematablecolumn"));
-               nme = getVarName(mb, varid);
+               vr = varGetProp(mb, varid, PropertyIndex("schematablecolumn"));
+               if( vr) 
+                       nme = vr->value.val.sval;
+               else
+                       nme = getVarName(mb, varid);
                if ( isaBatType(getArgType(mb,p,idx))){
                        b = BBPquickdesc(abs(stk->stk[varid].val.ival),TRUE);
-                       snprintf(s,BUFSIZ,"%s["BUNFMT"]",nme, b?BATcount(b):0);
+                       snprintf(s,BUFSIZ,"%s["BUNFMT"]" ,nme, b?BATcount(b):0);
                } else
-                       snprintf(s,BUFSIZ,"%s",nme);
-               GDKfree(nme);
+               if( cv)
+                       snprintf(s,BUFSIZ,"%s=%s ",nme,cv);
+               else
+                       snprintf(s,BUFSIZ,"%s ",nme);
        }
        return s;
 }
 
 str
-instruction2beauty(MalBlkPtr mb, MalStkPtr stk,  InstrPtr p, int done)
+shortStmtRendering(MalBlkPtr mb, MalStkPtr stk,  InstrPtr p)
 {
        int i;
        str base, s, t, nme;
@@ -430,22 +436,41 @@ instruction2beauty(MalBlkPtr mb, MalStkP
        t=s;
        if (p->token == REMsymbol) 
                return base;
+       if (p->barrier == LEAVEsymbol || 
+               p->barrier == REDOsymbol || 
+               p->barrier == RETURNsymbol || 
+               p->barrier == YIELDsymbol || 
+               p->barrier == EXITsymbol || 
+               p->barrier == RAISEsymbol) {
+                       snprintf(t,(len-(t-base)), "%s ", 
operatorName(p->barrier));
+                       advance(t,base,len);
+               }
+       if( p->token == FUNCTIONsymbol) {
+                       snprintf(t,(len-(t-base)), "function %s.", 
getModuleId(p));
+                       advance(t,base,len);
+               }
+       if (p->token == ENDsymbol ){
+               snprintf(t,(len-(t-base)), "end %s.%s", 
getModuleId(getInstrPtr(mb,0)), getFunctionId(getInstrPtr(mb,0)));
+               return s;
+       }
        // handle the result variables
-       if( done ){
-               for (i = 0; i < p->retc; i++)
-                       if (!getVarTmp(mb, getArg(p, i)) || isVarUsed(mb, 
getArg(p, i)) || isVarUDFtype(mb,getArg(p,i)))
-                               break;
+       for (i = 0; i < p->retc; i++)
+               if (!getVarTmp(mb, getArg(p, i)) || isVarUsed(mb, getArg(p, i)) 
|| isVarUDFtype(mb,getArg(p,i)))
+                       break;
 
-               if (i == p->retc) // no result arguments
-                       goto beauty_end;
+       if (i == p->retc) // no result arguments
+               goto short_end;
 
-               /* display optional multi-assignment list */
-               if (p->retc > 1)
+       /* display optional multi-assignment list */
+       if( getArgType(mb,p,0) != TYPE_void){
+               if (p->retc > 1){
                        *t++ = '(';
+                       *t=0;
+               }
 
                for (i = 0; i < p->retc; i++) {
-                       nme = beautyTerm(mb, stk, p,i);
-                       snprintf(t,(len-(t-base)), "%s", nme);
+                       nme = shortRenderingTerm(mb, stk, p,i);
+                       snprintf(t,(len-(t-base)), "%s%s", (i?",":" "), nme);
                        GDKfree(nme);
                        advance(t,base,len);
                        if (i < p->retc - 1)
@@ -453,33 +478,33 @@ instruction2beauty(MalBlkPtr mb, MalStkP
                }
                if (p->retc > 1)
                        *t++ = ')';
+               *t++ = ':';
+               *t++ = '=';
+               *t++ = ' ';
+       }
+       *t =0;
 
-       }
-       beauty_end:
+       short_end:
+       advance(t,base,len);
+
        // handle the instruction mapping
-
-       advance(t,base,len);
-       nme = 0;
-       //nme = varGetPropStr(mb, getArg(p,0), PropertyIndex("beautyoperator"));
-       if( nme){
-               snprintf(t,  (len-(t-base)),"%s", nme);
-               GDKfree(nme);
-       } else 
-               snprintf(t,  (len-(t-base)),"%s.%s", getModuleId(p), 
getFunctionId(p));
+       snprintf(t,  (len-(t-base)),"%s", 
(getFunctionId(p)?getFunctionId(p):""));
        advance(t,base,len);
 
        // handle the arguments, constants should  be shown including their 
non-default type
        /* display optional multi-assignment list */
        *t++ = '(';
-       for (i = 0; i < p->retc; i++) {
-               nme = beautyTerm(mb, stk, p,i);
-               snprintf(t,(len-(t-base)), "%s", nme);
+       for (i = p->retc; i < p->argc; i++) {
+               nme = shortRenderingTerm(mb, stk, p,i);
+               snprintf(t,(len-(t-base)), "%c%s", (i!= p->retc? ',':' '), nme);
                GDKfree(nme);
                advance(t,base,len);
                if (i < p->retc - 1)
                        *t++ = ',';
        }
+       *t++ = ' ';
        *t++ = ')';
+       *t=0;
 
        if (t >= s + len)
                throw(MAL,"instruction2str:","instruction too long");
diff --git a/monetdb5/mal/mal_listing.h b/monetdb5/mal/mal_listing.h
--- a/monetdb5/mal/mal_listing.h
+++ b/monetdb5/mal/mal_listing.h
@@ -21,7 +21,7 @@ mal_export void printInstruction(stream 
 mal_export str instructionCall(MalBlkPtr mb, InstrPtr p, str s, str base, 
size_t len);
 mal_export void promptInstruction(stream *fd, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p, int flg);
 mal_export str instruction2str(MalBlkPtr mb, MalStkPtr stl, InstrPtr p, int 
hidden);
-mal_export str instruction2beauty(MalBlkPtr mb, MalStkPtr stl, InstrPtr p, int 
done);
+mal_export str shortStmtRendering(MalBlkPtr mb, MalStkPtr stl, InstrPtr p);
 mal_export str mal2str(MalBlkPtr mb, int first, int last);
 mal_export void showMalBlkHistory(stream *out, MalBlkPtr mb);
 
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
@@ -25,7 +25,7 @@ stream *eventstream = 0;
 
 static int offlineProfiling = FALSE;
 static int cachedProfiling = FALSE;
-static int jsonrendering = TRUE;
+static int jsonProfiling = TRUE;
 static str myname = 0;
 static oid user = 0;
 
@@ -42,6 +42,40 @@ struct rusage infoUsage;
 static struct rusage prevUsage;
 #endif
 
+/*
+ * Profiler trace cache
+ * The trace information for a limited collection of queries is retained in 
+ * a profiler cache, located in the database directory profiler_logs.
+ * It can be used for post-mortem analysis.
+ *
+ * The cache file is simply derived from the MAL block invocation tag,
+ * which is assured to be unique.
+ * 
+ * The JSON structures are sent to the file and upon request also to a 
listener.
+ */
+
+#define MAXJSONEVENTS (1<<16) /* cut off large JSON traces */
+#define MAXPROFILECACHE 64
+static struct{
+       int tag;
+       int cnt;        // number of events in this bucket
+       lng start,finish;
+       char fname[BUFSIZ];
+       stream *trace;
+       str query;
+} profilerCache[MAXPROFILECACHE];
+
+static int profilerCacheSize= MAXPROFILECACHE;
+
+str
+PROFclearcache(void)
+{
+       char buf[BUFSIZ];
+       snprintf(buf,BUFSIZ,"rm profiler_logs%c*.json",DIR_SEP);
+       system(buf);
+       return MAL_SUCCEED;
+}
+
 #define LOGLEN 8192
 #define lognew()  loglen = 0; logbase = logbuffer; *logbase = 0;
 
@@ -58,7 +92,7 @@ offlineProfilerHeader(void)
 
        if (eventstream == NULL) 
                return ;
-       if (jsonrendering) 
+       if (jsonProfiling) 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to