| 29 | } |
| 30 | |
| 31 | static size_t add_memdump(struct json_stream *response, |
| 32 | const char *fieldname, const tal_t *root, |
| 33 | struct command *cmd) |
| 34 | { |
| 35 | size_t cumulative_size = 0; |
| 36 | |
| 37 | json_array_start(response, fieldname); |
| 38 | for (const tal_t *i = tal_first(root); i; i = tal_next(i)) { |
| 39 | const char *name = tal_name(i); |
| 40 | size_t size = tal_bytelen(i); |
| 41 | |
| 42 | /* Don't try to dump this command! */ |
| 43 | if (i == cmd || i == cmd->jcon) |
| 44 | continue; |
| 45 | |
| 46 | /* Don't dump logs, we know they grow. */ |
| 47 | if (name && streq(name, "struct log_book")) |
| 48 | continue; |
| 49 | |
| 50 | json_object_start(response, NULL); |
| 51 | json_add_ptr(response, "parent", tal_parent(i)); |
| 52 | json_add_ptr(response, "value", i); |
| 53 | json_add_u64(response, "size", size); |
| 54 | if (name) |
| 55 | json_add_string(response, "label", name); |
| 56 | |
| 57 | if (tal_first(i)) |
| 58 | size += add_memdump(response, "children", i, cmd); |
| 59 | json_add_u64(response, "cumulative_size", size); |
| 60 | json_object_end(response); |
| 61 | cumulative_size += size; |
| 62 | } |
| 63 | json_array_end(response); |
| 64 | return cumulative_size; |
| 65 | } |
| 66 | |
| 67 | static struct command_result *json_memdump(struct command *cmd, |
| 68 | const char *buffer, |
no test coverage detected