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