From b5674540ed07fd0a2c731b6cc34915de3b6e74e5 Mon Sep 17 00:00:00 2001 From: Hongyu Chen Date: Thu, 5 Feb 2015 12:18:05 -0800 Subject: [PATCH] Update following a-vietch's comments --- src/core/statistics/census_tracing.c | 29 +++++++++++++++++----------- src/core/statistics/census_tracing.h | 8 ++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/core/statistics/census_tracing.c b/src/core/statistics/census_tracing.c index ddf925cc47b..4c030152e6e 100644 --- a/src/core/statistics/census_tracing.c +++ b/src/core/statistics/census_tracing.c @@ -45,9 +45,9 @@ #include void trace_obj_destroy(trace_obj* obj) { - annotation* p = obj->annotations; + trace_annotation* p = obj->annotations; while (p != NULL) { - annotation* next = p->next; + trace_annotation* next = p->next; gpr_free(p); p = next; } @@ -119,7 +119,7 @@ void census_tracing_print(census_op_id op_id, const char* anno_txt) { gpr_mu_lock(&g_mu); trace = census_ht_find(g_trace_store, op_id_as_key(&op_id)); if (trace != NULL) { - annotation* anno = gpr_malloc(sizeof(annotation)); + trace_annotation* anno = gpr_malloc(sizeof(trace_annotation)); anno->ts = gpr_now(); { char* d = anno->txt; @@ -189,15 +189,22 @@ trace_obj* census_get_trace_obj_locked(census_op_id op_id) { } const char* census_get_trace_method_name(const trace_obj* trace) { - return (const char*)trace->method; + return trace->method; } -static annotation* dup_annotation_chain(annotation* from) { - annotation* to = NULL; - if (from != NULL) { - to = gpr_malloc(sizeof(annotation)); - memcpy(to, from, sizeof(annotation)); - to->next = dup_annotation_chain(from->next); +static trace_annotation* dup_annotation_chain(trace_annotation* from) { + trace_annotation *to = NULL, *prev = NULL; + for (; from != NULL; from = from->next) { + trace_annotation* tmp = gpr_malloc(sizeof(trace_annotation)); + memcpy(tmp, from, sizeof(trace_annotation)); + tmp->next = NULL; + if (to == NULL) { + to = tmp; + prev = to; + } else { + prev->next = tmp; + prev = tmp; + } } return to; } @@ -220,7 +227,7 @@ trace_obj** census_get_active_ops(int* num_active_ops) { if (g_trace_store != NULL) { size_t n = 0; census_ht_kv* all_kvs = census_ht_get_all_elements(g_trace_store, &n); - *num_active_ops = n; + *num_active_ops = (int)n; if (n != 0 ) { size_t i = 0; ret = gpr_malloc(sizeof(trace_obj *) * n); diff --git a/src/core/statistics/census_tracing.h b/src/core/statistics/census_tracing.h index 58333f7f6b8..fa0e087053f 100644 --- a/src/core/statistics/census_tracing.h +++ b/src/core/statistics/census_tracing.h @@ -47,18 +47,18 @@ extern "C" { #endif /* Struct for a trace annotation. */ -typedef struct annotation { +typedef struct trace_annotation { gpr_timespec ts; /* timestamp of the annotation */ char txt[CENSUS_MAX_ANNOTATION_LENGTH + 1]; /* actual txt annotation */ - struct annotation* next; -} annotation; + struct trace_annotation* next; +} trace_annotation; typedef struct trace_obj { census_op_id id; gpr_timespec ts; census_rpc_stats rpc_stats; char* method; - annotation* annotations; + trace_annotation* annotations; } trace_obj; /* Deletes trace object. */