static void record_stats(census_ht* store, census_op_id op_id, const census_rpc_stats* stats) { gpr_mu_lock(&g_mu); if (store != NULL) { census_trace_obj* trace = NULL; census_internal_lock_trace_store(); trace = census_get_trace_obj_locked(op_id); if (trace != NULL) { const char* method_name = census_get_trace_method_name(trace); struct census_window_stats* window_stats = NULL; census_ht_key key; key.ptr = (void*)method_name; window_stats = census_ht_find(store, key); census_internal_unlock_trace_store(); if (window_stats == NULL) { window_stats = census_window_stats_create(3, min_hour_total_intervals, 30, &window_stats_settings); key.ptr = gpr_strdup(key.ptr); census_ht_insert(store, key, (void*)window_stats); } census_window_stats_add(window_stats, gpr_now(GPR_CLOCK_REALTIME), stats); } else { census_internal_unlock_trace_store(); } } gpr_mu_unlock(&g_mu); }
static void test_get_trace_method_name(void) { census_op_id id; const char write_name[] = "service/method"; census_tracing_init(); id = census_tracing_start_op(); census_add_method_tag(id, write_name); census_internal_lock_trace_store(); { const char* read_name = census_get_trace_method_name(census_get_trace_obj_locked(id)); GPR_ASSERT(strcmp(read_name, write_name) == 0); } census_internal_unlock_trace_store(); census_tracing_shutdown(); }