aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2018-03-01 17:29:58 -0800
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2018-03-09 11:47:17 -0800
commitb646f89173be53d4f5eb59a894dbcdd64b457bee (patch)
tree05609d055067aa88d4af12c9ea59d3adc14cfc52 /src
parent27a8fe6780cb901668489495b2fc302a2d071d8c (diff)
downloadplatform_external_jemalloc_new-b646f89173be53d4f5eb59a894dbcdd64b457bee.tar.gz
platform_external_jemalloc_new-b646f89173be53d4f5eb59a894dbcdd64b457bee.tar.bz2
platform_external_jemalloc_new-b646f89173be53d4f5eb59a894dbcdd64b457bee.zip
Stats printing: Convert header and footer to use emitter.
Diffstat (limited to 'src')
-rw-r--r--src/stats.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/stats.c b/src/stats.c
index 9efb9a19..c238d34a 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -4,6 +4,7 @@
#include "jemalloc/internal/assert.h"
#include "jemalloc/internal/ctl.h"
+#include "jemalloc/internal/emitter.h"
#include "jemalloc/internal/mutex.h"
#include "jemalloc/internal/mutex_prof.h"
@@ -1289,15 +1290,17 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
}
}
+ emitter_t emitter;
+ emitter_init(&emitter,
+ json ? emitter_output_json : emitter_output_table, write_cb,
+ cbopaque);
+ emitter_begin(&emitter);
+ emitter_table_printf(&emitter, "___ Begin jemalloc statistics ___\n");
+ emitter_json_dict_begin(&emitter, "jemalloc");
+
if (json) {
- malloc_cprintf(write_cb, cbopaque,
- "{\n"
- "\t\"jemalloc\": {\n");
- } else {
- malloc_cprintf(write_cb, cbopaque,
- "___ Begin jemalloc statistics ___\n");
+ malloc_cprintf(write_cb, cbopaque, "\n");
}
-
if (general) {
stats_general_print(write_cb, cbopaque, json, config_stats);
}
@@ -1306,12 +1309,7 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
unmerged, bins, large, mutex);
}
- if (json) {
- malloc_cprintf(write_cb, cbopaque,
- "\t}\n"
- "}\n");
- } else {
- malloc_cprintf(write_cb, cbopaque,
- "--- End jemalloc statistics ---\n");
- }
+ emitter_json_dict_end(&emitter); /* Closes the "jemalloc" dict. */
+ emitter_table_printf(&emitter, "--- End jemalloc statistics ---\n");
+ emitter_end(&emitter);
}