From 8ed77753ef278da36708d445d3b554b42d78a093 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 2 Aug 2019 17:17:06 +0200 Subject: [PATCH] json-rpc: Add size and cumulative size to dev-memdump Since we are walking the entire allocation tree anyway, and access the tal metadata anyway, we can just as well also track the size of the memory allocations to simplify debugging of memory use. Signed-off-by: Christian Decker --- lightningd/memdump.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lightningd/memdump.c b/lightningd/memdump.c index fa3818258..51543f364 100644 --- a/lightningd/memdump.c +++ b/lightningd/memdump.c @@ -32,15 +32,17 @@ static void json_add_ptr(struct json_stream *response, const char *name, json_add_string(response, name, ptrstr); } -static void add_memdump(struct json_stream *response, +static size_t add_memdump(struct json_stream *response, const char *name, const tal_t *root, struct command *cmd) { const tal_t *i; + size_t cumulative_size = 0; json_array_start(response, name); for (i = tal_first(root); i; i = tal_next(i)) { const char *name = tal_name(i); + size_t size = tal_bytelen(i); /* Don't try to dump this command! */ if (i == cmd || i == cmd->jcon) @@ -53,14 +55,18 @@ static void add_memdump(struct json_stream *response, json_object_start(response, NULL); json_add_ptr(response, "parent", tal_parent(i)); json_add_ptr(response, "value", i); + json_add_u64(response, "size", size); if (name) json_add_string(response, "label", name); if (tal_first(i)) - add_memdump(response, "children", i, cmd); + size += add_memdump(response, "children", i, cmd); + json_add_u64(response, "cumulative_size", size); json_object_end(response); + cumulative_size += size; } json_array_end(response); + return cumulative_size; } static struct command_result *json_memdump(struct command *cmd,