Test JSON output of malloc_stats_print() and fix bugs.
Implement and test a JSON validation parser. Use the parser to validate JSON output from malloc_stats_print(), with a significant subset of supported output options. This resolves #583.
This commit is contained in:
parent
61d26425e5
commit
54d2d697b2
@ -186,6 +186,7 @@ TESTS_UNIT := \
|
|||||||
$(srcroot)test/unit/size_classes.c \
|
$(srcroot)test/unit/size_classes.c \
|
||||||
$(srcroot)test/unit/smoothstep.c \
|
$(srcroot)test/unit/smoothstep.c \
|
||||||
$(srcroot)test/unit/stats.c \
|
$(srcroot)test/unit/stats.c \
|
||||||
|
$(srcroot)test/unit/stats_print.c \
|
||||||
$(srcroot)test/unit/ticker.c \
|
$(srcroot)test/unit/ticker.c \
|
||||||
$(srcroot)test/unit/nstime.c \
|
$(srcroot)test/unit/nstime.c \
|
||||||
$(srcroot)test/unit/tsd.c \
|
$(srcroot)test/unit/tsd.c \
|
||||||
|
27
src/stats.c
27
src/stats.c
@ -39,7 +39,7 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
bool json, bool large, bool huge, unsigned i)
|
bool json, bool large, bool huge, unsigned i)
|
||||||
{
|
{
|
||||||
size_t page;
|
size_t page;
|
||||||
bool config_tcache, in_gap, in_gap_prev;
|
bool in_gap, in_gap_prev;
|
||||||
unsigned nbins, j;
|
unsigned nbins, j;
|
||||||
|
|
||||||
CTL_GET("arenas.page", &page, size_t);
|
CTL_GET("arenas.page", &page, size_t);
|
||||||
@ -49,7 +49,6 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t\t\"bins\": [\n");
|
"\t\t\t\t\"bins\": [\n");
|
||||||
} else {
|
} else {
|
||||||
CTL_GET("config.tcache", &config_tcache, bool);
|
|
||||||
if (config_tcache) {
|
if (config_tcache) {
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"bins: size ind allocated nmalloc"
|
"bins: size ind allocated nmalloc"
|
||||||
@ -536,7 +535,7 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
"\t\t\t\t\t\"allocated\": %zu\n", metadata_allocated);
|
"\t\t\t\t\t\"allocated\": %zu\n", metadata_allocated);
|
||||||
|
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t\t},\n");
|
"\t\t\t\t}%s\n", (bins || large || huge) ? "," : "");
|
||||||
} else {
|
} else {
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"metadata: mapped: %zu, allocated: %zu\n",
|
"metadata: mapped: %zu, allocated: %zu\n",
|
||||||
@ -838,9 +837,11 @@ stats_general_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t\"nbins\": %u,\n", nbins);
|
"\t\t\t\"nbins\": %u,\n", nbins);
|
||||||
|
|
||||||
|
if (config_tcache) {
|
||||||
CTL_GET("arenas.nhbins", &uv, unsigned);
|
CTL_GET("arenas.nhbins", &uv, unsigned);
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t\"nhbins\": %u,\n", uv);
|
"\t\t\t\"nhbins\": %u,\n", uv);
|
||||||
|
}
|
||||||
|
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t\"bin\": [\n");
|
"\t\t\t\"bin\": [\n");
|
||||||
@ -1022,31 +1023,37 @@ stats_print_helper(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
narenas, bins, large, huge);
|
narenas, bins, large, huge);
|
||||||
if (json) {
|
if (json) {
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
"\t\t\t}%s\n", (ninitialized > 1) ?
|
"\t\t\t}%s\n", unmerged ? "," :
|
||||||
"," : "");
|
"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unmerged stats. */
|
/* Unmerged stats. */
|
||||||
|
if (unmerged) {
|
||||||
for (i = j = 0; i < narenas; i++) {
|
for (i = j = 0; i < narenas; i++) {
|
||||||
if (initialized[i]) {
|
if (initialized[i]) {
|
||||||
if (json) {
|
if (json) {
|
||||||
j++;
|
j++;
|
||||||
malloc_cprintf(write_cb,
|
malloc_cprintf(write_cb,
|
||||||
cbopaque,
|
cbopaque,
|
||||||
"\t\t\t\"%u\": {\n", i);
|
"\t\t\t\"%u\": {\n",
|
||||||
|
i);
|
||||||
} else {
|
} else {
|
||||||
malloc_cprintf(write_cb,
|
malloc_cprintf(write_cb,
|
||||||
cbopaque, "\narenas[%u]:\n",
|
cbopaque,
|
||||||
|
"\narenas[%u]:\n",
|
||||||
i);
|
i);
|
||||||
}
|
}
|
||||||
stats_arena_print(write_cb, cbopaque,
|
stats_arena_print(write_cb,
|
||||||
json, i, bins, large, huge);
|
cbopaque, json, i, bins,
|
||||||
|
large, huge);
|
||||||
if (json) {
|
if (json) {
|
||||||
malloc_cprintf(write_cb,
|
malloc_cprintf(write_cb,
|
||||||
cbopaque,
|
cbopaque,
|
||||||
"\t\t\t}%s\n", (j <
|
"\t\t\t}%s\n", (j <
|
||||||
ninitialized) ? "," : "");
|
ninitialized) ? ","
|
||||||
|
: "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1000
test/unit/stats_print.c
Normal file
1000
test/unit/stats_print.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user