Enrich census initialization and feature code

pull/2669/head
Alistair Veitch 10 years ago
parent 5c575dd6e4
commit 925e4a6349
  1. 32
      include/grpc/census.h
  2. 2
      src/core/census/grpc_context.c
  3. 19
      src/core/census/initialize.c
  4. 7
      src/core/surface/init.c

@ -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 'functions' 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) {
} }
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 @@
#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; }

@ -78,8 +78,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();
} }

Loading…
Cancel
Save