mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-11 10:04:28 +01:00
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 <decker.christian@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user