Changeset: 73891dff281c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/73891dff281c
Modified Files:
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_private.h
        sql/backends/monet5/sql_scenario.c
Branch: Dec2023
Log Message:

Move client context printing to SQL layer.
We can now print whether a context has an open transaction.
We also print the name of the client thread responsible for the context.


diffs (135 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -53,12 +53,6 @@ mal_version(void)
        return MONETDB5_VERSION;
 }
 
-static void
-MALprintinfo(void)
-{
-       MCprintinfo();
-}
-
 /*
  * Initialization of the MAL context
  */
@@ -99,8 +93,6 @@ mal_init(char *modules[], bool embedded,
                return -1;
        initNamespace();
 
-       GDKprintinforegister(MALprintinfo);
-
        err = malBootstrap(modules, embedded, initpasswd);
        if (err !=MAL_SUCCEED) {
                mal_client_reset();
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
@@ -587,36 +587,3 @@ MCvalid(Client tc)
        MT_lock_unset(&mal_contextLock);
        return 0;
 }
-
-void
-MCprintinfo(void)
-{
-       int nrun = 0, nfinish = 0, nblock = 0;
-
-       MT_lock_set(&mal_contextLock);
-       for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
-               switch (c->mode) {
-               case RUNCLIENT:
-                       /* running */
-                       nrun++;
-                       if (c->idle)
-                               printf("client %d, user %s, using %"PRIu64" 
bytes of transient space, idle since %s", c->idx, c->username, (uint64_t) 
ATOMIC_GET(&c->qryctx.datasize), ctime(&c->idle));
-                       else
-                               printf("client %d, user %s, using %"PRIu64" 
bytes of transient space\n", c->idx, c->username, (uint64_t) 
ATOMIC_GET(&c->qryctx.datasize));
-                       break;
-               case FINISHCLIENT:
-                       /* finishing */
-                       nfinish++;
-                       break;
-               case BLOCKCLIENT:
-                       /* blocked */
-                       nblock++;
-                       break;
-               case FREECLIENT:
-                       break;
-               }
-       }
-       MT_lock_unset(&mal_contextLock);
-       printf("%d active clients, %d finishing clients, %d blocked clients\n",
-                  nrun, nfinish, nblock);
-}
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
@@ -80,6 +80,3 @@ void mal_runtime_reset(void)
 
 char *dupError(const char *err)
        __attribute__((__visibility__("hidden"), __returns_nonnull__));
-
-void MCprintinfo(void)
-       __attribute__((__visibility__("hidden")));
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -87,10 +87,55 @@ static MT_Lock sql_contextLock = MT_LOCK
 static str SQLinit(Client c, const char *initpasswd);
 static str master_password = NULL;
 
+#include "mal.h"
+#include "mal_client.h"
+
+static void
+CLIENTprintinfo(void)
+{
+       int nrun = 0, nfinish = 0, nblock = 0;
+       char buf[32];
+       char tbuf[64];
+       struct tm tm;
+
+       MT_lock_set(&mal_contextLock);
+       for (Client c = mal_clients; c < mal_clients + MAL_MAXCLIENTS; c++) {
+               switch (c->mode) {
+               case RUNCLIENT:
+                       /* running */
+                       nrun++;
+                       if (c->qryctx.maxmem)
+                               snprintf(buf, sizeof(buf), " (max %"PRIu64")", 
(uint64_t) c->qryctx.maxmem);
+                       else
+                               buf[0] = 0;
+                       if (c->idle) {
+                               localtime_r(&c->idle, &tm);
+                               strftime(tbuf, sizeof(tbuf), ", idle since %F 
%H:%M:%S%z", &tm);
+                       } else
+                               tbuf[0] = 0;
+                       printf("client %d, user %s, thread %s, using %"PRIu64" 
bytes of transient space%s%s%s\n", c->idx, c->username, c->mythread ? 
c->mythread : "?", (uint64_t) ATOMIC_GET(&c->qryctx.datasize), buf, tbuf, 
c->sqlcontext && ((backend *) c->sqlcontext)->mvc && ((backend *) 
c->sqlcontext)->mvc->session && ((backend *) c->sqlcontext)->mvc->session->tr 
&& ((backend *) c->sqlcontext)->mvc->session->tr->active ? ", active 
transaction" : "");
+                       break;
+               case FINISHCLIENT:
+                       /* finishing */
+                       nfinish++;
+                       break;
+               case BLOCKCLIENT:
+                       /* blocked */
+                       nblock++;
+                       break;
+               case FREECLIENT:
+                       break;
+               }
+       }
+       MT_lock_unset(&mal_contextLock);
+       printf("%d active clients, %d finishing clients, %d blocked clients; 
max: %d\n",
+                  nrun, nfinish, nblock, MAL_MAXCLIENTS);
+}
+
 static void
 SQLprintinfo(void)
 {
-       /* we need to start printing SQL info here... */
+       CLIENTprintinfo();
        store_printinfo(SQLstore);
 }
 
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to