Changeset: eea209186244 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/eea209186244
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk.h
gdk/gdk_system.c
gdk/gdk_utils.c
sql/backends/monet5/sql_scenario.c
sql/common/sql_keyword.c
sql/storage/store.c
Branch: Dec2025
Log Message:
Improved printing of information about allocators in USR1 output.
diffs (truncated from 307 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
@@ -569,7 +569,7 @@ void ma_destroy(allocator *sa);
void ma_free(allocator *sa, void *);
exception_buffer *ma_get_eb(allocator *sa) __attribute__((__pure__));
allocator *ma_get_parent(const allocator *sa);
-void ma_info(const allocator *sa, char *buf, size_t buflen);
+int ma_info(const allocator *sa, char *buf, size_t buflen, const char *pref);
const char *ma_name(allocator *sa);
allocator_state ma_open(allocator *sa);
void *ma_realloc(allocator *sa, void *ptr, size_t sz, size_t osz);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1774,7 +1774,7 @@ gdk_export void ma_free(allocator *sa, v
gdk_export exception_buffer *ma_get_eb(allocator *sa)
__attribute__((__pure__));
-gdk_export void ma_info(const allocator *sa, char *buf, size_t buflen);
+gdk_export int ma_info(const allocator *sa, char *buf, size_t buflen, const
char *pref);
#define MA_NEW( sa, type ) ((type*)ma_alloc( sa,
sizeof(type)))
#define MA_ZNEW( sa, type ) ((type*)ma_zalloc( sa,
sizeof(type)))
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -324,7 +324,7 @@ dump_threads(void)
struct mtthread *jn = t->joinwait;
const char *working = ATOMIC_PTR_GET(&t->working);
char mabuf[300];
- ma_info(t->ma, mabuf, sizeof(mabuf));
+ ma_info(t->ma, mabuf, sizeof(mabuf), ", allocator ");
int pos = snprintf(buf, sizeof(buf),
"%s, tid %zu, "
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1714,19 +1714,15 @@ typedef struct freed_t {
static inline size_t
ma_get_blk_idx(allocator *sa, void *blk, size_t offset)
{
- size_t i;
- for(i = offset; i < sa->nr; i++) {
+ for (size_t i = offset; i < sa->nr; i++) {
if (sa->blks[i] == blk)
- break;
+ return i;
}
- if (i >= sa->nr) {
- assert(0 && "allocator block not found");
- if (sa->eb.enabled) {
- eb_error(&sa->eb, "allocator block not found", 1000);
- }
-
+ assert(0 && "allocator block not found");
+ if (sa->eb.enabled) {
+ eb_error(&sa->eb, "allocator block not found", 1000);
}
- return i;
+ return sa->nr;
}
@@ -2082,7 +2078,7 @@ static void *
sa->used += sz;
}
if (sz < MA_BLOCK_SIZE) {
- // countig object only
+ // counting object only
sa->objects += 1;
sa->inuse += 1;
}
@@ -2348,22 +2344,31 @@ ma_get_parent(const allocator *a)
return a ? a->pa : NULL;
}
-void
-ma_info(const allocator *a, char *buf, size_t bufsize)
+int
+ma_info(const allocator *a, char *buf, size_t bufsize, const char *pref)
{
+ int pos = 0;
buf[0] = 0;
- if (a != NULL)
- snprintf(buf, bufsize,
- ", allocator %s, size %zu, nr %zu, used %zu%s"
- ", usedmem %zu%s, blk_size %zu, objects %zu"
- ", inuse %zu, free_obj_hits %zu, frees %zu"
- ", free_blk_hits %zu, tmp_used %zu, refcount %d",
- a->name, a->size, a->nr,
- a->used, humansize(a->used, (char[24]){0}, 24),
- a->usedmem, humansize(a->usedmem, (char[24]){0}, 24),
- a->blk_size, a->objects,
- a->inuse, a->free_obj_hits, a->frees,
- a->free_blk_hits, a->tmp_used, a->refcount);
+ if (a != NULL) {
+ pos = snprintf(buf, bufsize, "%s%s: used %zu%s, usedmem %zu%s",
+ pref ? pref : "",
+ a->name,
+ a->used, humansize(a->used, (char[24]){0}, 24),
+ a->usedmem, humansize(a->usedmem, (char[24]){0},
24));
+ if (a->objects > 0)
+ pos += snprintf(buf + pos, bufsize - pos,
+ ", objects %zu", a->objects);
+ if (a->inuse > 0)
+ pos += snprintf(buf + pos, bufsize - pos,
+ ", inuse %zu", a->inuse);
+ if (a->tmp_used > 0)
+ pos += snprintf(buf + pos, bufsize - pos,
+ ", tmp_used %zu", a->tmp_used);
+ if (a->refcount > 0)
+ pos += snprintf(buf + pos, bufsize - pos,
+ ", refcount %d", a->refcount);
+ }
+ return pos;
}
inline size_t
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
@@ -93,16 +93,9 @@ static void
CLIENTprintinfo(void)
{
int nrun = 0, nfinish = 0, nblock = 0;
- char mmbuf[64];
- char tmbuf[64];
- char trbuf[128];
- char chbuf[64];
- char cabuf[64];
- char clbuf[64];
- char crbuf[64];
- char cpbuf[64];
- char qybuf[200];
struct tm tm;
+ char buf[2048];
+ int pos;
if (!MT_lock_trytime(&mal_contextLock, 1000)) {
printf("Clients are currently locked, so no client
information\n");
@@ -113,68 +106,82 @@ CLIENTprintinfo(void)
switch (c->mode) {
case RUNCLIENT:
/* running */
+ pos = snprintf(buf, sizeof(buf),
+ "client %d, user %s, thread
%s"
+ ", using %"PRIu64" bytes of
transient space",
+ c->idx, c->username,
c->mythread ? c->mythread : "?",
+ (uint64_t)
ATOMIC_GET(&c->qryctx.datasize));
nrun++;
if (c->qryctx.maxmem)
- snprintf(mmbuf, sizeof(mmbuf), " (max
%"PRIu64")", (uint64_t) c->qryctx.maxmem);
- else
- mmbuf[0] = 0;
+ pos += snprintf(buf, sizeof(buf) - pos,
+ " (max
%"PRIu64")",
+ (uint64_t)
c->qryctx.maxmem);
if (c->idle) {
localtime_r(&c->idle, &tm);
- strftime(tmbuf, sizeof(tmbuf), ", idle since %F
%H:%M:%S%z", &tm);
+ pos += strftime(buf + pos, sizeof(buf) - pos,
+ ", idle since
%F %H:%M:%S%z", &tm);
} else if (c->lastcmd) {
localtime_r(&c->lastcmd, &tm);
- strftime(tmbuf, sizeof(tmbuf), ", busy since %F
%H:%M:%S%z", &tm);
- } else
- tmbuf[0] = 0;
- if (c->query)
- strconcat_len(qybuf, sizeof(qybuf), ", query:
", c->query, NULL);
- else
- qybuf[0] = 0;
- if (c->sqlcontext && ((backend *) c->sqlcontext)->mvc &&
- ((backend *) c->sqlcontext)->mvc->session &&
- ((backend *) c->sqlcontext)->mvc->session->tr) {
- int i = 0;
- if (((backend *)
c->sqlcontext)->mvc->session->tr->active)
- i = snprintf(trbuf, sizeof(trbuf), ",
active transaction, ts: "ULLFMT, ((backend *)
c->sqlcontext)->mvc->session->tr->ts);
- if (i < (int) sizeof(trbuf))
- i += snprintf(trbuf + i, sizeof(trbuf)
- i, ", prepared queries: %d", qc_size(((backend *) c->sqlcontext)->mvc->qc));
- if (i < (int) sizeof(trbuf))
- snprintf(trbuf + i, sizeof(trbuf) - i,
", open resultsets: %d", res_tables_count(((backend *)
c->sqlcontext)->results));
+ pos += strftime(buf + pos, sizeof(buf) - pos,
+ ", busy since
%F %H:%M:%S%z", &tm);
+ }
+ pos += ma_info(c->ma, buf + pos, sizeof(buf) - pos, ",
allocator ");
+ pos += ma_info(c->qryctx.errorallocator, buf + pos,
sizeof(buf) - pos, ", allocator ");
+ Symbol prg = c->curprg;
+ if (prg) {
+ MalBlkPtr def = prg->def;
+ if (def) {
+ pos += ma_info(def->ma, buf + pos,
sizeof(buf) - pos, ", allocator ");
+ pos += ma_info(def->instr_allocator,
buf + pos, sizeof(buf) - pos, ", allocator ");
+ }
}
- else
- trbuf[0] = 0;
- if (c->client_hostname)
- snprintf(chbuf, sizeof(chbuf), ", client host:
%s", c->client_hostname);
- else
- chbuf[0] = 0;
- if (c->client_application)
- snprintf(cabuf, sizeof(cabuf), ", client app:
%s", c->client_application);
- else
- cabuf[0] = 0;
- if (c->client_library)
- snprintf(clbuf, sizeof(clbuf), ", client lib:
%s", c->client_library);
- else
- clbuf[0] = 0;
- if (c->client_remark)
- snprintf(crbuf, sizeof(crbuf), ", client
remark: %s", c->client_remark);
- else
- crbuf[0] = 0;
+ backend *be = c->sqlcontext;
+ if (be) {
+ mvc *sql = be->mvc;
+ if (sql) {
+ sql_session *s = sql->session;
+ if (s) {
+ sql_trans *tr = s->tr;
+ if (tr && tr->active)
+ pos += snprintf(buf +
pos, sizeof(buf) - pos,
+
", active transaction, ts: "ULLFMT,
+
tr->ts);
+ }
+ pos += ma_info(sql->pa, buf + pos,
sizeof(buf) - pos, ", allocator ");
+ pos += ma_info(sql->sa, buf + pos,
sizeof(buf) - pos, ", allocator ");
+ pos += ma_info(sql->ta, buf + pos,
sizeof(buf) - pos, ", allocator ");
+ pos += snprintf(buf + pos, sizeof(buf)
- pos,
+ ",
prepared queries: %d",
+
qc_size(sql->qc));
+ }
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", open
resultsets: %d",
+
res_tables_count(be->results));
+ }
+ const char *s = c->client_hostname;
+ if (s)
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", client host:
%s", s);
+ s = c->client_application;
+ if (s)
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", client app:
%s", s);
+ s = c->client_library;
+ if (s)
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", client lib:
%s", s);
+ s = c->client_remark;
+ if (s)
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", client
remark: %s", s);
if (c->client_pid)
- snprintf(cpbuf, sizeof(cpbuf), ", client pid:
%ld", c->client_pid);
- else
- cpbuf[0] = 0;
- char mabuf1[300] = "";
- char mabuf2[300] = "";
- char mabuf3[300] = "";
- ma_info(c->ma, mabuf1, sizeof(mabuf1));
- if (c->curprg && c->curprg->def)
- ma_info(c->curprg->def->ma, mabuf2,
sizeof(mabuf2));
- if (c->sqlcontext) {
- backend *be = (backend*) c->sqlcontext;
- if (be->mvc)
- ma_info(be->mvc->pa, mabuf3,
sizeof(mabuf3));
- }
- printf("client %d, user %s, thread %s, using %"PRIu64"
bytes of transient space%s%s%s%s%s%s%s%s%s%s%s%s\n", c->idx, c->username,
c->mythread ? c->mythread : "?", (uint64_t) ATOMIC_GET(&c->qryctx.datasize),
mmbuf, mabuf1, mabuf2, mabuf3, tmbuf, trbuf, chbuf, cabuf, clbuf, cpbuf, crbuf,
qybuf);
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", client pid:
%ld", c->client_pid);
+ s = c->query;
+ if (s)
+ pos += snprintf(buf + pos, sizeof(buf) - pos,
+ ", query: %s",
s);
+ printf("%s\n", buf);
break;
case FINISHCLIENT:
/* finishing */
diff --git a/sql/common/sql_keyword.c b/sql/common/sql_keyword.c
--- a/sql/common/sql_keyword.c
+++ b/sql/common/sql_keyword.c
@@ -45,8 +45,10 @@ keywords_insert(const char *oldk, int to
char *k = NULL;
allocator *ta = MT_thread_getallocator();
allocator_state ta_state = ma_open(ta);
- if (GDKtolower(ta, &k, &(size_t){0}, oldk) != GDK_SUCCEED)
+ if (GDKtolower(ta, &k, &(size_t){0}, oldk) != GDK_SUCCEED) {
+ ma_close(&ta_state);
return -1;
+ }
k = GDKstrdup(k);
ma_close(&ta_state);
if (kw != NULL && k != NULL) {
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -7858,6 +7858,9 @@ store_printinfo(sqlstore *store)
{
printf("SQL store object id: %"PRIu64"\n",
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]