Skip to content
Snippets Groups Projects
Commit af7abf92 authored by Craig Tiller's avatar Craig Tiller
Browse files

Enable runtime configuration of tracers

parent 8507e150
No related branches found
No related tags found
No related merge requests found
...@@ -524,6 +524,16 @@ void grpc_server_shutdown_and_notify(grpc_server *server, void *tag); ...@@ -524,6 +524,16 @@ void grpc_server_shutdown_and_notify(grpc_server *server, void *tag);
Implies grpc_server_shutdown() if one was not previously performed. */ Implies grpc_server_shutdown() if one was not previously performed. */
void grpc_server_destroy(grpc_server *server); void grpc_server_destroy(grpc_server *server);
/** Enable or disable a tracer.
Tracers (usually controlled by the environment variable GRPC_TRACE)
allow printf-style debugging on GRPC internals, and are useful for
tracking down problems in the field.
Use of this function is not strictly thread-safe, but the
thread-safety issues raised by it should not be of concern. */
int grpc_tracer_set_enabled(const char *name, int enabled);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <string.h> #include <string.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/support/env.h" #include "src/core/support/env.h"
...@@ -80,27 +81,10 @@ static void parse(const char *s) { ...@@ -80,27 +81,10 @@ static void parse(const char *s) {
char **strings = NULL; char **strings = NULL;
size_t nstrings = 0; size_t nstrings = 0;
size_t i; size_t i;
tracer *t;
split(s, &strings, &nstrings); split(s, &strings, &nstrings);
for (i = 0; i < nstrings; i++) { for (i = 0; i < nstrings; i++) {
const char *s = strings[i]; grpc_tracer_set_enabled(strings[i], 1);
if (0 == strcmp(s, "all")) {
for (t = tracers; t; t = t->next) {
*t->flag = 1;
}
} else {
int found = 0;
for (t = tracers; t; t = t->next) {
if (0 == strcmp(s, t->name)) {
*t->flag = 1;
found = 1;
}
}
if (!found) {
gpr_log(GPR_ERROR, "Unknown trace var: '%s'", s);
}
}
} }
for (i = 0; i < nstrings; i++) { for (i = 0; i < nstrings; i++) {
...@@ -121,3 +105,25 @@ void grpc_tracer_init(const char *env_var) { ...@@ -121,3 +105,25 @@ void grpc_tracer_init(const char *env_var) {
gpr_free(t); gpr_free(t);
} }
} }
int grpc_tracer_set_enabled(const char *name, int enabled) {
tracer *t;
if (0 == strcmp(name, "all")) {
for (t = tracers; t; t = t->next) {
*t->flag = 1;
}
} else {
int found = 0;
for (t = tracers; t; t = t->next) {
if (0 == strcmp(name, t->name)) {
*t->flag = enabled;
found = 1;
}
}
if (!found) {
gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
return 0; /* early return */
}
}
return 1;
}
...@@ -147,6 +147,10 @@ int main(int argc, char **argv) { ...@@ -147,6 +147,10 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv); grpc_test_init(argc, argv);
grpc_init(); grpc_init();
GPR_ASSERT(0 == grpc_tracer_set_enabled("also-doesnt-exist", 0));
GPR_ASSERT(1 == grpc_tracer_set_enabled("http", 1));
GPR_ASSERT(1 == grpc_tracer_set_enabled("all", 1));
for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
grpc_end2end_tests(configs[i]); grpc_end2end_tests(configs[i]);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment