Stats printing: convert most per-arena stats to use the emitter.

This commit is contained in:
David Goldblatt 2018-03-05 17:58:02 -08:00 committed by David Goldblatt
parent 8fc850695d
commit 07fb707623

View File

@ -720,77 +720,53 @@ stats_arena_print(emitter_t *emitter, unsigned i, bool bins, bool large,
alloc_count_nrequests.uint64_val = small_nrequests + large_nrequests; alloc_count_nrequests.uint64_val = small_nrequests + large_nrequests;
emitter_table_row(emitter, &alloc_count_row); emitter_table_row(emitter, &alloc_count_row);
if (json) { emitter_row_t mem_count_row;
malloc_cprintf(write_cb, cbopaque, ",\n"); emitter_row_init(&mem_count_row);
}
if (!json) { emitter_col_t mem_count_title;
malloc_cprintf(write_cb, cbopaque, emitter_col_init(&mem_count_title, &mem_count_row);
"active: %12zu\n", pactive * page); mem_count_title.justify = emitter_justify_left;
} mem_count_title.width = 25;
mem_count_title.type = emitter_type_title;
mem_count_title.str_val = "";
CTL_M2_GET("stats.arenas.0.mapped", i, &mapped, size_t); emitter_col_t mem_count_val;
if (json) { emitter_col_init(&mem_count_val, &mem_count_row);
malloc_cprintf(write_cb, cbopaque, mem_count_val.justify = emitter_justify_right;
"\t\t\t\t\"mapped\": %zu,\n", mapped); mem_count_val.width = 12;
} else { mem_count_val.type = emitter_type_title;
malloc_cprintf(write_cb, cbopaque, mem_count_val.str_val = "";
"mapped: %12zu\n", mapped);
}
CTL_M2_GET("stats.arenas.0.retained", i, &retained, size_t); emitter_table_row(emitter, &mem_count_row);
if (json) { mem_count_val.type = emitter_type_size;
malloc_cprintf(write_cb, cbopaque,
"\t\t\t\t\"retained\": %zu,\n", retained);
} else {
malloc_cprintf(write_cb, cbopaque,
"retained: %12zu\n", retained);
}
CTL_M2_GET("stats.arenas.0.base", i, &base, size_t); /* Active count in bytes is emitted only in table mode. */
if (json) { mem_count_title.str_val = "active:";
malloc_cprintf(write_cb, cbopaque, mem_count_val.size_val = pactive * page;
"\t\t\t\t\"base\": %zu,\n", base); emitter_table_row(emitter, &mem_count_row);
} else {
malloc_cprintf(write_cb, cbopaque,
"base: %12zu\n", base);
}
CTL_M2_GET("stats.arenas.0.internal", i, &internal, size_t); #define GET_AND_EMIT_MEM_STAT(stat) \
if (json) { CTL_M2_GET("stats.arenas.0."#stat, i, &stat, size_t); \
malloc_cprintf(write_cb, cbopaque, emitter_json_kv(emitter, #stat, emitter_type_size, &stat); \
"\t\t\t\t\"internal\": %zu,\n", internal); mem_count_title.str_val = #stat":"; \
} else { mem_count_val.size_val = stat; \
malloc_cprintf(write_cb, cbopaque, emitter_table_row(emitter, &mem_count_row);
"internal: %12zu\n", internal);
}
CTL_M2_GET("stats.arenas.0.metadata_thp", i, &metadata_thp, size_t); GET_AND_EMIT_MEM_STAT(mapped)
if (json) { GET_AND_EMIT_MEM_STAT(retained)
malloc_cprintf(write_cb, cbopaque, GET_AND_EMIT_MEM_STAT(base)
"\t\t\t\t\"metadata_thp\": %zu,\n", metadata_thp); GET_AND_EMIT_MEM_STAT(internal)
} else { GET_AND_EMIT_MEM_STAT(metadata_thp)
malloc_cprintf(write_cb, cbopaque, GET_AND_EMIT_MEM_STAT(tcache_bytes)
"metadata_thp: %12zu\n", metadata_thp); GET_AND_EMIT_MEM_STAT(resident)
} #undef GET_AND_EMIT_MEM_STAT
CTL_M2_GET("stats.arenas.0.tcache_bytes", i, &tcache_bytes, size_t);
if (json) { if (json) {
malloc_cprintf(write_cb, cbopaque, if (bins || large || mutex) {
"\t\t\t\t\"tcache\": %zu,\n", tcache_bytes); malloc_cprintf(write_cb, cbopaque, ",\n");
} else { } else {
malloc_cprintf(write_cb, cbopaque, malloc_cprintf(write_cb, cbopaque, "\n");
"tcache: %12zu\n", tcache_bytes); }
}
CTL_M2_GET("stats.arenas.0.resident", i, &resident, size_t);
if (json) {
malloc_cprintf(write_cb, cbopaque,
"\t\t\t\t\"resident\": %zu%s\n", resident,
(bins || large || mutex) ? "," : "");
} else {
malloc_cprintf(write_cb, cbopaque,
"resident: %12zu\n", resident);
} }
if (mutex) { if (mutex) {