Changeset: 3b8613bb427a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3b8613bb427a
Modified Files:
gdk/gdk.h
gdk/gdk_system.c
gdk/gdk_utils.c
sql/backends/monet5/sql_scenario.c
Branch: resource_management
Log Message:
Mostly debug stuff.
diffs (230 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1755,6 +1755,8 @@ 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);
+
#define MA_NEW( sa, type ) ((type*)ma_alloc( sa,
sizeof(type)))
#define MA_ZNEW( sa, type ) ((type*)ma_zalloc( sa,
sizeof(type)))
#define MA_NEW_ARRAY( sa, type, size ) (type*)ma_alloc( sa,
((size)*sizeof(type)))
@@ -1771,8 +1773,8 @@ gdk_export exception_buffer *ma_get_eb(a
size_t _sz = (sz); \
void *_res = ma_alloc(_sa, _sz); \
TRC_DEBUG(ALLOC, \
- "ma_alloc(%p,%zu) -> %p\n", \
- _sa, _sz, _res); \
+ "ma_alloc(%p(%s),%zu) -> %p\n", \
+ _sa, ma_name(_sa), _sz, _res); \
_res; \
})
#define ma_zalloc(sa, sz) \
@@ -1781,8 +1783,8 @@ gdk_export exception_buffer *ma_get_eb(a
size_t _sz = (sz); \
void *_res = ma_zalloc(_sa, _sz); \
TRC_DEBUG(ALLOC, \
- "ma_zalloc(%p,%zu) -> %p\n", \
- _sa, _sz, _res); \
+ "ma_zalloc(%p(%s),%zu) -> %p\n", \
+ _sa, ma_name(_sa), _sz, _res); \
_res; \
})
#define ma_realloc(sa, ptr, sz, osz) \
@@ -1793,8 +1795,8 @@ gdk_export exception_buffer *ma_get_eb(a
size_t _osz = (osz); \
void *_res = ma_realloc(_sa, _ptr, _sz, _osz); \
TRC_DEBUG(ALLOC, \
- "ma_realloc(%p,%p,%zu,%zu) -> %p\n", \
- _sa, _ptr, _sz, _osz, _res); \
+ "ma_realloc(%p(%s),%p,%zu,%zu) -> %p\n", \
+ _sa, ma_name(_sa), _ptr, _sz, _osz, _res); \
_res; \
})
#define ma_strdup(sa, s) \
@@ -1803,8 +1805,8 @@ gdk_export exception_buffer *ma_get_eb(a
const char *_s = (s); \
char *_res = ma_strdup(_sa, _s); \
TRC_DEBUG(ALLOC, \
- "ma_strdup(%p,len=%zu) -> %p\n", \
- _sa, strlen(_s), _res); \
+ "ma_strdup(%p(%s),len=%zu) -> %p\n", \
+ _sa, ma_name(_sa), strlen(_s), _res); \
_res; \
})
#define ma_strndup(sa, s, l) \
@@ -1814,8 +1816,19 @@ gdk_export exception_buffer *ma_get_eb(a
size_t _l = (l); \
char *_res = ma_strndup(_sa, _s, _l); \
TRC_DEBUG(ALLOC, \
- "ma_strndup(%p,len=%zu) -> %p\n", \
- _sa, _l, _res); \
+ "ma_strndup(%p(%s),len=%zu) -> %p\n", \
+ _sa, ma_name(_sa), _l, _res); \
+ _res; \
+ })
+#define create_allocator(sa, nm, lk)
\
+ ({ \
+ allocator *_sa = (sa); \
+ const char *_nm = (nm); \
+ bool _lk = (lk); \
+ allocator *_res = create_allocator(_sa, _nm, _lk); \
+ TRC_DEBUG(ALLOC, \
+ "create_allocator(%p(%s)) -> %p(%s)\n", \
+ _sa, ma_name(_sa), _res, ma_name(_res)); \
_res; \
})
#endif
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -323,8 +323,8 @@ dump_threads(void)
MT_Cond *cn = t->condwait;
struct mtthread *jn = t->joinwait;
const char *working = ATOMIC_PTR_GET(&t->working);
- size_t allocsz = t->ma ? ma_size(t->ma) : 0;
- const char *allocnm = t->ma ? ma_name(t->ma) : NULL;
+ char mabuf[300];
+ ma_info(t->ma, mabuf, sizeof(mabuf));
int pos = snprintf(buf, sizeof(buf),
"%s, tid %zu, "
@@ -334,7 +334,7 @@ dump_threads(void)
#ifdef HAVE_GETTID
"LWP %ld, "
#endif
- "%"PRIu32" free bats, waiting for %s%s,
allocator %s %zu%s, working on %.200s",
+ "%"PRIu32" free bats, waiting for %s%s%s,
working on %.200s",
t->threadname,
t->tid,
#ifdef HAVE_PTHREAD_H
@@ -346,8 +346,7 @@ dump_threads(void)
t->freebats.nfreebats,
lk ? "lock " : sm ? "semaphore " : cn ?
"condvar " : jn ? "thread " : "",
lk ? lk->name : sm ? sm->name : cn ?
cn->name : jn ? jn->threadname : "nothing",
- allocnm ? allocnm : "unnamed",
- allocsz, humansize(allocsz, (char[24]){0},
24),
+ mabuf,
ATOMIC_GET(&t->exited) ? "exiting" :
working ? working : "nothing");
#ifdef LOCK_OWNER
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1684,7 +1684,7 @@ GDKprintinforegister(void (*func)(void))
#define SA_NUM_BLOCKS 64
#define SA_BLOCK_SIZE (128*1024)
-#define SA_HEADER_SIZE 2*(sizeof(size_t))
+#define SA_HEADER_SIZE (2*(sizeof(size_t)))
#define CANARY_VALUE ((size_t)0xDEADBEEFDEADBEEF)
#define round16(sz) ((sz+15)&~15)
#define round_block_size(sz) ((sz + (SA_BLOCK_SIZE - 1))&~(SA_BLOCK_SIZE - 1))
@@ -2095,6 +2095,7 @@ ma_alloc(allocator *sa, size_t sz)
return sa_fill_in_header(r, sz);
}
+#undef create_allocator
allocator *
create_allocator(allocator *pa, const char *name, bool use_lock)
{
@@ -2231,7 +2232,7 @@ ma_size(allocator *sa)
const char *
ma_name(allocator *sa)
{
- return sa->name;
+ return sa ? sa->name : "";
}
exception_buffer *
@@ -2245,6 +2246,17 @@ ma_open(allocator *sa)
{
assert(sa);
if (sa) {
+ allocator_state st;
+ COND_LOCK_ALLOCATOR(sa);
+ sa->tmp_used += 1;
+ st = (allocator_state) {
+ .nr = sa->nr,
+ .used = sa->used,
+ .usedmem = sa->usedmem,
+ .objects = sa->objects,
+ .inuse = sa->inuse,
+ };
+ COND_UNLOCK_ALLOCATOR(sa);
allocator_state *res = ma_alloc(sa,
sizeof(allocator_state));
if (!res) {
@@ -2252,15 +2264,8 @@ ma_open(allocator *sa)
eb_error(&sa->eb, "out of memory", 1000);
return NULL;
}
+ *res = st;
- COND_LOCK_ALLOCATOR(sa);
- sa->tmp_used += 1;
- res->nr = sa->nr;
- res->used = sa->used;
- res->usedmem = sa->usedmem;
- res->objects = sa->objects;
- res->inuse = sa->inuse;
- COND_UNLOCK_ALLOCATOR(sa);
return res;
}
return NULL;
@@ -2354,6 +2359,14 @@ ma_get_parent(const allocator *a)
return a ? a->pa : NULL;
}
+void
+ma_info(const allocator *a, char *buf, size_t bufsize)
+{
+ buf[0] = 0;
+ if (a != NULL)
+ snprintf(buf, bufsize, ", allocator %s, size %zu, nr %zu, used
%zu, usedmem %zu, 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, a->usedmem, a->blk_size, a->objects, a->inuse,
a->free_obj_hits, a->frees, a->free_blk_hits, a->tmp_used, a->refcount);
+}
+
inline size_t
GDKmem_cursize(void)
{
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,7 +93,6 @@ static void
CLIENTprintinfo(void)
{
int nrun = 0, nfinish = 0, nblock = 0;
- char mabuf[64]; // memory allocator buffer
char mmbuf[64];
char tmbuf[64];
char trbuf[128];
@@ -164,21 +163,18 @@ CLIENTprintinfo(void)
snprintf(cpbuf, sizeof(cpbuf), ", client pid:
%ld", c->client_pid);
else
cpbuf[0] = 0;
- size_t ma_used = 0; // total allocated through client
allocators
- if (c->ma)
- ma_used += ma_size(c->ma);
+ char mabuf1[300] = "";
+ char mabuf2[300] = "";
+ char mabuf3[300] = "";
+ ma_info(c->ma, mabuf1, sizeof(mabuf1));
if (c->curprg && c->curprg->def)
- ma_used += ma_size(c->curprg->def->ma);
+ ma_info(c->curprg->def->ma, mabuf2,
sizeof(mabuf2));
if (c->sqlcontext) {
backend *be = (backend*) c->sqlcontext;
if (be->mvc)
- ma_used += ma_size(be->mvc->pa);
+ ma_info(be->mvc->pa, mabuf3,
sizeof(mabuf3));
}
- if (ma_used)
- snprintf(mabuf, sizeof(mabuf), ", allocators
combined: %zu%s bytes", ma_used, humansize(ma_used, (char[24]){0}, 24));
- else
- mabuf[0] = 0;
- printf("client %d, user %s, thread %s, using %"PRIu64"
bytes of transient space%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, mabuf, tmbuf, trbuf, chbuf, cabuf, clbuf, cpbuf, crbuf, qybuf);
+ 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);
break;
case FINISHCLIENT:
/* finishing */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]