Skip to content
Snippets Groups Projects
Commit 96f1e5a0 authored by Hongyu Chen's avatar Hongyu Chen
Browse files

Merge pull request #2669 from a-veitch/init_api_fix

Enrich census initialization and feature code
parents ef4aac6d a4c4d3c4
No related branches found
No related tags found
No related merge requests found
...@@ -44,26 +44,30 @@ ...@@ -44,26 +44,30 @@
extern "C" { extern "C" {
#endif #endif
/* Identify census functionality that can be enabled via census_initialize(). */ /* Identify census features that can be enabled via census_initialize(). */
enum census_functions { enum census_features {
CENSUS_NONE = 0, /* Do not enable census. */ CENSUS_FEATURE_NONE = 0, /* Do not enable census. */
CENSUS_TRACING = 1, /* Enable census tracing. */ CENSUS_FEATURE_TRACING = 1, /* Enable census tracing. */
CENSUS_STATS = 2, /* Enable Census stats collection. */ CENSUS_FEATURE_STATS = 2, /* Enable Census stats collection. */
CENSUS_CPU = 4, /* Enable Census CPU usage collection. */ CENSUS_FEATURE_CPU = 4, /* Enable Census CPU usage collection. */
CENSUS_ALL = CENSUS_TRACING | CENSUS_STATS | CENSUS_CPU CENSUS_FEATURE_ALL =
CENSUS_FEATURE_TRACING | CENSUS_FEATURE_STATS | CENSUS_FEATURE_CPU
}; };
/* Shutdown and startup census subsystem. The 'functions' argument should be /** Shutdown and startup census subsystem. The 'features' argument should be
* the OR (|) of census_functions values. If census fails to initialize, then * the OR (|) of census_features values. If census fails to initialize, then
* census_initialize() will return a non-zero value. It is an error to call * census_initialize() will return a non-zero value. It is an error to call
* census_initialize() more than once (without an intervening * census_initialize() more than once (without an intervening
* census_shutdown()). */ * census_shutdown()). */
int census_initialize(int functions); int census_initialize(int features);
void census_shutdown(); void census_shutdown(void);
/* If any census feature has been initialized, this funtion will return a /** Return the features supported by the current census implementation (not all
* non-zero value. */ * features will be available on all platforms). */
int census_available(); int census_supported(void);
/** Return the census features currently enabled. */
int census_enabled(void);
/* Internally, Census relies on a context, which should be propagated across /* Internally, Census relies on a context, which should be propagated across
* RPC's. From the RPC subsystems viewpoint, this is an opaque data structure. * RPC's. From the RPC subsystems viewpoint, this is an opaque data structure.
......
...@@ -39,7 +39,7 @@ static void grpc_census_context_destroy(void *context) { ...@@ -39,7 +39,7 @@ static void grpc_census_context_destroy(void *context) {
} }
void grpc_census_call_set_context(grpc_call *call, census_context *context) { void grpc_census_call_set_context(grpc_call *call, census_context *context) {
if (!census_available()) { if (census_enabled() == CENSUS_FEATURE_NONE) {
return; return;
} }
if (context == NULL) { if (context == NULL) {
......
...@@ -33,20 +33,25 @@ ...@@ -33,20 +33,25 @@
#include <grpc/census.h> #include <grpc/census.h>
static int census_fns_enabled = CENSUS_NONE; static int features_enabled = CENSUS_FEATURE_NONE;
int census_initialize(int functions) { int census_initialize(int features) {
if (census_fns_enabled != CENSUS_NONE) { if (features_enabled != CENSUS_FEATURE_NONE) {
return 1; return 1;
} }
if (functions != CENSUS_NONE) { if (features != CENSUS_FEATURE_NONE) {
return 1; return 1;
} else { } else {
census_fns_enabled = functions; features_enabled = features;
return 0; return 0;
} }
} }
void census_shutdown() { census_fns_enabled = CENSUS_NONE; } void census_shutdown(void) { features_enabled = CENSUS_FEATURE_NONE; }
int census_available() { return (census_fns_enabled != CENSUS_NONE); } int census_supported(void) {
/* TODO(aveitch): improve this as we implement features... */
return CENSUS_FEATURE_NONE;
}
int census_enabled(void) { return features_enabled; }
...@@ -80,8 +80,11 @@ void grpc_init(void) { ...@@ -80,8 +80,11 @@ void grpc_init(void) {
grpc_security_pre_init(); grpc_security_pre_init();
grpc_iomgr_init(); grpc_iomgr_init();
grpc_tracer_init("GRPC_TRACE"); grpc_tracer_init("GRPC_TRACE");
if (census_initialize(CENSUS_NONE)) { /* Only initialize census if noone else has. */
gpr_log(GPR_ERROR, "Could not initialize census."); if (census_enabled() == CENSUS_FEATURE_NONE) {
if (census_initialize(census_supported())) { /* enable all features. */
gpr_log(GPR_ERROR, "Could not initialize census.");
}
} }
grpc_timers_global_init(); grpc_timers_global_init();
} }
......
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