|
|
@ -29,40 +29,31 @@ int grpc_tracer_set_enabled(const char* name, int enabled); |
|
|
|
|
|
|
|
|
|
|
|
namespace grpc_core { |
|
|
|
namespace grpc_core { |
|
|
|
|
|
|
|
|
|
|
|
// there is only ever one global list of tracers for the entire program.
|
|
|
|
TraceFlagList* TraceFlagList::instance_ = nullptr; |
|
|
|
static TraceFlag* g_root_tracer = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flags register themselves on the list during construction
|
|
|
|
TraceFlagList* TraceFlagList::Get() { |
|
|
|
TraceFlag::TraceFlag(bool default_enabled, const char* name) |
|
|
|
if (instance_ == nullptr) |
|
|
|
: next_tracer_(g_root_tracer), name_(name), value_(default_enabled) { |
|
|
|
instance_ = static_cast<TraceFlagList*>(gpr_malloc(sizeof(TraceFlagList))); |
|
|
|
g_root_tracer = this; |
|
|
|
return instance_; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TraceFlag::LogAllTracers() { |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "available tracers:"); |
|
|
|
|
|
|
|
TraceFlag* t; |
|
|
|
|
|
|
|
for (t = g_root_tracer; t != nullptr; t = t->next_tracer_) { |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "\t%s", t->name_); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool TraceFlag::Set(const char* name, bool enabled) { |
|
|
|
bool TraceFlagList::Set(const char* name, bool enabled) { |
|
|
|
TraceFlag* t; |
|
|
|
TraceFlag* t; |
|
|
|
if (0 == strcmp(name, "all")) { |
|
|
|
if (0 == strcmp(name, "all")) { |
|
|
|
for (t = g_root_tracer; t; t = t->next_tracer_) { |
|
|
|
for (t = root_tracer_; t; t = t->next_tracer_) { |
|
|
|
t->set_enabled(enabled); |
|
|
|
t->set_enabled(enabled); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (0 == strcmp(name, "list_tracers")) { |
|
|
|
} else if (0 == strcmp(name, "list_tracers")) { |
|
|
|
LogAllTracers(); |
|
|
|
LogAllTracers(); |
|
|
|
} else if (0 == strcmp(name, "refcount")) { |
|
|
|
} else if (0 == strcmp(name, "refcount")) { |
|
|
|
for (t = g_root_tracer; t; t = t->next_tracer_) { |
|
|
|
for (t = root_tracer_; t; t = t->next_tracer_) { |
|
|
|
if (strstr(t->name_, "refcount") != nullptr) { |
|
|
|
if (strstr(t->name_, "refcount") != nullptr) { |
|
|
|
t->set_enabled(enabled); |
|
|
|
t->set_enabled(enabled); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bool found = false; |
|
|
|
bool found = false; |
|
|
|
for (t = g_root_tracer; t; t = t->next_tracer_) { |
|
|
|
for (t = root_tracer_; t; t = t->next_tracer_) { |
|
|
|
if (0 == strcmp(name, t->name_)) { |
|
|
|
if (0 == strcmp(name, t->name_)) { |
|
|
|
t->set_enabled(enabled); |
|
|
|
t->set_enabled(enabled); |
|
|
|
found = true; |
|
|
|
found = true; |
|
|
@ -76,6 +67,25 @@ bool TraceFlag::Set(const char* name, bool enabled) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TraceFlagList::Add(TraceFlag* flag) { |
|
|
|
|
|
|
|
flag->next_tracer_ = root_tracer_; |
|
|
|
|
|
|
|
root_tracer_ = flag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TraceFlagList::LogAllTracers() { |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "available tracers:"); |
|
|
|
|
|
|
|
TraceFlag* t; |
|
|
|
|
|
|
|
for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { |
|
|
|
|
|
|
|
gpr_log(GPR_DEBUG, "\t%s", t->name_); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Flags register themselves on the list during construction
|
|
|
|
|
|
|
|
TraceFlag::TraceFlag(bool default_enabled, const char* name) |
|
|
|
|
|
|
|
: name_(name), value_(default_enabled) { |
|
|
|
|
|
|
|
TraceFlagList::Get()->Add(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace grpc_core
|
|
|
|
} // namespace grpc_core
|
|
|
|
|
|
|
|
|
|
|
|
static void add(const char* beg, const char* end, char*** ss, size_t* ns) { |
|
|
|
static void add(const char* beg, const char* end, char*** ss, size_t* ns) { |
|
|
@ -111,9 +121,9 @@ static void parse(const char* s) { |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrings; i++) { |
|
|
|
for (i = 0; i < nstrings; i++) { |
|
|
|
if (strings[i][0] == '-') { |
|
|
|
if (strings[i][0] == '-') { |
|
|
|
grpc_core::TraceFlag::Set(strings[i] + 1, false); |
|
|
|
grpc_core::TraceFlagList::Get()->Set(strings[i] + 1, false); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc_core::TraceFlag::Set(strings[i], true); |
|
|
|
grpc_core::TraceFlagList::Get()->Set(strings[i], true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -134,5 +144,5 @@ void grpc_tracer_init(const char* env_var) { |
|
|
|
void grpc_tracer_shutdown(void) {} |
|
|
|
void grpc_tracer_shutdown(void) {} |
|
|
|
|
|
|
|
|
|
|
|
int grpc_tracer_set_enabled(const char* name, int enabled) { |
|
|
|
int grpc_tracer_set_enabled(const char* name, int enabled) { |
|
|
|
return grpc_core::TraceFlag::Set(name, enabled != 0); |
|
|
|
return grpc_core::TraceFlagList::Get()->Set(name, enabled != 0); |
|
|
|
} |
|
|
|
} |
|
|
|