Stats printing: Move global mutex stats to use emitter.
This commit is contained in:
parent
ebe0b5f828
commit
86c61d4a57
@ -35,27 +35,27 @@ typedef enum {
|
|||||||
mutex_prof_num_arena_mutexes
|
mutex_prof_num_arena_mutexes
|
||||||
} mutex_prof_arena_ind_t;
|
} mutex_prof_arena_ind_t;
|
||||||
|
|
||||||
#define MUTEX_PROF_UINT64_COUNTERS \
|
#define MUTEX_PROF_UINT64_COUNTERS \
|
||||||
OP(num_ops, uint64_t) \
|
OP(num_ops, uint64_t, "n_lock_ops") \
|
||||||
OP(num_wait, uint64_t) \
|
OP(num_wait, uint64_t, "n_waiting") \
|
||||||
OP(num_spin_acq, uint64_t) \
|
OP(num_spin_acq, uint64_t, "n_spin_acq") \
|
||||||
OP(num_owner_switch, uint64_t) \
|
OP(num_owner_switch, uint64_t, "n_owner_switch") \
|
||||||
OP(total_wait_time, uint64_t) \
|
OP(total_wait_time, uint64_t, "total_wait_ns") \
|
||||||
OP(max_wait_time, uint64_t)
|
OP(max_wait_time, uint64_t, "max_wait_ns")
|
||||||
|
|
||||||
#define MUTEX_PROF_UINT32_COUNTERS \
|
#define MUTEX_PROF_UINT32_COUNTERS \
|
||||||
OP(max_num_thds, uint32_t)
|
OP(max_num_thds, uint32_t, "max_n_thds")
|
||||||
|
|
||||||
#define MUTEX_PROF_COUNTERS \
|
#define MUTEX_PROF_COUNTERS \
|
||||||
MUTEX_PROF_UINT64_COUNTERS \
|
MUTEX_PROF_UINT64_COUNTERS \
|
||||||
MUTEX_PROF_UINT32_COUNTERS
|
MUTEX_PROF_UINT32_COUNTERS
|
||||||
|
|
||||||
#define OP(counter, type) mutex_counter_##counter,
|
#define OP(counter, type, human) mutex_counter_##counter,
|
||||||
|
|
||||||
#define COUNTER_ENUM(counter_list, t) \
|
#define COUNTER_ENUM(counter_list, t) \
|
||||||
typedef enum { \
|
typedef enum { \
|
||||||
counter_list \
|
counter_list \
|
||||||
mutex_prof_num_##t##_counters \
|
mutex_prof_num_##t##_counters \
|
||||||
} mutex_prof_##t##_counter_ind_t;
|
} mutex_prof_##t##_counter_ind_t;
|
||||||
|
|
||||||
COUNTER_ENUM(MUTEX_PROF_UINT64_COUNTERS, uint64_t)
|
COUNTER_ENUM(MUTEX_PROF_UINT64_COUNTERS, uint64_t)
|
||||||
|
140
src/stats.c
140
src/stats.c
@ -89,7 +89,7 @@ read_arena_bin_mutex_stats(unsigned arena_ind, unsigned bin_ind,
|
|||||||
uint64_t results_uint64_t[mutex_prof_num_uint64_t_counters],
|
uint64_t results_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
uint32_t results_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
uint32_t results_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
||||||
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
||||||
#define OP(c, t) \
|
#define OP(c, t, human) \
|
||||||
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
||||||
"arenas.0.bins.0","mutex", #c); \
|
"arenas.0.bins.0","mutex", #c); \
|
||||||
CTL_M2_M4_GET(cmd, arena_ind, bin_ind, \
|
CTL_M2_M4_GET(cmd, arena_ind, bin_ind, \
|
||||||
@ -98,6 +98,63 @@ read_arena_bin_mutex_stats(unsigned arena_ind, unsigned bin_ind,
|
|||||||
#undef OP
|
#undef OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mutex_stats_init_row(emitter_row_t *row, const char *table_name,
|
||||||
|
emitter_col_t *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]) {
|
||||||
|
mutex_prof_uint64_t_counter_ind_t k_uint64_t = 0;
|
||||||
|
mutex_prof_uint32_t_counter_ind_t k_uint32_t = 0;
|
||||||
|
|
||||||
|
emitter_col_t *col;
|
||||||
|
|
||||||
|
emitter_row_init(row);
|
||||||
|
emitter_col_init(name, row);
|
||||||
|
name->justify = emitter_justify_left;
|
||||||
|
name->width = 21;
|
||||||
|
name->type = emitter_type_title;
|
||||||
|
name->str_val = table_name;
|
||||||
|
|
||||||
|
#define WIDTH_uint32_t 12
|
||||||
|
#define WIDTH_uint64_t 16
|
||||||
|
#define OP(counter, counter_type, human) \
|
||||||
|
col = &col_##counter_type[k_##counter_type]; \
|
||||||
|
++k_##counter_type; \
|
||||||
|
emitter_col_init(col, row); \
|
||||||
|
col->justify = emitter_justify_right; \
|
||||||
|
col->width = WIDTH_##counter_type; \
|
||||||
|
col->type = emitter_type_title; \
|
||||||
|
col->str_val = human;
|
||||||
|
MUTEX_PROF_COUNTERS
|
||||||
|
#undef OP
|
||||||
|
#undef WIDTH_uint32_t
|
||||||
|
#undef WIDTH_uint64_t
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
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_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
||||||
|
emitter_table_row(emitter, row);
|
||||||
|
|
||||||
|
mutex_prof_uint64_t_counter_ind_t k_uint64_t = 0;
|
||||||
|
mutex_prof_uint32_t_counter_ind_t k_uint32_t = 0;
|
||||||
|
|
||||||
|
emitter_col_t *col;
|
||||||
|
|
||||||
|
#define EMITTER_TYPE_uint32_t emitter_type_uint32
|
||||||
|
#define EMITTER_TYPE_uint64_t emitter_type_uint64
|
||||||
|
#define OP(counter, type, human) \
|
||||||
|
col = &col_##type[k_##type]; \
|
||||||
|
++k_##type; \
|
||||||
|
emitter_json_kv(emitter, #counter, EMITTER_TYPE_##type, \
|
||||||
|
(const void *)&col->bool_val);
|
||||||
|
MUTEX_PROF_COUNTERS;
|
||||||
|
#undef OP
|
||||||
|
#undef EMITTER_TYPE_uint32_t
|
||||||
|
#undef EMITTER_TYPE_uint64_t
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mutex_stats_output_json(void (*write_cb)(void *, const char *), void *cbopaque,
|
mutex_stats_output_json(void (*write_cb)(void *, const char *), void *cbopaque,
|
||||||
const char *name, uint64_t stats_uint64_t[mutex_prof_num_uint64_t_counters],
|
const char *name, uint64_t stats_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
@ -109,7 +166,7 @@ mutex_stats_output_json(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
mutex_prof_uint32_t_counter_ind_t k_uint32_t = 0;
|
mutex_prof_uint32_t_counter_ind_t k_uint32_t = 0;
|
||||||
char *fmt_str[2] = {"%s\t\"%s\": %"FMTu32"%s\n",
|
char *fmt_str[2] = {"%s\t\"%s\": %"FMTu32"%s\n",
|
||||||
"%s\t\"%s\": %"FMTu64"%s\n"};
|
"%s\t\"%s\": %"FMTu64"%s\n"};
|
||||||
#define OP(c, t) \
|
#define OP(c, t, human) \
|
||||||
malloc_cprintf(write_cb, cbopaque, \
|
malloc_cprintf(write_cb, cbopaque, \
|
||||||
fmt_str[sizeof(t) / sizeof(uint32_t) - 1], \
|
fmt_str[sizeof(t) / sizeof(uint32_t) - 1], \
|
||||||
json_indent, #c, (t)stats_##t[mutex_counter_##c], \
|
json_indent, #c, (t)stats_##t[mutex_counter_##c], \
|
||||||
@ -342,7 +399,7 @@ read_arena_mutex_stats(unsigned arena_ind,
|
|||||||
|
|
||||||
mutex_prof_arena_ind_t i;
|
mutex_prof_arena_ind_t i;
|
||||||
for (i = 0; i < mutex_prof_num_arena_mutexes; i++) {
|
for (i = 0; i < mutex_prof_num_arena_mutexes; i++) {
|
||||||
#define OP(c, t) \
|
#define OP(c, t, human) \
|
||||||
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
||||||
"arenas.0.mutexes", arena_mutex_names[i], #c); \
|
"arenas.0.mutexes", arena_mutex_names[i], #c); \
|
||||||
CTL_M2_GET(cmd, arena_ind, \
|
CTL_M2_GET(cmd, arena_ind, \
|
||||||
@ -370,7 +427,7 @@ mutex_stats_output(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
(int)(20 - strlen(name)), ' ');
|
(int)(20 - strlen(name)), ' ');
|
||||||
|
|
||||||
char *fmt_str[2] = {"%12"FMTu32, "%16"FMTu64};
|
char *fmt_str[2] = {"%12"FMTu32, "%16"FMTu64};
|
||||||
#define OP(c, t) \
|
#define OP(c, t, human) \
|
||||||
malloc_cprintf(write_cb, cbopaque, \
|
malloc_cprintf(write_cb, cbopaque, \
|
||||||
fmt_str[sizeof(t) / sizeof(uint32_t) - 1], \
|
fmt_str[sizeof(t) / sizeof(uint32_t) - 1], \
|
||||||
(t)stats_##t[mutex_counter_##c]);
|
(t)stats_##t[mutex_counter_##c]);
|
||||||
@ -906,20 +963,26 @@ stats_general_print(emitter_t *emitter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_global_mutex_stats(
|
mutex_stats_read_global(const char *name, emitter_col_t *col_name,
|
||||||
uint64_t results_uint64_t[mutex_prof_num_global_mutexes][mutex_prof_num_uint64_t_counters],
|
emitter_col_t col_uint64_t[mutex_prof_num_uint64_t_counters],
|
||||||
uint32_t results_uint32_t[mutex_prof_num_global_mutexes][mutex_prof_num_uint32_t_counters]) {
|
emitter_col_t col_uint32_t[mutex_prof_num_uint32_t_counters]) {
|
||||||
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
char cmd[MUTEX_CTL_STR_MAX_LENGTH];
|
||||||
|
|
||||||
mutex_prof_global_ind_t i;
|
col_name->str_val = name;
|
||||||
for (i = 0; i < mutex_prof_num_global_mutexes; i++) {
|
|
||||||
#define OP(c, t) \
|
emitter_col_t *dst;
|
||||||
gen_mutex_ctl_str(cmd, MUTEX_CTL_STR_MAX_LENGTH, \
|
#define EMITTER_TYPE_uint32_t emitter_type_uint32
|
||||||
"mutexes", global_mutex_names[i], #c); \
|
#define EMITTER_TYPE_uint64_t emitter_type_uint64
|
||||||
CTL_GET(cmd, (t *)&results_##t[i][mutex_counter_##c], t);
|
#define OP(counter, counter_type, human) \
|
||||||
MUTEX_PROF_COUNTERS
|
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 OP
|
||||||
}
|
#undef EMITTER_TYPE_uint32_t
|
||||||
|
#undef EMITTER_TYPE_uint64_t
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -946,12 +1009,6 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
|||||||
CTL_GET("stats.mapped", &mapped, size_t);
|
CTL_GET("stats.mapped", &mapped, size_t);
|
||||||
CTL_GET("stats.retained", &retained, size_t);
|
CTL_GET("stats.retained", &retained, size_t);
|
||||||
|
|
||||||
uint64_t mutex_stats_uint64_t[mutex_prof_num_global_mutexes][mutex_prof_num_uint64_t_counters];
|
|
||||||
uint32_t mutex_stats_uint32_t[mutex_prof_num_global_mutexes][mutex_prof_num_uint32_t_counters];
|
|
||||||
if (mutex) {
|
|
||||||
read_global_mutex_stats(mutex_stats_uint64_t, mutex_stats_uint32_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (have_background_thread) {
|
if (have_background_thread) {
|
||||||
CTL_GET("stats.background_thread.num_threads",
|
CTL_GET("stats.background_thread.num_threads",
|
||||||
&num_background_threads, size_t);
|
&num_background_threads, size_t);
|
||||||
@ -996,29 +1053,26 @@ stats_print_helper(emitter_t *emitter, bool merged, bool destroyed,
|
|||||||
num_background_threads, background_thread_num_runs,
|
num_background_threads, background_thread_num_runs,
|
||||||
background_thread_run_interval);
|
background_thread_run_interval);
|
||||||
|
|
||||||
if (json) {
|
if (mutex) {
|
||||||
if (mutex) {
|
emitter_row_t row;
|
||||||
malloc_cprintf(write_cb, cbopaque, ",\n");
|
emitter_col_t name;
|
||||||
malloc_cprintf(write_cb, cbopaque,
|
emitter_col_t col64[mutex_prof_num_uint64_t_counters];
|
||||||
"\t\t\t\"mutexes\": {\n");
|
emitter_col_t col32[mutex_prof_num_uint32_t_counters];
|
||||||
mutex_prof_global_ind_t i;
|
|
||||||
for (i = 0; i < mutex_prof_num_global_mutexes; i++) {
|
mutex_stats_init_row(&row, "", &name, col64, col32);
|
||||||
mutex_stats_output_json(write_cb, cbopaque,
|
|
||||||
global_mutex_names[i], mutex_stats_uint64_t[i], mutex_stats_uint32_t[i],
|
emitter_table_row(emitter, &row);
|
||||||
"\t\t\t\t",
|
emitter_json_dict_begin(emitter, "mutexes");
|
||||||
i == mutex_prof_num_global_mutexes - 1);
|
|
||||||
}
|
for (int i = 0; i < mutex_prof_num_global_mutexes; i++) {
|
||||||
malloc_cprintf(write_cb, cbopaque, "\t\t\t}");
|
mutex_stats_read_global(global_mutex_names[i], &name,
|
||||||
}
|
col64, col32);
|
||||||
} else {
|
emitter_json_dict_begin(emitter, global_mutex_names[i]);
|
||||||
if (mutex) {
|
mutex_stats_emit(emitter, &row, col64, col32);
|
||||||
mutex_prof_global_ind_t i;
|
emitter_json_dict_end(emitter);
|
||||||
for (i = 0; i < mutex_prof_num_global_mutexes; i++) {
|
|
||||||
mutex_stats_output(write_cb, cbopaque,
|
|
||||||
global_mutex_names[i], mutex_stats_uint64_t[i], mutex_stats_uint32_t[i],
|
|
||||||
i == 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitter_json_dict_end(emitter); /* Close "mutexes". */
|
||||||
}
|
}
|
||||||
|
|
||||||
emitter_json_dict_end(emitter); /* Close "stats". */
|
emitter_json_dict_end(emitter); /* Close "stats". */
|
||||||
|
Loading…
Reference in New Issue
Block a user