Changeset: 7a16fbce6a1c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7a16fbce6a1c
Added Files:
monetdb5/modules/mal/sysmon.mal
sql/scripts/26_sysmon.sql
Modified Files:
monetdb5/mal/mal_instruction.c
monetdb5/mal/mal_instruction.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_runtime.c
monetdb5/mal/mal_runtime.h
monetdb5/modules/mal/Makefile.ag
monetdb5/modules/mal/mal_init.mal
sql/backends/monet5/sql.mx
sql/backends/monet5/sql_gencode.c
sql/scripts/Makefile.ag
sql/test/BugDay_2005-10-06_2.8/Tests/MapiClient-dump.SF-905851.stable.out
sql/test/BugTracker-2009/Tests/mclient-lsql-D.stable.out
sql/test/BugTracker-2009/Tests/name_clash_with_dump.SF-2780395.stable.out
sql/test/BugTracker-2011/Tests/interrupted-initialization.Bug-2875.stable.out
sql/test/BugTracker-2012/Tests/rewrite_like_into_likesubselect.Bug-3179.stable.out
sql/test/BugTracker/Tests/explain.SF-1739353.stable.out
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.stable.out
sql/test/BugTracker/Tests/multi-column-constraint.SF-1964587.stable.out
sql/test/Dump/Tests/dump-empty.stable.out
sql/test/Dump/Tests/dump.stable.out
sql/test/Tests/systemfunctions.stable.out
sql/test/UserDump/Tests/create.stable.out
sql/test/bugs/Tests/groupby_having_charlength-bug-sf-943566.stable.out
sql/test/testdb/Tests/testdb-dump.stable.out
Branch: default
Log Message:
Introduction of the sysmon functions
A queue is maintained with the running SQL queries.
It can be inspected using sysmon.queue().
It will also be extended with options to pause/resume/stop queries
More testing required.
diffs (truncated from 1055 to 300 lines):
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
@@ -130,7 +130,8 @@ newMalBlk(int maxvars, int maxstmts)
mb->recycle = 0;
mb->recid = 0;
mb->trap = 0;
- mb->starttime = 0;
+ mb->runtime = 0;
+ mb->calls = 0;
if (newMalBlkStmt(mb, maxstmts) < 0)
return NULL;
return mb;
@@ -242,6 +243,8 @@ copyMalBlk(MalBlkPtr old)
mb->recycle = old->recycle;
mb->recid = old->recid;
mb->trap = old->trap;
+ mb->runtime = old->runtime;
+ mb->calls = old->calls;
mb->replica = old->replica;
mb->maxarg = old->maxarg;
mb->profiler = NULL;
diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h
--- a/monetdb5/mal/mal_instruction.h
+++ b/monetdb5/mal/mal_instruction.h
@@ -143,7 +143,8 @@ typedef struct MALBLK {
lng recid; /* ID given by recycler
optimizer */
lng legid;
sht trap; /* call debugger when
called */
- lng starttime; /* track when the query
started, for resource management */
+ lng runtime; /* average execution
time of block in ticks */
+ int calls; /* number of calls */
} *MalBlkPtr, MalBlkRecord;
/* Allocation of space assumes a rather exotic number of
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
@@ -280,7 +280,7 @@ str malCommandCall(MalStkPtr stk, InstrP
lhs->val.pval = 0;\
lhs->len = 0;\
}\
- }\
+ }
int
isNotUsedIn(InstrPtr p, int start, int a)
@@ -319,7 +319,7 @@ str runMAL(Client cntxt, MalBlkPtr mb, M
RuntimeProfileRecord runtimeProfile;
(void) mbcaller;
- runtimeProfileInit(mb, &runtimeProfile, cntxt->flags & memoryFlag);
+ runtimeProfileInit(cntxt, mb, &runtimeProfile, cntxt->flags &
memoryFlag);
if (mb->errors) {
if (cntxt->itrace == 0) /* permit debugger analysis */
throw( MAL, "mal.interpreter", "Syntax error in
script");
@@ -383,8 +383,10 @@ str runMAL(Client cntxt, MalBlkPtr mb, M
env->cmd = stk->cmd;
if (!stk->keepAlive && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, env != stk);
- if (stk && stk != env)
+ if (stk && stk != env) {
+ runtimeProfileFinish(cntxt, mb, &runtimeProfile);
GDKfree(stk);
+ }
if (cntxt->qtimeout && time(NULL) - stk->clock.tv_usec >
cntxt->qtimeout)
throw(MAL, "mal.interpreter", RUNTIME_QRY_TIMEOUT);
return ret;
@@ -439,7 +441,7 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
* number of cores, which may be too coarse.
*/
MT_sema_down(&mal_parallelism,"callMAL");
- runtimeProfileInit(mb, &runtimeProfile, cntxt->flags & memoryFlag);
+ runtimeProfileInit(cntxt, mb, &runtimeProfile, cntxt->flags &
memoryFlag);
#ifdef DEBUG_CALLMAL
mnstr_printf(cntxt->fdout, "callMAL\n");
printInstruction(cntxt->fdout, mb, 0, pci, LIST_MAL_ALL);
@@ -483,6 +485,7 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
MT_sema_up(&mal_parallelism,"callMAL");
if (cntxt->qtimeout && time(NULL) - stk->clock.tv_usec >
cntxt->qtimeout)
throw(MAL, "mal.interpreter", RUNTIME_QRY_TIMEOUT);
+ runtimeProfileFinish(cntxt, mb, &runtimeProfile);
return ret;
}
@@ -511,7 +514,7 @@ str runMALsequence(Client cntxt, MalBlkP
//int tid = 0;
RuntimeProfileRecord runtimeProfile, runtimeProfileFunction;
- runtimeProfileInit(mb, &runtimeProfile, cntxt->flags & memoryFlag);
+ runtimeProfileInit(cntxt, mb, &runtimeProfile, cntxt->flags &
memoryFlag);
if (stk == NULL)
throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
if (cntxt->flags & timerFlag)
@@ -528,10 +531,8 @@ str runMALsequence(Client cntxt, MalBlkP
}
/* also produce event record for start of function */
- if ( startpc == 1 ) {
- runtimeProfileInit(mb, &runtimeProfileFunction, cntxt->flags &
memoryFlag);
- mb->starttime = GDKusec();
- }
+ if ( startpc == 1 )
+ runtimeProfileInit(cntxt, mb, &runtimeProfileFunction,
cntxt->flags & memoryFlag);
stkpc = startpc;
exceptionVar = -1;
@@ -560,9 +561,6 @@ str runMALsequence(Client cntxt, MalBlkP
}
}
- //Ensure we spread system resources over multiple users as well.
- //if ( cntxt->idx > 1 )
- //MALresourceFairness(cntxt,mb,GDKusec()-
mb->starttime);
runtimeProfileBegin(cntxt, mb, stk, stkpc, &runtimeProfile, 1);
if (pci->recycle > 0)
stk->clk = GDKusec();
@@ -730,6 +728,7 @@ str runMALsequence(Client cntxt, MalBlkP
if (oldtimer)
cntxt->timer = oldtimer;
runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
+ runtimeProfileFinish(cntxt, mb,
&runtimeProfile);
if (pcicaller && garbageControl(getInstrPtr(mb,
0)))
garbageCollector(cntxt, mb, stk, TRUE);
runtimeProfile.ppc = 0; /* also finalize
function call event */
@@ -883,6 +882,7 @@ str runMALsequence(Client cntxt, MalBlkP
/* unknown exceptions lead to propagation */
if (exceptionVar == -1) {
runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
+ runtimeProfileFinish(cntxt, mb,
&runtimeProfile);
if (cntxt->qtimeout && time(NULL) -
stk->clock.tv_usec > cntxt->qtimeout)
ret= createException(MAL,
"mal.interpreter", RUNTIME_QRY_TIMEOUT);
stkpc = mb->stop;
@@ -1117,6 +1117,7 @@ str runMALsequence(Client cntxt, MalBlkP
if (stkpc == mb->stop) {
runtimeProfile.ppc = 0; /* also finalize
function call event */
runtimeProfileExit(cntxt, mb, stk, pci,
&runtimeProfile);
+ runtimeProfileFinish(cntxt, mb,
&runtimeProfile);
break;
}
if (stkpc == mb->stop)
@@ -1152,6 +1153,7 @@ str runMALsequence(Client cntxt, MalBlkP
/* reset the clock */
if (oldtimer)
cntxt->timer = oldtimer;
+ runtimeProfileFinish(cntxt, mb,
&runtimeProfile);
}
}
stkpc = mb->stop;
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
@@ -2,7 +2,7 @@
* The contents of this file are subject to the MonetDB Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
- * http://www.monetdb.org/Legal/MonetDBLicense
+ * http://www.monetdbuorg/Legal/MonetDBtxtLicense
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@@ -25,23 +25,78 @@
#include "monetdb_config.h"
#include "mal_utils.h"
#include "mal_runtime.h"
+#include "mal_interpreter.h"
#include "mal_function.h"
#include "mal_profiler.h"
#include "mal_listing.h"
+#include "mal_authorize.h"
#define heapinfo(X) ((X) && (X)->base ? (X)->free: 0)
#define hashinfo(X) (((X) && (X)->mask)? ((X)->mask + (X)->lim + 1) *
sizeof(int) + sizeof(*(X)) + cnt * sizeof(int): 0)
+
+// Keep a queue of running queries
+struct RUN {
+ Client cntxt;
+ MalBlkPtr mb;
+ lng tag;
+ str query;
+ str status;
+ lng start;
+ lng runtime;
+} *running;
+static int qtop, qsize;
+static int qtag;
+
+
+static str isaSQLquery(MalBlkPtr mb){
+ int i;
+ InstrPtr p;
+ if (mb)
+ for ( i = mb->stop-1 ; i > 0; i--){
+ p = getInstrPtr(mb,i);
+ if ( p->token == ENDsymbol)
+ break;
+ if ( getModuleId(p) && idcmp(getModuleId(p), "querylog") == 0
&& idcmp(getFunctionId(p),"define")==0)
+ return getVarConstant(mb,getArg(p,2)).val.sval;
+ }
+ return 0;
+}
+
/*
* Manage the runtime profiling information
*/
void
-runtimeProfileInit(MalBlkPtr mb, RuntimeProfile prof, int initmemory)
+runtimeProfileInit(Client cntxt, MalBlkPtr mb, RuntimeProfile prof, int
initmemory)
{
+ int i;
+ str q;
+
+ MT_lock_set(&mal_delayLock, "sysmon");
+ if ( running == 0)
+ running = (struct RUN *) GDKzalloc( sizeof (struct RUN) *
(qsize= 256));
+ else
+ if ( qtop +1 == qsize )
+ running = (struct RUN *) GDKrealloc( running, sizeof (struct
RUN) * (qsize +=256));
+ for( i = 0; i < qtop; i++)
+ if ( running[i].mb == mb)
+ break;
+
prof->newclk = 0;
prof->ppc = -2;
prof->tcs = 0;
prof->inblock = 0;
prof->oublock = 0;
+
+ if ( i == qtop ) {
+ running[i].mb = mb; // for detecting duplicates
+ running[i].tag = qtag++;
+ running[i].start = GDKusec();
+ running[i].runtime = mb->runtime;
+ q = isaSQLquery(mb);
+ running[i].query = q? GDKstrdup(q):0;
+ running[i].status = "running";
+ running[i].cntxt = cntxt;
+ }
if (initmemory)
prof->memory = MT_mallinfo();
else
@@ -50,6 +105,38 @@ runtimeProfileInit(MalBlkPtr mb, Runtime
setFilterOnBlock(mb, 0, 0);
prof->ppc = -1;
}
+
+ qtop += i == qtop;
+ MT_lock_unset(&mal_delayLock, "sysmon");
+
+}
+
+void
+runtimeProfileFinish(Client cntxt, MalBlkPtr mb, RuntimeProfile prof)
+{
+ int i,j;
+
+ (void) cntxt;
+ (void) prof;
+
+
+ MT_lock_set(&mal_delayLock, "sysmon");
+ for( i=j=0; i< qtop; i++)
+ if ( running[i].mb != mb)
+ running[j++] = running[i];
+ else {
+ if (running[i].query)
+ GDKfree(running[i].query);
+ running[i].cntxt = 0;
+ running[i].tag = 0;
+ running[i].query = 0;
+ running[i].status =0;
+ mb->calls++;
+ mb->runtime += ((GDKusec() - running[i].start)-
running[i].runtime)/mb->calls;
+ }
+
+ qtop = j;
+ MT_lock_unset(&mal_delayLock, "sysmon");
}
void
@@ -61,7 +148,7 @@ runtimeProfileBegin(Client cntxt, MalBlk
if (stk && mb->profiler != NULL) {
prof->newclk = stk->clk = GDKusec();
if (mb->profiler[stkpc].trace) {
- MT_lock_set(&mal_delayLock, "DFLOWdelay");
+ MT_lock_set(&mal_delayLock, "sysmon");
gettimeofday(&stk->clock, NULL);
prof->ppc = stkpc;
mb->profiler[stkpc].clk = 0;
@@ -75,7 +162,7 @@ runtimeProfileBegin(Client cntxt, MalBlk
mb->profiler[stkpc].timer = stk->timer;
#endif
mb->profiler[stkpc].clk = stk->clk;
- MT_lock_unset(&mal_delayLock, "DFLOWdelay");
+ MT_lock_unset(&mal_delayLock, "sysmon");
}
}
}
@@ -103,7 +190,7 @@ runtimeProfileExit(Client cntxt, MalBlkP
return; /* mostly true */
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list