Changeset: 9487a5a71fa8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9487a5a71fa8
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_import.c
        monetdb5/mal/mal_interpreter.h
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_profiler.h
        monetdb5/mal/mal_runtime.c
        monetdb5/mal/mal_runtime.h
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_mvc.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: Jun2020_prof_ext
Log Message:

Patch with non-mal events for profiler.


diffs (truncated from 798 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
@@ -2172,6 +2172,7 @@ str fstrcmp_impl(dbl *ret, str *string1,
 void garbageCollector(Client cntxt, MalBlkPtr mb, MalStkPtr stk, int flag);
 void garbageElement(Client cntxt, ValPtr v);
 str generatorRef;
+void generic_event(str face, struct GenericEvent e, int state);
 MALfcn getAddress(str fcnname);
 str getArgDefault(MalBlkPtr mb, InstrPtr p, int idx);
 ptr getArgReference(MalStkPtr stk, InstrPtr pci, int k);
@@ -2538,6 +2539,7 @@ void runtimeProfileBegin(Client cntxt, M
 void runtimeProfileExit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci, RuntimeProfile prof);
 void runtimeProfileFinish(Client cntxt, MalBlkPtr mb, MalStkPtr stk);
 void runtimeProfileInit(Client cntxt, MalBlkPtr mb, MalStkPtr stk);
+oid runtimeProfileSetTag(Client cntxt);
 int safetyBarrier(InstrPtr p, InstrPtr q);
 str sampleRef;
 str schedulerRef;
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -45,6 +45,40 @@ MT_Lock     mal_copyLock = MT_LOCK_INITI
 MT_Lock     mal_delayLock = MT_LOCK_INITIALIZER("mal_delayLock");
 MT_Lock     mal_oltpLock = MT_LOCK_INITIALIZER("mal_oltpLock");
 
+static pthread_key_t tl_client_key;
+
+static int
+initialize_tl_client_key(void)
+{
+       static bool initialized = false;
+       if (initialized)
+               return 0;
+
+       if (pthread_key_create(&tl_client_key, NULL) != 0)
+               return -1;
+
+       initialized = true;
+       return 0;
+}
+
+Client
+getClientContext(void)
+{
+       return (Client) pthread_getspecific(tl_client_key);
+}
+
+/* declared in mal_private.h so only the MAL interpreter core can access it */
+Client
+setClientContext(Client cntxt)
+{
+       Client old = getClientContext();
+
+       if (pthread_setspecific(tl_client_key, cntxt) != 0)
+               GDKfatal("Failed to set thread local Client context");
+
+       return old;
+}
+
 /*
  * Initialization of the MAL context
  */
@@ -53,6 +87,9 @@ int mal_init(void){
 /* Any error encountered here terminates the process
  * with a message sent to stderr
  */
+       if (initialize_tl_client_key() != 0)
+               return -1;
+
        if (!MCinit())
                return -1;
 #ifndef NDEBUG
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
@@ -46,6 +46,7 @@
 #include "mal_private.h"
 #include "mal_runtime.h"
 #include "mal_authorize.h"
+#include "mal_profiler.h"
 #include "mapi_prompt.h"
 
 int MAL_MAXCLIENTS = 0;
@@ -199,6 +200,18 @@ MCexitClient(Client c)
                c->fdout = NULL;
                c->fdin = NULL;
        }
+
+       if(malProfileMode > 0)
+               generic_event("client_connection",
+                                         (struct GenericEvent)
+                                         { &c->idx,
+                                               NULL,
+                                               NULL,
+                                               NULL,
+                                               0 },
+                                         1);
+
+       setClientContext(NULL);
 }
 
 static Client
@@ -288,8 +301,21 @@ MCinitClient(oid user, bstream *fin, str
 
        MT_lock_set(&mal_contextLock);
        c = MCnewClient();
-       if (c)
+
+       if (c){
+               Client c_old = setClientContext(c);
+               assert(NULL == c_old);
                c = MCinitClientRecord(c, user, fin, fout);
+               if(malProfileMode > 0)
+                       generic_event("client_connection",
+                                                 (struct GenericEvent)
+                                                 { &c->idx,
+                                                       NULL,
+                                                       NULL,
+                                                       NULL,
+                                                       0 },
+                                                 0);
+       }
        MT_lock_unset(&mal_contextLock);
        return c;
 }
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -255,7 +255,7 @@ malInclude(Client c, str name, int listi
 str
 evalFile(str fname, int listing)
 {
-       Client c;
+       Client c, c_old;
        stream *fd;
        str filename;
        str msg = MAL_SUCCEED;
@@ -276,13 +276,15 @@ evalFile(str fname, int listing)
                        close_stream(fd);
                throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
-       c= MCinitClient(MAL_ADMIN, bs, 0);
+       c_old = setClientContext(NULL); // save context
+       c = MCinitClient(MAL_ADMIN, bs, 0);
        if( c == NULL){
                throw(MAL,"mal.eval","Can not create user context");
        }
        c->curmodule = c->usermodule = userModule();
        if(c->curmodule == NULL) {
                MCcloseClient(c);
+               setClientContext(c_old); // save context
                throw(MAL,"mal.eval",SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
        c->promptlength = 0;
@@ -290,15 +292,18 @@ evalFile(str fname, int listing)
 
        if ( (msg = defaultScenario(c)) ) {
                MCcloseClient(c);
+               setClientContext(c_old); // save context
                return msg;
        }
        if((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
                MCcloseClient(c);
+               setClientContext(c_old); // save context
                return msg;
        }
 
        msg = runScenario(c,0);
        MCcloseClient(c);
+       setClientContext(c_old); // save context
        return msg;
 }
 
@@ -322,7 +327,7 @@ mal_cmdline(char *s, size_t *len)
 str
 compileString(Symbol *fcn, Client cntxt, str s)
 {
-       Client c;
+       Client c, c_old;
        size_t len = strlen(s);
        buffer *b;
        str msg = MAL_SUCCEED;
@@ -361,6 +366,7 @@ compileString(Symbol *fcn, Client cntxt,
        }
        strncpy(fdin->buf, qry, len+1);
 
+       c_old = setClientContext(NULL); // save context
        // compile in context of called for
        c= MCinitClient(MAL_ADMIN, fdin, 0);
        if( c == NULL){
@@ -377,6 +383,7 @@ compileString(Symbol *fcn, Client cntxt,
                GDKfree(b);
                c->usermodule= 0;
                MCcloseClient(c);
+               setClientContext(c_old);
                return msg;
        }
 
@@ -391,6 +398,7 @@ compileString(Symbol *fcn, Client cntxt,
        c->usermodule= 0;
        /* restore IO channel */
        MCcloseClient(c);
+       setClientContext(c_old);
        GDKfree(qry);
        GDKfree(b);
        return msg;
@@ -399,7 +407,7 @@ compileString(Symbol *fcn, Client cntxt,
 str
 callString(Client cntxt, str s, int listing)
 {
-       Client c;
+       Client c, c_old;
        int i;
        size_t len = strlen(s);
        buffer *b;
@@ -429,7 +437,8 @@ callString(Client cntxt, str s, int list
                GDKfree(qry);
                throw(MAL,"callstring", SQLSTATE(HY013) MAL_MALLOC_FAIL);
        }
-       c= MCinitClient(MAL_ADMIN, bs, cntxt->fdout);
+       c_old = setClientContext(NULL);
+       c = MCinitClient(MAL_ADMIN, bs, cntxt->fdout);
        if( c == NULL){
                GDKfree(b);
                GDKfree(qry);
@@ -445,6 +454,7 @@ callString(Client cntxt, str s, int list
                GDKfree(b);
                GDKfree(qry);
                MCcloseClient(c);
+               setClientContext(c_old);
                return msg;
        }
 
@@ -454,6 +464,7 @@ callString(Client cntxt, str s, int list
                GDKfree(qry);
                c->fdout = GDKstdout;
                MCcloseClient(c);
+               setClientContext(c_old);
                return msg;
        }
        msg = runScenario(c,1);
@@ -463,6 +474,7 @@ callString(Client cntxt, str s, int list
                GDKfree(b);
                GDKfree(qry);
                MCcloseClient(c);
+               setClientContext(c_old);
                return msg;
        }
        // The command may have changed the environment of the calling client.
@@ -488,6 +500,7 @@ callString(Client cntxt, str s, int list
        bstream_destroy(c->fdin);
        c->fdin = 0;
        MCcloseClient(c);
+       setClientContext(c_old);
        GDKfree(qry);
        GDKfree(b);
        return msg;
diff --git a/monetdb5/mal/mal_interpreter.h b/monetdb5/mal/mal_interpreter.h
--- a/monetdb5/mal/mal_interpreter.h
+++ b/monetdb5/mal/mal_interpreter.h
@@ -33,6 +33,9 @@ mal_export void garbageCollector(Client 
 mal_export str malCommandCall(MalStkPtr stk, InstrPtr pci);
 mal_export int isNotUsedIn(InstrPtr p, int start, int a);
 
+/* defined in mal.c */
+mal_export Client getClientContext(void);
+
 mal_export ptr getArgReference(MalStkPtr stk, InstrPtr pci, int k);
 #if !defined(NDEBUG) && defined(__GNUC__)
 /* for ease of programming and debugging (assert reporting a useful
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -41,6 +41,9 @@ str yieldFactory(MalBlkPtr mb, InstrPtr 
        __attribute__((__visibility__("hidden")));
 str callFactory(Client cntxt, MalBlkPtr mb, ValPtr argv[],char flag)
        __attribute__((__visibility__("hidden")));
+
+Client setClientContext(Client cntxt)
+       __attribute__((__visibility__("hidden")));
 #endif
 
 str malAtomDefinition(str name,int tpe)
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
@@ -8,10 +8,11 @@
 
 /* (c) M.L. Kersten
  * Performance tracing
- * The stethoscope/tachograph and tomograph performance monitors have 
exclusive access
- * to a single event stream, which avoids concurrency conflicts amongst 
clients.
- * It also avoid cluthered event records on the stream. Since this event 
stream is owned
- * by a client, we should ensure that the profiler is automatically
+ * The stethoscope/tachograph and tomograph performance monitors have exclusive
+ * access to a single event stream, which avoids concurrency conflicts amongst
+ * clients.
+ * It also avoid cluthered event records on the stream. Since this event stream
+ * is owned by a client, we should ensure that the profiler is automatically
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to