Stats printing: Convert arena large stats to use emitter.

This completes the conversion; we now have only structured text output.
This commit is contained in:
David Goldblatt 2018-03-06 20:25:35 -08:00 committed by David Goldblatt
parent 4eed989bbf
commit 4c36cd2cc5

View File

@ -408,21 +408,47 @@ stats_arena_bins_print(emitter_t *emitter, bool mutex, unsigned i) {
} }
static void static void
stats_arena_lextents_print(void (*write_cb)(void *, const char *), stats_arena_lextents_print(emitter_t *emitter, unsigned i) {
void *cbopaque, bool json, unsigned i) {
unsigned nbins, nlextents, j; unsigned nbins, nlextents, j;
bool in_gap, in_gap_prev; bool in_gap, in_gap_prev;
CTL_GET("arenas.nbins", &nbins, unsigned); CTL_GET("arenas.nbins", &nbins, unsigned);
CTL_GET("arenas.nlextents", &nlextents, unsigned); CTL_GET("arenas.nlextents", &nlextents, unsigned);
if (json) {
malloc_cprintf(write_cb, cbopaque, emitter_row_t header_row;
"\t\t\t\t\"lextents\": [\n"); emitter_row_init(&header_row);
} else { emitter_row_t row;
malloc_cprintf(write_cb, cbopaque, emitter_row_init(&row);
"large: size ind allocated nmalloc"
" ndalloc nrequests curlextents\n"); #define COL(name, left_or_right, col_width, etype) \
} emitter_col_t header_##name; \
emitter_col_init(&header_##name, &header_row); \
header_##name.justify = emitter_justify_##left_or_right; \
header_##name.width = col_width; \
header_##name.type = emitter_type_title; \
header_##name.str_val = #name; \
\
emitter_col_t col_##name; \
emitter_col_init(&col_##name, &row); \
col_##name.justify = emitter_justify_##left_or_right; \
col_##name.width = col_width; \
col_##name.type = emitter_type_##etype;
COL(size, right, 20, size)
COL(ind, right, 4, unsigned)
COL(allocated, right, 13, size)
COL(nmalloc, right, 13, uint64)
COL(ndalloc, right, 13, uint64)
COL(nrequests, right, 13, uint64)
COL(curlextents, right, 13, size)
#undef COL
/* As with bins, we label the large extents table. */
header_size.width -= 6;
emitter_table_printf(emitter, "large:");
emitter_table_row(emitter, &header_row);
emitter_json_arr_begin(emitter, "lextents");
for (j = 0, in_gap = false; j < nlextents; j++) { for (j = 0, in_gap = false; j < nlextents; j++) {
uint64_t nmalloc, ndalloc, nrequests; uint64_t nmalloc, ndalloc, nrequests;
size_t lextent_size, curlextents; size_t lextent_size, curlextents;
@ -436,38 +462,35 @@ stats_arena_lextents_print(void (*write_cb)(void *, const char *),
in_gap_prev = in_gap; in_gap_prev = in_gap;
in_gap = (nrequests == 0); in_gap = (nrequests == 0);
if (!json && in_gap_prev && !in_gap) { if (in_gap_prev && !in_gap) {
malloc_cprintf(write_cb, cbopaque, emitter_table_printf(emitter,
" ---\n"); " ---\n");
} }
CTL_M2_GET("arenas.lextent.0.size", j, &lextent_size, size_t); CTL_M2_GET("arenas.lextent.0.size", j, &lextent_size, size_t);
CTL_M2_M4_GET("stats.arenas.0.lextents.0.curlextents", i, j, CTL_M2_M4_GET("stats.arenas.0.lextents.0.curlextents", i, j,
&curlextents, size_t); &curlextents, size_t);
if (json) {
malloc_cprintf(write_cb, cbopaque, emitter_json_arr_obj_begin(emitter);
"\t\t\t\t\t{\n" emitter_json_kv(emitter, "curlextents", emitter_type_size,
"\t\t\t\t\t\t\"curlextents\": %zu\n" &curlextents);
"\t\t\t\t\t}%s\n", emitter_json_arr_obj_end(emitter);
curlextents,
(j + 1 < nlextents) ? "," : ""); col_size.size_val = lextent_size;
} else if (!in_gap) { col_ind.unsigned_val = nbins + j;
malloc_cprintf(write_cb, cbopaque, col_allocated.size_val = curlextents * lextent_size;
"%20zu %3u %12zu %12"FMTu64" %12"FMTu64 col_nmalloc.uint64_val = nmalloc;
" %12"FMTu64" %12zu\n", col_ndalloc.uint64_val = ndalloc;
lextent_size, nbins + j, col_nrequests.uint64_val = nrequests;
curlextents * lextent_size, nmalloc, ndalloc, col_curlextents.size_val = curlextents;
nrequests, curlextents);
if (!in_gap) {
emitter_table_row(emitter, &row);
} }
} }
if (json) { emitter_json_arr_end(emitter); /* Close "lextents". */
malloc_cprintf(write_cb, cbopaque, if (in_gap) {
"\t\t\t\t]\n"); emitter_table_printf(emitter, " ---\n");
} else {
if (in_gap) {
malloc_cprintf(write_cb, cbopaque,
" ---\n");
}
} }
} }
@ -513,11 +536,6 @@ stats_arena_print(emitter_t *emitter, unsigned i, bool bins, bool large,
size_t tcache_bytes; size_t tcache_bytes;
uint64_t uptime; uint64_t uptime;
/* These should be removed once the emitter conversion is done. */
void (*write_cb)(void *, const char *) = emitter->write_cb;
void *cbopaque = emitter->cbopaque;
bool json = (emitter->output == emitter_output_json);
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);
@ -799,17 +817,8 @@ stats_arena_print(emitter_t *emitter, unsigned i, bool bins, bool large,
if (bins) { if (bins) {
stats_arena_bins_print(emitter, mutex, i); stats_arena_bins_print(emitter, mutex, i);
} }
/* Emitter conversion point. */
if (json) {
if (large) {
malloc_cprintf(write_cb, cbopaque, ",\n");
} else {
malloc_cprintf(write_cb, cbopaque, "\n");
}
}
if (large) { if (large) {
stats_arena_lextents_print(write_cb, cbopaque, json, i); stats_arena_lextents_print(emitter, i);
} }
} }