Stats printing: Make arena mutex stats use the emitter.
This commit is contained in:
parent
07fb707623
commit
a1738f4efd
168
src/stats.c
168
src/stats.c
@ -131,6 +131,52 @@ mutex_stats_init_row(emitter_row_t *row, const char *table_name,
|
|||||||
#undef WIDTH_uint64_t
|
#undef WIDTH_uint64_t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mutex_stats_read_global(const char *name, emitter_col_t *col_name,
|
||||||
|
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
|
emitter_col_t col_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
||||||
|
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
||||||
|
|
||||||
|
col_name->str_val = name;
|
||||||
|
|
||||||
|
emitter_col_t *dst;
|
||||||
|
#define EMITTER_TYPE_uint32_t emitter_type_uint32
|
||||||
|
#define EMITTER_TYPE_uint64_t emitter_type_uint64
|
||||||
|
#define OP(counter, counter_type, human) \
|
||||||
|
dst = &col_##counter_type[mutex_counter_##counter]; \
|
||||||
|
dst->type = EMITTER_TYPE_##counter_type; \
|
||||||
|
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
||||||
|
"mutexes", name, #counter); \
|
||||||
|
CTL_GET(cmd, (counter_type *)&dst->bool_val, counter_type);
|
||||||
|
MUTEX_PROF_COUNTERS
|
||||||
|
#undef OP
|
||||||
|
#undef EMITTER_TYPE_uint32_t
|
||||||
|
#undef EMITTER_TYPE_uint64_t
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mutex_stats_read_arena(unsigned arena_ind, mutex_prof_arena_ind_t mutex_ind,
|
||||||
|
const char *name, emitter_col_t *col_name,
|
||||||
|
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
|
emitter_col_t col_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
||||||
|
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
||||||
|
|
||||||
|
col_name->str_val = name;
|
||||||
|
|
||||||
|
emitter_col_t *dst;
|
||||||
|
#define EMITTER_TYPE_uint32_t emitter_type_uint32
|
||||||
|
#define EMITTER_TYPE_uint64_t emitter_type_uint64
|
||||||
|
#define OP(counter, counter_type, human) \
|
||||||
|
dst = &col_##counter_type[mutex_counter_##counter]; \
|
||||||
|
dst->type = EMITTER_TYPE_##counter_type; \
|
||||||
|
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
||||||
|
"arenas.0.mutexes", arena_mutex_names[mutex_ind], #counter);\
|
||||||
|
CTL_M2_GET(cmd, arena_ind, \
|
||||||
|
(counter_type *)&dst->bool_val, counter_type);
|
||||||
|
MUTEX_PROF_COUNTERS
|
||||||
|
#undef OP
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mutex_stats_emit(emitter_t *emitter, emitter_row_t *row,
|
mutex_stats_emit(emitter_t *emitter, emitter_row_t *row,
|
||||||
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
@ -392,76 +438,27 @@ stats_arena_lextents_print(void (*write_cb)(void *, const char *),
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_arena_mutex_stats(unsigned arena_ind,
|
stats_arena_mutexes_print(emitter_t *emitter, unsigned arena_ind) {
|
||||||
uint64_t results_uint64_t[mutex_prof_num_arena_mutexes][mutex_prof_num_uint64_t_counters],
|
emitter_row_t row;
|
||||||
uint32_t results_uint32_t[mutex_prof_num_arena_mutexes][mutex_prof_num_uint32_t_counters]) {
|
emitter_col_t col_name;
|
||||||
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
emitter_col_t col64[mutex_prof_num_uint64_t_counters];
|
||||||
|
emitter_col_t col32[mutex_prof_num_uint32_t_counters];
|
||||||
|
|
||||||
mutex_prof_arena_ind_t i;
|
mutex_stats_init_row(&row, "", &col_name, col64, col32);
|
||||||
for (i = 0; i < mutex_prof_num_arena_mutexes; i++) {
|
|
||||||
#define OP(c, t, human) \
|
emitter_json_dict_begin(emitter, "mutexes");
|
||||||
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
emitter_table_row(emitter, &row);
|
||||||
"arenas.0.mutexes", arena_mutex_names[i], #c); \
|
|
||||||
CTL_M2_GET(cmd, arena_ind, \
|
for (mutex_prof_arena_ind_t i = 0; i < mutex_prof_num_arena_mutexes;
|
||||||
(t *)&results_##t[i][mutex_counter_##c], t);
|
i++) {
|
||||||
MUTEX_PROF_COUNTERS
|
const char *name = arena_mutex_names[i];
|
||||||
#undef OP
|
emitter_json_dict_begin(emitter, name);
|
||||||
}
|
mutex_stats_read_arena(arena_ind, i, name, &col_name, col64,
|
||||||
}
|
col32);
|
||||||
|
mutex_stats_emit(emitter, &row, col64, col32);
|
||||||
static void
|
emitter_json_dict_end(emitter); /* Close the mutex dict. */
|
||||||
mutex_stats_output(void (*write_cb)(void *, const char *), void *cbopaque,
|
|
||||||
const char *name, uint64_t stats_uint64_t[mutex_prof_num_uint64_t_counters],
|
|
||||||
uint32_t stats_uint32_t[mutex_prof_num_uint32_t_counters],
|
|
||||||
bool first_mutex) {
|
|
||||||
if (first_mutex) {
|
|
||||||
/* Print title. */
|
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
|
||||||
" n_lock_ops n_waiting"
|
|
||||||
" n_spin_acq n_owner_switch total_wait_ns"
|
|
||||||
" max_wait_ns max_n_thds\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
malloc_cprintf(write_cb, cbopaque, "%s", name);
|
|
||||||
malloc_cprintf(write_cb, cbopaque, ":%*c",
|
|
||||||
(int)(20 - strlen(name)), ' ');
|
|
||||||
|
|
||||||
char *fmt_str[2] = {"%12"FMTu32, "%16"FMTu64};
|
|
||||||
#define OP(c, t, human) \
|
|
||||||
malloc_cprintf(write_cb, cbopaque, \
|
|
||||||
fmt_str[sizeof(t) / sizeof(uint32_t) - 1], \
|
|
||||||
(t)stats_##t[mutex_counter_##c]);
|
|
||||||
MUTEX_PROF_COUNTERS
|
|
||||||
#undef OP
|
|
||||||
malloc_cprintf(write_cb, cbopaque, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
stats_arena_mutexes_print(void (*write_cb)(void *, const char *),
|
|
||||||
void *cbopaque, bool json, bool json_end, unsigned arena_ind) {
|
|
||||||
uint64_t mutex_stats_64[mutex_prof_num_arena_mutexes][mutex_prof_num_uint64_t_counters];
|
|
||||||
uint32_t mutex_stats_32[mutex_prof_num_arena_mutexes][mutex_prof_num_uint32_t_counters];
|
|
||||||
read_arena_mutex_stats(arena_ind, mutex_stats_64, mutex_stats_32);
|
|
||||||
|
|
||||||
/* Output mutex stats. */
|
|
||||||
if (json) {
|
|
||||||
malloc_cprintf(write_cb, cbopaque, "\t\t\t\t\"mutexes\": {\n");
|
|
||||||
mutex_prof_arena_ind_t i, last_mutex;
|
|
||||||
last_mutex = mutex_prof_num_arena_mutexes - 1;
|
|
||||||
for (i = 0; i < mutex_prof_num_arena_mutexes; i++) {
|
|
||||||
mutex_stats_output_json(write_cb, cbopaque,
|
|
||||||
arena_mutex_names[i], mutex_stats_64[i], mutex_stats_32[i],
|
|
||||||
"\t\t\t\t\t", (i == last_mutex));
|
|
||||||
}
|
|
||||||
malloc_cprintf(write_cb, cbopaque, "\t\t\t\t}%s\n",
|
|
||||||
json_end ? "" : ",");
|
|
||||||
} else {
|
|
||||||
mutex_prof_arena_ind_t i;
|
|
||||||
for (i = 0; i < mutex_prof_num_arena_mutexes; i++) {
|
|
||||||
mutex_stats_output(write_cb, cbopaque,
|
|
||||||
arena_mutex_names[i], mutex_stats_64[i], mutex_stats_32[i], i == 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
emitter_json_dict_end(emitter); /* End "mutexes". */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -761,18 +758,19 @@ stats_arena_print(emitter_t *emitter, unsigned i, bool bins, bool large,
|
|||||||
GET_AND_EMIT_MEM_STAT(resident)
|
GET_AND_EMIT_MEM_STAT(resident)
|
||||||
#undef GET_AND_EMIT_MEM_STAT
|
#undef GET_AND_EMIT_MEM_STAT
|
||||||
|
|
||||||
|
if (mutex) {
|
||||||
|
stats_arena_mutexes_print(emitter, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Emitter conversion point. */
|
||||||
if (json) {
|
if (json) {
|
||||||
if (bins || large || mutex) {
|
if (bins || large) {
|
||||||
malloc_cprintf(write_cb, cbopaque, ",\n");
|
malloc_cprintf(write_cb, cbopaque, ",\n");
|
||||||
} else {
|
} else {
|
||||||
malloc_cprintf(write_cb, cbopaque, "\n");
|
malloc_cprintf(write_cb, cbopaque, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mutex) {
|
|
||||||
stats_arena_mutexes_print(write_cb, cbopaque, json,
|
|
||||||
!(bins || large), i);
|
|
||||||
}
|
|
||||||
if (bins) {
|
if (bins) {
|
||||||
stats_arena_bins_print(write_cb, cbopaque, json, large, mutex,
|
stats_arena_bins_print(write_cb, cbopaque, json, large, mutex,
|
||||||
i);
|
i);
|
||||||
@ -1020,29 +1018,6 @@ stats_general_print(emitter_t *emitter) {
|
|||||||
emitter_json_dict_end(emitter); /* Close "arenas" */
|
emitter_json_dict_end(emitter); /* Close "arenas" */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
mutex_stats_read_global(const char *name, emitter_col_t *col_name,
|
|
||||||
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
|
||||||
emitter_col_t col_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
|
||||||
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
|
||||||
|
|
||||||
col_name->str_val = name;
|
|
||||||
|
|
||||||
emitter_col_t *dst;
|
|
||||||
#define EMITTER_TYPE_uint32_t emitter_type_uint32
|
|
||||||
#define EMITTER_TYPE_uint64_t emitter_type_uint64
|
|
||||||
#define OP(counter, counter_type, human) \
|
|
||||||
dst = &col_##counter_type[mutex_counter_##counter]; \
|
|
||||||
dst->type = EMITTER_TYPE_##counter_type; \
|
|
||||||
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
|
||||||
"mutexes", name, #counter); \
|
|
||||||
CTL_GET(cmd, (counter_type *)&dst->bool_val, counter_type);
|
|
||||||
MUTEX_PROF_COUNTERS
|
|
||||||
#undef OP
|
|
||||||
#undef EMITTER_TYPE_uint32_t
|
|
||||||
#undef EMITTER_TYPE_uint64_t
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
||||||
bool unmerged, bool bins, bool large, bool mutex) {
|
bool unmerged, bool bins, bool large, bool mutex) {
|
||||||
@ -1198,7 +1173,6 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emitter_json_dict_end(emitter); /* Close "stats.arenas". */
|
emitter_json_dict_end(emitter); /* Close "stats.arenas". */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user