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 #551.
This commit is contained in:
parent
7a61ebe71f
commit
66bf773ef2
@ -190,6 +190,7 @@ TESTS_UNIT := \
|
|||||||
$(srcroot)test/unit/slab.c \
|
$(srcroot)test/unit/slab.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 \
|
||||||
|
65
src/stats.c
65
src/stats.c
@ -37,7 +37,7 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
bool json, bool large, unsigned i)
|
bool json, bool large, 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);
|
||||||
@ -47,7 +47,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"
|
||||||
@ -700,9 +699,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);
|
||||||
|
|
||||||
CTL_GET("arenas.nhbins", &uv, unsigned);
|
if (config_tcache) {
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
CTL_GET("arenas.nhbins", &uv, unsigned);
|
||||||
"\t\t\t\"nhbins\": %u,\n", uv);
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
|
"\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");
|
||||||
@ -867,8 +868,10 @@ stats_print_helper(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
MALLCTL_ARENAS_ALL, bins, large);
|
MALLCTL_ARENAS_ALL, bins, large);
|
||||||
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",
|
||||||
"," : "");
|
((destroyed_initialized &&
|
||||||
|
destroyed) || unmerged) ? "," :
|
||||||
|
"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,31 +889,37 @@ stats_print_helper(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
MALLCTL_ARENAS_DESTROYED, bins, large);
|
MALLCTL_ARENAS_DESTROYED, bins, large);
|
||||||
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. */
|
||||||
for (i = j = 0; i < narenas; i++) {
|
if (unmerged) {
|
||||||
if (initialized[i]) {
|
for (i = j = 0; i < narenas; i++) {
|
||||||
if (json) {
|
if (initialized[i]) {
|
||||||
j++;
|
if (json) {
|
||||||
malloc_cprintf(write_cb,
|
j++;
|
||||||
cbopaque,
|
malloc_cprintf(write_cb,
|
||||||
"\t\t\t\"%u\": {\n", i);
|
cbopaque,
|
||||||
} else {
|
"\t\t\t\"%u\": {\n",
|
||||||
malloc_cprintf(write_cb,
|
i);
|
||||||
cbopaque, "\narenas[%u]:\n",
|
} else {
|
||||||
i);
|
malloc_cprintf(write_cb,
|
||||||
}
|
cbopaque,
|
||||||
stats_arena_print(write_cb, cbopaque,
|
"\narenas[%u]:\n",
|
||||||
json, i, bins, large);
|
i);
|
||||||
if (json) {
|
}
|
||||||
malloc_cprintf(write_cb,
|
stats_arena_print(write_cb,
|
||||||
cbopaque,
|
cbopaque, json, i, bins,
|
||||||
"\t\t\t}%s\n", (j <
|
large);
|
||||||
ninitialized) ? "," : "");
|
if (json) {
|
||||||
|
malloc_cprintf(write_cb,
|
||||||
|
cbopaque,
|
||||||
|
"\t\t\t}%s\n", (j <
|
||||||
|
ninitialized) ? ","
|
||||||
|
: "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1006
test/unit/stats_print.c
Normal file
1006
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