summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2002-01-03 05:34:33 +0000
committerMartin Pool <mbp@samba.org>2002-01-03 05:34:33 +0000
commite28cdc093141c85b142c3f5acaacb17dbc310a6c (patch)
tree20595f7a1e1cbdcf6c673897249ad3d55fb70709
parent588a59b5051b88268d1a686c7c93264662f50b74 (diff)
downloadsamba-e28cdc093141c85b142c3f5acaacb17dbc310a6c.tar.gz
samba-e28cdc093141c85b142c3f5acaacb17dbc310a6c.tar.bz2
samba-e28cdc093141c85b142c3f5acaacb17dbc310a6c.zip
talloc accounting now includes number of chunks and bytes allocated.
(This used to be commit cd25d01e42e7874bc93f6ca336c5b2cde453bb52)
-rw-r--r--source3/lib/talloc.c51
1 files changed, 42 insertions, 9 deletions
diff --git a/source3/lib/talloc.c b/source3/lib/talloc.c
index 3b4c3e9d15..01a6e19bb2 100644
--- a/source3/lib/talloc.c
+++ b/source3/lib/talloc.c
@@ -352,23 +352,43 @@ char *talloc_strdup(TALLOC_CTX *t, const char *p)
* Return a human-readable description of all talloc memory usage.
* The result is allocated from @p t.
**/
-char *talloc_describe_all(TALLOC_CTX *t)
+char *talloc_describe_all(TALLOC_CTX *rt)
{
- int n_pools = 0;
- size_t total = 0;
- TALLOC_CTX *titer;
+ int n_pools = 0, total_chunks = 0;
+ size_t total_bytes = 0;
+ TALLOC_CTX *it;
char *s;
- s = talloc_asprintf(t, "global talloc allocations in pid%u:\n",
+ s = talloc_asprintf(rt, "global talloc allocations in pid%u:\n",
(unsigned) getpid());
- s = talloc_asprintf_append(t, s, "name\n----\n");
+ s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
+ "name", "chunks", "bytes");
+ s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
+ "----------------------------------------",
+ "--------",
+ "--------");
- for (titer = list_head; titer; titer = titer->next_ctx) {
+ for (it = list_head; it; it = it->next_ctx) {
+ size_t bytes;
+ int n_chunks;
n_pools++;
- s = talloc_asprintf_append(t, s, "\"%s\"\n", titer->name);
+ talloc_get_allocation(it, &bytes, &n_chunks);
+ s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
+ it->name,
+ (unsigned) n_chunks,
+ (unsigned) bytes);
+ total_bytes += bytes;
+ total_chunks += n_chunks;
}
- s = talloc_asprintf_append(t, s, "-----\nTotal %d pools\n", n_pools);
+ s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
+ "----------------------------------------",
+ "--------",
+ "--------");
+
+ s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
+ "TOTAL",
+ (unsigned) total_chunks, (unsigned) total_bytes);
return s;
}
@@ -379,7 +399,20 @@ char *talloc_describe_all(TALLOC_CTX *t)
* Return an estimated memory usage for the specified pool. This does
* not include memory used by the underlying malloc implementation.
**/
+void talloc_get_allocation(TALLOC_CTX *t,
+ size_t *total_bytes,
+ int *n_chunks)
+{
+ struct talloc_chunk *chunk;
+
+ *total_bytes = 0;
+ *n_chunks = 0;
+ for (chunk = t->list; chunk; chunk = chunk->next) {
+ n_chunks[0]++;
+ *total_bytes += chunk->size;
+ }
+}
/** @} */