Stats printing: move stats_print_helper to use emitter.

This commit is contained in:
David Goldblatt 2018-03-05 12:58:24 -08:00 committed by David Goldblatt
parent 86c61d4a57
commit cbde666d9a

View File

@ -481,6 +481,10 @@ stats_arena_print(void (*write_cb)(void *, const char *), void *cbopaque,
size_t tcache_bytes; size_t tcache_bytes;
uint64_t uptime; uint64_t uptime;
if (json) {
malloc_cprintf(write_cb, cbopaque, "\n");
}
CTL_GET("arenas.page", &page, size_t); CTL_GET("arenas.page", &page, size_t);
CTL_M2_GET("stats.arenas.0.nthreads", i, &nthreads, unsigned); CTL_M2_GET("stats.arenas.0.nthreads", i, &nthreads, unsigned);
@ -1077,24 +1081,12 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
emitter_json_dict_end(emitter); /* Close "stats". */ emitter_json_dict_end(emitter); /* Close "stats". */
if (json) {
if (merged || unmerged || destroyed) {
malloc_cprintf(write_cb, cbopaque, ",\n");
} else {
malloc_cprintf(write_cb, cbopaque, "\n");
}
}
if (merged || destroyed || unmerged) { if (merged || destroyed || unmerged) {
unsigned narenas; unsigned narenas;
if (json) { emitter_json_dict_begin(emitter, "stats.arenas");
malloc_cprintf(write_cb, cbopaque,
"\t\t\"stats.arenas\": {\n");
}
CTL_GET("arenas.narenas", &narenas, unsigned); CTL_GET("arenas.narenas", &narenas, unsigned);
{
size_t mib[3]; size_t mib[3];
size_t miblen = sizeof(mib) / sizeof(size_t); size_t miblen = sizeof(mib) / sizeof(size_t);
size_t sz; size_t sz;
@ -1120,79 +1112,46 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
/* Merged stats. */ /* Merged stats. */
if (merged && (ninitialized > 1 || !unmerged)) { if (merged && (ninitialized > 1 || !unmerged)) {
/* Print merged arena stats. */ /* Print merged arena stats. */
if (json) { emitter_table_printf(emitter, "Merged arenas stats:\n");
malloc_cprintf(write_cb, cbopaque, emitter_json_dict_begin(emitter, "merged");
"\t\t\t\"merged\": {\n");
} else {
malloc_cprintf(write_cb, cbopaque,
"\nMerged arenas stats:\n");
}
stats_arena_print(write_cb, cbopaque, json, stats_arena_print(write_cb, cbopaque, json,
MALLCTL_ARENAS_ALL, bins, large, mutex); MALLCTL_ARENAS_ALL, bins, large, mutex);
if (json) { emitter_json_dict_end(emitter); /* Close "merged". */
malloc_cprintf(write_cb, cbopaque,
"\t\t\t}%s\n",
((destroyed_initialized &&
destroyed) || unmerged) ? "," :
"");
}
} }
/* Destroyed stats. */ /* Destroyed stats. */
if (destroyed_initialized && destroyed) { if (destroyed_initialized && destroyed) {
/* Print destroyed arena stats. */ /* Print destroyed arena stats. */
if (json) { emitter_table_printf(emitter,
malloc_cprintf(write_cb, cbopaque, "Destroyed arenas stats:\n");
"\t\t\t\"destroyed\": {\n"); emitter_json_dict_begin(emitter, "destroyed");
} else {
malloc_cprintf(write_cb, cbopaque,
"\nDestroyed arenas stats:\n");
}
stats_arena_print(write_cb, cbopaque, json, stats_arena_print(write_cb, cbopaque, json,
MALLCTL_ARENAS_DESTROYED, bins, large, MALLCTL_ARENAS_DESTROYED, bins, large,
mutex); mutex);
if (json) { emitter_json_dict_end(emitter); /* Close "destroyed". */
malloc_cprintf(write_cb, cbopaque,
"\t\t\t}%s\n", unmerged ? "," :
"");
}
} }
/* Unmerged stats. */ /* Unmerged stats. */
if (unmerged) { if (unmerged) {
for (i = j = 0; i < narenas; i++) { for (i = j = 0; i < narenas; i++) {
if (initialized[i]) { if (initialized[i]) {
if (json) { char arena_ind_str[20];
j++; malloc_snprintf(arena_ind_str,
malloc_cprintf(write_cb, sizeof(arena_ind_str), "%u", i);
cbopaque, emitter_json_dict_begin(emitter,
"\t\t\t\"%u\": {\n", arena_ind_str);
i); emitter_table_printf(emitter,
} else { "arenas[%s]:\n", arena_ind_str);
malloc_cprintf(write_cb,
cbopaque,
"\narenas[%u]:\n",
i);
}
stats_arena_print(write_cb, stats_arena_print(write_cb,
cbopaque, json, i, bins, cbopaque, json, i, bins,
large, mutex); large, mutex);
if (json) { /* Close "<arena-ind>". */
malloc_cprintf(write_cb, emitter_json_dict_end(emitter);
cbopaque,
"\t\t\t}%s\n", (j <
ninitialized) ? ","
: "");
}
}
} }
} }
} }
if (json) { emitter_json_dict_end(emitter); /* Close "stats.arenas". */
malloc_cprintf(write_cb, cbopaque,
"\t\t}\n");
}
} }
} }