Changeset: 5a758dd94a99 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5a758dd94a99
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.h
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        monetdb5/mal/mal_recycle.c
        monetdb5/mal/mal_runtime.c
        monetdb5/mal/mal_runtime.h
        monetdb5/mal/mal_session.c
        monetdb5/modules/mal/Tests/remote03.stable.out
        monetdb5/modules/mal/profiler.c
        monetdb5/modules/mal/trader.c
Branch: default
Log Message:

Inline the performance metrics
The basic performance metrics are moved to the instruction
record. This simplifies the code and avoids possible
mis-alignment of profiler stack and instruction stack.


diffs (truncated from 981 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
@@ -2476,7 +2476,6 @@ void initLibraries(void);
 void initMALstack(MalBlkPtr mb, MalStkPtr stk);
 void initNamespace(void);
 void initParser(void);
-void initProfiler(MalBlkPtr mb);
 int initQlog(void);
 int inlineMALblock(MalBlkPtr mb, int pc, MalBlkPtr mc);
 int inlineProp;
@@ -2717,7 +2716,7 @@ void printSignature(stream *fd, Symbol s
 void printStack(stream *f, MalBlkPtr mb, MalStkPtr s);
 str prodRef;
 int profilerAvailable(void);
-void profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, int pc, int start);
+void profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int 
start);
 void profilerGetCPUStat(lng *user, lng *nice, lng *sys, lng *idle, lng 
*iowait);
 void profilerHeartbeatEvent(str msg, lng ticks);
 str profilerRef;
@@ -2795,7 +2794,7 @@ str runMALdataflow(Client cntxt, MalBlkP
 str runMALsequence(Client cntxt, MalBlkPtr mb, int startpc, int stoppc, 
MalStkPtr stk, MalStkPtr env, InstrPtr pcicaller);
 str runScenario(Client c);
 int runonceProp;
-void runtimeProfileBegin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, int stkpc, 
RuntimeProfile prof, int start);
+void runtimeProfileBegin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, RuntimeProfile prof);
 void runtimeProfileExit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, RuntimeProfile prof);
 void runtimeProfileFinish(Client cntxt, MalBlkPtr mb);
 void runtimeProfileInit(Client cntxt, MalBlkPtr mb, MalStkPtr stk);
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -166,6 +166,11 @@ typedef struct VARRECORD {
        int prps[];                                     /* property array */
 } *VarPtr, VarRecord;
 
+/* For performance analysis we keep track of the number of calls and
+ * the total time spent while executing the instruction. (See
+ * mal_profiler.mx) 
+ */
+
 typedef struct {
        bit token;                                      /* instruction type */
        bit barrier;                            /* flow of control modifier 
takes:
@@ -178,32 +183,18 @@ typedef struct {
        int jump;                                       /* controlflow program 
counter */
        MALfcn fcn;                                     /* resolved function 
address */
        struct MALBLK *blk;                     /* resolved MAL function 
address */
+       /* inline statistics */
+       bit trace;
+       int calls;                                      /* number of calls made 
*/
+       lng ticks;                                      /* total micro seconds 
spent */
+       lng rbytes,wbytes;                      /* accumulated number of bytes 
touched */
+       /* the core admin */
        str modname;                            /* module context */
        str fcnname;                            /* function name */
        int argc, retc, maxarg;         /* total and result argument count */
        int argv[];                                     /* at least a few 
entries */
 } *InstrPtr, InstrRecord;
 
-/* For performance analysis we keep track of the number of calls and
- * the total time spent while executing the instruction. (See
- * mal_profiler.mx) The performance structures are separately
- * administered, because they are only used in limited
- * curcumstances. */
-
-typedef struct PERF {
-#ifdef HAVE_TIMES
-       struct tms timer;                       /* timing information */
-#endif
-       struct timeval clock;           /* clock */
-       lng clk;                                        /* time when 
instruction started */
-       lng ticks;                                      /* micro seconds spent 
on last call */
-       lng totalticks;                         /* accumulate micro seconds 
send on this instruction */
-       int calls;                                      /* number of calls seen 
*/
-       bit trace;                                      /* facilitate 
filter-based profiling */
-       lng rbytes;                                     /* bytes read by an 
instruction */
-       lng wbytes;                                     /* bytes written by an 
instruction */
-} *ProfPtr, ProfRecord;
-
 typedef struct MALBLK {
        str binding;                            /* related C-function */
        str help;                                       /* supportive 
commentary */
@@ -221,7 +212,6 @@ typedef struct MALBLK {
        int errors;                                     /* left over errors */
        int typefixed;                          /* no undetermined instruction 
*/
        int flowfixed;                          /* all flow instructions are 
fixed */
-       ProfPtr profiler;
        struct MALBLK *history;         /* of optimizer actions */
        short keephistory;                      /* do we need the history at 
all */
        short dotfile;                          /* send dot file to 
stethoscope? */
diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -91,13 +91,6 @@ newMalBlkStmt(MalBlkPtr mb, int maxstmts
        mb->stmt = p;
        mb->stop = 0;
        mb->ssize = maxstmts;
-    if (mb->profiler){
-        mb->profiler = (ProfPtr) GDKrealloc(mb->profiler, (mb->ssize ) * 
sizeof(ProfRecord));
-               if( mb->profiler == 0){
-                       GDKerror("newMalBlk:" MAL_MALLOC_FAIL);
-                       return -1;
-               }
-       }
        mb->recid = recycleSeq++;
        return 0;
 }
@@ -140,7 +133,6 @@ newMalBlk(int maxvars, int maxstmts)
        mb->maxarg = MAXARG;            /* the minimum for each instruction */
        mb->typefixed = 0;
        mb->flowfixed = 0;
-       mb->profiler = NULL;
        mb->ptop = mb->psize = 0;
        mb->prps = NULL;
        mb->replica = NULL;
@@ -178,12 +170,6 @@ resizeMalBlk(MalBlkPtr mb, int maxstmt, 
        for( i = mb->vsize; i < maxvar; i++)
                mb->var[i] = 0;
        mb->vsize = maxvar;
-
-       if ( mb->profiler){
-               mb->profiler = (ProfRecord *) GDKrealloc(mb->profiler, maxstmt 
* sizeof(ProfRecord));
-               if (mb->profiler == NULL)
-                       GDKerror("resizeMalBlk:" MAL_MALLOC_FAIL);
-       }
 }
 /* The resetMalBlk code removes instructions, but without freeing the
  * space. This way the structure is prepared for re-use */
@@ -230,9 +216,6 @@ freeMalBlk(MalBlkPtr mb)
        if (mb->help)
                GDKfree(mb->help);
        mb->help = 0;
-       if (mb->profiler)
-               GDKfree(mb->profiler);
-       mb->profiler = NULL;
        GDKfree(mb);
 }
 
@@ -303,7 +286,6 @@ copyMalBlk(MalBlkPtr old)
        mb->optimize = old->optimize;
        mb->replica = old->replica;
        mb->maxarg = old->maxarg;
-       mb->profiler = NULL;
 
        mb->ptop = mb->psize = 0;
        mb->prps = NULL;
@@ -424,10 +406,6 @@ trimexpand(MalBlkPtr mb, int varsize, in
        mb->stmt = stmt;
 
        mb->ssize = mb->ssize + stmtsize;
-       if (mb->profiler) {
-               GDKfree(mb->profiler);
-               mb->profiler = 0;
-       }
 }
 
 void
@@ -593,11 +571,8 @@ removeInstruction(MalBlkPtr mb, InstrPtr
        if (i == mb->stop)
                return;
 
-       for (; i < mb->stop - 1; i++) {
+       for (; i < mb->stop - 1; i++) 
                mb->stmt[i] = mb->stmt[i + 1];
-               if (mb->profiler)
-                       mb->profiler[i] = mb->profiler[i + 1];
-       }
        mb->stmt[i] = 0;
        mb->stop--;
        assert(i == mb->stop);
@@ -1792,31 +1767,12 @@ pushInstruction(MalBlkPtr mb, InstrPtr p
                        return;
                }
                memcpy(newblk, mb->stmt, mb->ssize * sizeof(InstrPtr));
-
-               /* also extend the storage space for the profiler */
-               /* left to the environment */
-               if (mb->profiler) {
-                       ProfPtr old = mb->profiler;
-                       int osize = mb->ssize;
-                       mb->profiler = (ProfPtr) GDKzalloc((mb->ssize + 
STMT_INCREMENT) * sizeof(ProfRecord));
-                       if ( mb->profiler == NULL){
-                               mb->errors++;
-                               showException(GDKout, MAL, "pushInstruction", 
MAL_MALLOC_FAIL);
-                               return;
-                       }
-                       memcpy((char *) mb->profiler, (char *) old, 
sizeof(ProfRecord) * osize);
-                       GDKfree(old);
-               }
                mb->ssize += STMT_INCREMENT;
                GDKfree(mb->stmt);
                mb->stmt = newblk;
        }
        /* If the destination variable has not been set, introduce a
         * temporary variable to hold the result instead. */
-/*
-       if (p->argv[0] < 0)
-               p->argv[0] = newTmpVariable(mb, TYPE_any);
-*/
        assert(p->argc == 0 || p->argv[0] >= 0);
        if (mb->stmt[i]) {
                /* if( getModuleId(mb->stmt[i] ) )
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -505,7 +505,7 @@ str runMALsequence(Client cntxt, MalBlkP
        int garbages[16], *garbage;
        int stkpc = 0;
        RuntimeProfileRecord runtimeProfile, runtimeProfileFunction;
-       runtimeProfile.stkpc = runtimeProfileFunction.stkpc = 0;
+       runtimeProfile.ticks = runtimeProfileFunction.ticks = 0;
 
        if (stk == NULL)
                throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
@@ -533,7 +533,7 @@ str runMALsequence(Client cntxt, MalBlkP
        /* also produce event record for start of function */
        if ( startpc == 1 ){
                runtimeProfileInit(cntxt, mb, stk);
-               runtimeProfileBegin(cntxt, mb, stk, 0, &runtimeProfileFunction, 
1);
+               runtimeProfileBegin(cntxt, mb, stk, NULL, 
&runtimeProfileFunction);
                mb->starttime = GDKusec();
                if (cntxt->stimeout && cntxt->session && GDKusec()- 
cntxt->session > cntxt->stimeout)
                        throw(MAL, "mal.interpreter", RUNTIME_SESSION_TIMEOUT);
@@ -569,7 +569,7 @@ str runMALsequence(Client cntxt, MalBlkP
                }
 
                //Ensure we spread system resources over multiple users as well.
-               runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 1);
+               runtimeProfileBegin(cntxt, mb, stk, pci, &runtimeProfile);
         if (!RECYCLEentry(cntxt, mb, stk, pci,&runtimeProfile)){
                        /* The interpreter loop
                         * The interpreter is geared towards execution a MAL
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
@@ -55,8 +55,8 @@ profilerAvailable(void)
 {
        return 1;
 }
-static void offlineProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, int pc, 
int start);
-static void cachedProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, int pc);
+static void offlineProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pc, int start);
+static void cachedProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pc);
 static int initTrace(void);
 static void startHeartbeat(int delay);
 
@@ -238,11 +238,11 @@ static void logsend(char *logbuffer)
  * Note that the profiler itself should lead to event generations.
  */
 void
-profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, int pc, int start)
+profilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int start)
 {
-       InstrPtr p;
-       if (mb->profiler == NULL) return;
-       if (profileCounter[PROFdot].status == 1 && start && pc == 0){
+       if (stk == NULL) return;
+       if (pci == NULL) return;
+       if (profileCounter[PROFdot].status == 1 && start && pci == NULL){
                if (mb->dotfile == 0){
                        MT_lock_set(&mal_profileLock, "profilerEvent");
                        showFlowGraph(mb,stk,"stethoscope");
@@ -251,17 +251,16 @@ profilerEvent(int idx, MalBlkPtr mb, Mal
        }
        if (profileCounter[PROFstart].status == 0 && start)
                return;
-       p = getInstrPtr(mb,pc);
-       if ( !start && p && p->token == ENDsymbol)
+       if ( !start && pci && pci->token == ENDsymbol)
                profilerHeartbeatEvent("ping", 0);
        if (myname == 0)
                myname = putName("profiler", 8);
-       if (getModuleId(getInstrPtr(mb, pc)) == myname)
+       if (getModuleId(pci) == myname)
                return;
        if (offlineProfiling)
-               offlineProfilerEvent(idx, mb, stk, pc,start);
+               offlineProfilerEvent(idx, mb, stk, pci,start);
        if (cachedProfiling && !start)
-               cachedProfilerEvent(idx, mb, stk, pc);
+               cachedProfilerEvent(idx, mb, stk, pci);
 }
 
 static void
@@ -349,12 +348,14 @@ offlineProfilerHeader(void)
 }
 
 void
-offlineProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, int pc, int start)
+offlineProfilerEvent(int idx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int 
start)
 {
        char logbuffer[LOGLEN], *logbase;
        int loglen;
+       char ctm[26];
+       time_t clk;
+       struct timeval clock;
        /*static struct Mallinfo prevMalloc;*/
-       InstrPtr pci = getInstrPtr(mb, pc);
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to