Merge branch 'tracer' of https://github.com/ctiller/grpc into tracing++

reviewable/pr13109/r2
ncteisen 7 years ago
commit fcdafde9bd
  1. 2
      include/grpc/grpc.h
  2. 2
      src/core/ext/filters/client_channel/channel_connectivity.cc
  3. 59
      src/core/ext/filters/client_channel/client_channel.cc
  4. 2
      src/core/ext/filters/client_channel/client_channel.h
  5. 4
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  6. 8
      src/core/ext/filters/client_channel/lb_policy.cc
  7. 2
      src/core/ext/filters/client_channel/lb_policy.h
  8. 48
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  9. 30
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  10. 46
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  11. 10
      src/core/ext/filters/client_channel/resolver.cc
  12. 2
      src/core/ext/filters/client_channel/resolver.h
  13. 2
      src/core/ext/filters/client_channel/subchannel.cc
  14. 1
      src/core/ext/filters/http/http_filters_plugin.cc
  15. 4
      src/core/ext/filters/http/message_compress/message_compress_filter.cc
  16. 5
      src/core/ext/transport/chttp2/transport/chttp2_plugin.cc
  17. 31
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  18. 8
      src/core/ext/transport/chttp2/transport/chttp2_transport.h
  19. 7
      src/core/ext/transport/chttp2/transport/frame_settings.cc
  20. 6
      src/core/ext/transport/chttp2/transport/hpack_encoder.cc
  21. 4
      src/core/ext/transport/chttp2/transport/hpack_parser.cc
  22. 6
      src/core/ext/transport/chttp2/transport/hpack_table.cc
  23. 6
      src/core/ext/transport/chttp2/transport/internal.h
  24. 8
      src/core/ext/transport/chttp2/transport/parsing.cc
  25. 9
      src/core/ext/transport/chttp2/transport/stream_lists.cc
  26. 12
      src/core/ext/transport/chttp2/transport/writing.cc
  27. 7
      src/core/ext/transport/inproc/inproc_plugin.cc
  28. 6
      src/core/ext/transport/inproc/inproc_transport.cc
  29. 2
      src/core/ext/transport/inproc/inproc_transport.h
  30. 2
      src/core/lib/channel/channel_stack.cc
  31. 4
      src/core/lib/channel/channel_stack.h
  32. 4
      src/core/lib/channel/channel_stack_builder.cc
  33. 2
      src/core/lib/channel/channel_stack_builder.h
  34. 111
      src/core/lib/debug/trace.cc
  35. 66
      src/core/lib/debug/trace.h
  36. 4
      src/core/lib/http/parser.cc
  37. 2
      src/core/lib/http/parser.h
  38. 31
      src/core/lib/iomgr/call_combiner.cc
  39. 2
      src/core/lib/iomgr/call_combiner.h
  40. 4
      src/core/lib/iomgr/closure.cc
  41. 2
      src/core/lib/iomgr/closure.h
  42. 7
      src/core/lib/iomgr/combiner.cc
  43. 2
      src/core/lib/iomgr/combiner.h
  44. 16
      src/core/lib/iomgr/error.cc
  45. 2
      src/core/lib/iomgr/error.h
  46. 52
      src/core/lib/iomgr/ev_epoll1_linux.cc
  47. 72
      src/core/lib/iomgr/ev_epollex_linux.cc
  48. 10
      src/core/lib/iomgr/ev_epollsig_linux.cc
  49. 10
      src/core/lib/iomgr/ev_poll_posix.cc
  50. 9
      src/core/lib/iomgr/ev_posix.cc
  51. 2
      src/core/lib/iomgr/ev_posix.h
  52. 4
      src/core/lib/iomgr/ev_windows.cc
  53. 4
      src/core/lib/iomgr/exec_ctx.cc
  54. 16
      src/core/lib/iomgr/executor.cc
  55. 1
      src/core/lib/iomgr/iomgr_posix.cc
  56. 2
      src/core/lib/iomgr/iomgr_uv.cc
  57. 8
      src/core/lib/iomgr/lockfree_event.cc
  58. 2
      src/core/lib/iomgr/pollset.h
  59. 5
      src/core/lib/iomgr/pollset_uv.cc
  60. 5
      src/core/lib/iomgr/pollset_windows.cc
  61. 21
      src/core/lib/iomgr/resource_quota.cc
  62. 2
      src/core/lib/iomgr/resource_quota.h
  63. 8
      src/core/lib/iomgr/tcp_client_posix.cc
  64. 6
      src/core/lib/iomgr/tcp_client_uv.cc
  65. 50
      src/core/lib/iomgr/tcp_posix.cc
  66. 2
      src/core/lib/iomgr/tcp_posix.h
  67. 2
      src/core/lib/iomgr/tcp_server_posix.cc
  68. 8
      src/core/lib/iomgr/tcp_server_uv.cc
  69. 18
      src/core/lib/iomgr/tcp_uv.cc
  70. 2
      src/core/lib/iomgr/tcp_uv.h
  71. 6
      src/core/lib/iomgr/tcp_windows.cc
  72. 37
      src/core/lib/iomgr/timer_generic.cc
  73. 25
      src/core/lib/iomgr/timer_manager.cc
  74. 5
      src/core/lib/iomgr/timer_uv.cc
  75. 8
      src/core/lib/security/context/security_context.cc
  76. 2
      src/core/lib/security/context/security_context.h
  77. 2
      src/core/lib/security/credentials/jwt/jwt_credentials.cc
  78. 2
      src/core/lib/security/credentials/oauth2/oauth2_credentials.cc
  79. 17
      src/core/lib/security/credentials/plugin/plugin_credentials.cc
  80. 2
      src/core/lib/security/credentials/plugin/plugin_credentials.h
  81. 11
      src/core/lib/security/transport/secure_endpoint.cc
  82. 2
      src/core/lib/security/transport/secure_endpoint.h
  83. 8
      src/core/lib/security/transport/security_connector.cc
  84. 2
      src/core/lib/security/transport/security_connector.h
  85. 9
      src/core/lib/surface/alarm.cc
  86. 2
      src/core/lib/surface/alarm_internal.h
  87. 2
      src/core/lib/surface/api_trace.cc
  88. 4
      src/core/lib/surface/api_trace.h
  89. 14
      src/core/lib/surface/call.cc
  90. 7
      src/core/lib/surface/call.h
  91. 42
      src/core/lib/surface/completion_queue.cc
  92. 10
      src/core/lib/surface/completion_queue.h
  93. 24
      src/core/lib/surface/init.cc
  94. 10
      src/core/lib/surface/init_secure.cc
  95. 5
      src/core/lib/surface/server.cc
  96. 2
      src/core/lib/surface/server.h
  97. 9
      src/core/lib/transport/bdp_estimator.cc
  98. 6
      src/core/lib/transport/bdp_estimator.h
  99. 13
      src/core/lib/transport/connectivity_state.cc
  100. 2
      src/core/lib/transport/connectivity_state.h
  101. Some files were not shown because too many files have changed in this diff Show More

@ -411,7 +411,7 @@ GRPCAPI void grpc_server_destroy(grpc_server *server);
/** Enable or disable a tracer. /** Enable or disable a tracer.
Tracers (usually controlled by the environment variable GRPC_TRACE) TraceFlags (usually controlled by the environment variable GRPC_TRACE)
allow printf-style debugging on GRPC internals, and are useful for allow printf-style debugging on GRPC internals, and are useful for
tracking down problems in the field. tracking down problems in the field.

@ -122,7 +122,7 @@ static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w,
gpr_mu_lock(&w->mu); gpr_mu_lock(&w->mu);
if (due_to_completion) { if (due_to_completion) {
if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { if (grpc_trace_operation_failures.enabled()) {
GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error)); GRPC_LOG_IF_ERROR("watch_completion_error", GRPC_ERROR_REF(error));
} }
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);

@ -55,8 +55,7 @@
/* Client channel implementation */ /* Client channel implementation */
grpc_tracer_flag grpc_client_channel_trace = grpc_core::TraceFlag grpc_client_channel_trace(false, "client_channel");
GRPC_TRACER_INITIALIZER(false, "client_channel");
/************************************************************************* /*************************************************************************
* METHOD-CONFIG TABLE * METHOD-CONFIG TABLE
@ -250,7 +249,7 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx *exec_ctx,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
} }
} }
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: setting connectivity state to %s", chand, gpr_log(GPR_DEBUG, "chand=%p: setting connectivity state to %s", chand,
grpc_connectivity_state_name(state)); grpc_connectivity_state_name(state));
} }
@ -264,7 +263,7 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx *exec_ctx,
grpc_connectivity_state publish_state = w->state; grpc_connectivity_state publish_state = w->state;
/* check if the notification is for the latest policy */ /* check if the notification is for the latest policy */
if (w->lb_policy == w->chand->lb_policy) { if (w->lb_policy == w->chand->lb_policy) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand,
w->lb_policy, grpc_connectivity_state_name(w->state)); w->lb_policy, grpc_connectivity_state_name(w->state));
} }
@ -301,7 +300,7 @@ static void watch_lb_policy_locked(grpc_exec_ctx *exec_ctx, channel_data *chand,
static void start_resolving_locked(grpc_exec_ctx *exec_ctx, static void start_resolving_locked(grpc_exec_ctx *exec_ctx,
channel_data *chand) { channel_data *chand) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand); gpr_log(GPR_DEBUG, "chand=%p: starting name resolution", chand);
} }
GPR_ASSERT(!chand->started_resolving); GPR_ASSERT(!chand->started_resolving);
@ -374,7 +373,7 @@ static void parse_retry_throttle_params(const grpc_json *field, void *arg) {
static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx,
void *arg, grpc_error *error) { void *arg, grpc_error *error) {
channel_data *chand = (channel_data *)arg; channel_data *chand = (channel_data *)arg;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand, gpr_log(GPR_DEBUG, "chand=%p: got resolver result: error=%s", chand,
grpc_error_string(error)); grpc_error_string(error));
} }
@ -483,7 +482,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx,
grpc_channel_args_destroy(exec_ctx, chand->resolver_result); grpc_channel_args_destroy(exec_ctx, chand->resolver_result);
chand->resolver_result = NULL; chand->resolver_result = NULL;
} }
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p: resolver result: lb_policy_name=\"%s\"%s, " "chand=%p: resolver result: lb_policy_name=\"%s\"%s, "
"service_config=\"%s\"", "service_config=\"%s\"",
@ -524,7 +523,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx,
if (new_lb_policy != NULL || error != GRPC_ERROR_NONE || if (new_lb_policy != NULL || error != GRPC_ERROR_NONE ||
chand->resolver == NULL) { chand->resolver == NULL) {
if (chand->lb_policy != NULL) { if (chand->lb_policy != NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand,
chand->lb_policy); chand->lb_policy);
} }
@ -538,11 +537,11 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx,
// Now that we've swapped out the relevant fields of chand, check for // Now that we've swapped out the relevant fields of chand, check for
// error or shutdown. // error or shutdown.
if (error != GRPC_ERROR_NONE || chand->resolver == NULL) { if (error != GRPC_ERROR_NONE || chand->resolver == NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand); gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand);
} }
if (chand->resolver != NULL) { if (chand->resolver != NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand);
} }
grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); grpc_resolver_shutdown_locked(exec_ctx, chand->resolver);
@ -565,7 +564,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx,
grpc_error *state_error = grpc_error *state_error =
GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy"); GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy");
if (new_lb_policy != NULL) { if (new_lb_policy != NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand);
} }
GRPC_ERROR_UNREF(state_error); GRPC_ERROR_UNREF(state_error);
@ -896,7 +895,7 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem, grpc_call_element *elem,
grpc_error *error) { grpc_error *error) {
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: failing %" PRIdPTR " pending batches: %s", "chand=%p calld=%p: failing %" PRIdPTR " pending batches: %s",
elem->channel_data, calld, calld->waiting_for_pick_batches_count, elem->channel_data, calld, calld->waiting_for_pick_batches_count,
@ -939,7 +938,7 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem) { grpc_call_element *elem) {
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending %" PRIdPTR gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending %" PRIdPTR
" pending batches to subchannel_call=%p", " pending batches to subchannel_call=%p",
chand, calld, calld->waiting_for_pick_batches_count, chand, calld, calld->waiting_for_pick_batches_count,
@ -965,7 +964,7 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem) { grpc_call_element *elem) {
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call",
chand, calld); chand, calld);
} }
@ -1011,7 +1010,7 @@ static void create_subchannel_call_locked(grpc_exec_ctx *exec_ctx,
grpc_error *new_error = grpc_connected_subchannel_create_call( grpc_error *new_error = grpc_connected_subchannel_create_call(
exec_ctx, calld->connected_subchannel, &call_args, exec_ctx, calld->connected_subchannel, &call_args,
&calld->subchannel_call); &calld->subchannel_call);
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: create subchannel_call=%p: error=%s", gpr_log(GPR_DEBUG, "chand=%p calld=%p: create subchannel_call=%p: error=%s",
chand, calld, calld->subchannel_call, grpc_error_string(new_error)); chand, calld, calld->subchannel_call, grpc_error_string(new_error));
} }
@ -1037,7 +1036,7 @@ static void pick_done_locked(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
"Call dropped by load balancing policy") "Call dropped by load balancing policy")
: GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( : GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"Failed to create subchannel", &error, 1); "Failed to create subchannel", &error, 1);
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: failed to create subchannel: error=%s", chand, "chand=%p calld=%p: failed to create subchannel: error=%s", chand,
calld, grpc_error_string(calld->error)); calld, grpc_error_string(calld->error));
@ -1071,7 +1070,7 @@ static void pick_callback_cancel_locked(grpc_exec_ctx *exec_ctx, void *arg,
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (calld->lb_policy != NULL) { if (calld->lb_policy != NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p",
chand, calld, calld->lb_policy); chand, calld, calld->lb_policy);
} }
@ -1089,7 +1088,7 @@ static void pick_callback_done_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_call_element *elem = (grpc_call_element *)arg; grpc_call_element *elem = (grpc_call_element *)arg;
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously",
chand, calld); chand, calld);
} }
@ -1106,7 +1105,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem) { grpc_call_element *elem) {
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p", gpr_log(GPR_DEBUG, "chand=%p calld=%p: starting pick on lb_policy=%p",
chand, calld, chand->lb_policy); chand, calld, chand->lb_policy);
} }
@ -1144,7 +1143,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx,
calld->subchannel_call_context, NULL, &calld->lb_pick_closure); calld->subchannel_call_context, NULL, &calld->lb_pick_closure);
if (pick_done) { if (pick_done) {
/* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed synchronously", gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed synchronously",
chand, calld); chand, calld);
} }
@ -1190,7 +1189,7 @@ static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem = args->elem; grpc_call_element *elem = args->elem;
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: cancelling pick waiting for resolver result", "chand=%p calld=%p: cancelling pick waiting for resolver result",
chand, calld); chand, calld);
@ -1212,7 +1211,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx,
(pick_after_resolver_result_args *)arg; (pick_after_resolver_result_args *)arg;
if (args->finished) { if (args->finished) {
/* cancelled, do nothing */ /* cancelled, do nothing */
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "call cancelled before resolver result"); gpr_log(GPR_DEBUG, "call cancelled before resolver result");
} }
gpr_free(args); gpr_free(args);
@ -1223,13 +1222,13 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx,
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data", gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver failed to return data",
chand, calld); chand, calld);
} }
async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error));
} else { } else {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick",
chand, calld); chand, calld);
} }
@ -1248,7 +1247,7 @@ static void pick_after_resolver_result_start_locked(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem) { grpc_call_element *elem) {
channel_data *chand = (channel_data *)elem->channel_data; channel_data *chand = (channel_data *)elem->channel_data;
call_data *calld = (call_data *)elem->call_data; call_data *calld = (call_data *)elem->call_data;
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: deferring pick pending resolver result", chand, "chand=%p calld=%p: deferring pick pending resolver result", chand,
calld); calld);
@ -1333,7 +1332,7 @@ static void cc_start_transport_stream_op_batch(
GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0); GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0);
// If we've previously been cancelled, immediately fail any new batches. // If we've previously been cancelled, immediately fail any new batches.
if (calld->error != GRPC_ERROR_NONE) { if (calld->error != GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: failing batch with error: %s", gpr_log(GPR_DEBUG, "chand=%p calld=%p: failing batch with error: %s",
chand, calld, grpc_error_string(calld->error)); chand, calld, grpc_error_string(calld->error));
} }
@ -1349,7 +1348,7 @@ static void cc_start_transport_stream_op_batch(
// error to the caller when the first batch does get passed down. // error to the caller when the first batch does get passed down.
GRPC_ERROR_UNREF(calld->error); GRPC_ERROR_UNREF(calld->error);
calld->error = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); calld->error = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error);
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: recording cancel_error=%s", chand, gpr_log(GPR_DEBUG, "chand=%p calld=%p: recording cancel_error=%s", chand,
calld, grpc_error_string(calld->error)); calld, grpc_error_string(calld->error));
} }
@ -1378,7 +1377,7 @@ static void cc_start_transport_stream_op_batch(
// the channel combiner, which is more efficient (especially for // the channel combiner, which is more efficient (especially for
// streaming calls). // streaming calls).
if (calld->subchannel_call != NULL) { if (calld->subchannel_call != NULL) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: sending batch to subchannel_call=%p", chand, "chand=%p calld=%p: sending batch to subchannel_call=%p", chand,
calld, calld->subchannel_call); calld, calld->subchannel_call);
@ -1392,7 +1391,7 @@ static void cc_start_transport_stream_op_batch(
// For batches containing a send_initial_metadata op, enter the channel // For batches containing a send_initial_metadata op, enter the channel
// combiner to start a pick. // combiner to start a pick.
if (batch->send_initial_metadata) { if (batch->send_initial_metadata) {
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, "chand=%p calld=%p: entering client_channel combiner", gpr_log(GPR_DEBUG, "chand=%p calld=%p: entering client_channel combiner",
chand, calld); chand, calld);
} }
@ -1403,7 +1402,7 @@ static void cc_start_transport_stream_op_batch(
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
} else { } else {
// For all other batches, release the call combiner. // For all other batches, release the call combiner.
if (GRPC_TRACER_ON(grpc_client_channel_trace)) { if (grpc_client_channel_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"chand=%p calld=%p: saved batch, yeilding call combiner", chand, "chand=%p calld=%p: saved batch, yeilding call combiner", chand,
calld); calld);

@ -23,7 +23,7 @@
#include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/channel_stack.h"
extern grpc_tracer_flag grpc_client_channel_trace; extern grpc_core::TraceFlag grpc_client_channel_trace;
// Channel arg key for server URI string. // Channel arg key for server URI string.
#define GRPC_ARG_SERVER_URI "grpc.server_uri" #define GRPC_ARG_SERVER_URI "grpc.server_uri"

@ -78,9 +78,9 @@ extern "C" void grpc_client_channel_init(void) {
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
(void *)&grpc_client_channel_filter); (void *)&grpc_client_channel_filter);
grpc_http_connect_register_handshaker_factory(); grpc_http_connect_register_handshaker_factory();
grpc_register_tracer(&grpc_client_channel_trace);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer(&grpc_trace_resolver_refcount);
#endif #endif
} }

@ -21,10 +21,8 @@
#define WEAK_REF_BITS 16 #define WEAK_REF_BITS 16
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount(
grpc_tracer_flag grpc_trace_lb_policy_refcount = false, "lb_policy_refcount");
GRPC_TRACER_INITIALIZER(false, "lb_policy_refcount");
#endif
void grpc_lb_policy_init(grpc_lb_policy *policy, void grpc_lb_policy_init(grpc_lb_policy *policy,
const grpc_lb_policy_vtable *vtable, const grpc_lb_policy_vtable *vtable,
@ -52,7 +50,7 @@ static gpr_atm ref_mutate(grpc_lb_policy *c, gpr_atm delta,
gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta)
: gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta);
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_lb_policy_refcount)) { if (grpc_trace_lb_policy_refcount.enabled()) {
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"LB_POLICY: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c, "LB_POLICY: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c,
purpose, old_val, old_val + delta, reason); purpose, old_val, old_val + delta, reason);

@ -34,7 +34,7 @@ typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable;
typedef struct grpc_lb_policy_args grpc_lb_policy_args; typedef struct grpc_lb_policy_args grpc_lb_policy_args;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_lb_policy_refcount; extern grpc_core::TraceFlag grpc_trace_lb_policy_refcount;
#endif #endif
struct grpc_lb_policy { struct grpc_lb_policy {

@ -126,7 +126,7 @@
#define GRPC_GRPCLB_RECONNECT_JITTER 0.2 #define GRPC_GRPCLB_RECONNECT_JITTER 0.2
#define GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS 10000 #define GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS 10000
grpc_tracer_flag grpc_lb_glb_trace = GRPC_TRACER_INITIALIZER(false, "glb"); grpc_core::TraceFlag grpc_lb_glb_trace(false, "glb");
/* add lb_token of selected subchannel (address) to the call's initial /* add lb_token of selected subchannel (address) to the call's initial
* metadata */ * metadata */
@ -212,7 +212,7 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg,
} else { } else {
grpc_grpclb_client_stats_unref(wc_arg->client_stats); grpc_grpclb_client_stats_unref(wc_arg->client_stats);
} }
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Unreffing RR %p", (void *)wc_arg->rr_policy); gpr_log(GPR_INFO, "Unreffing RR %p", (void *)wc_arg->rr_policy);
} }
GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure");
@ -618,7 +618,7 @@ static void update_lb_connectivity_status_locked(
GPR_ASSERT(rr_state_error == GRPC_ERROR_NONE); GPR_ASSERT(rr_state_error == GRPC_ERROR_NONE);
} }
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log( gpr_log(
GPR_INFO, "Setting grpclb's state to %s from new RR policy %p state.", GPR_INFO, "Setting grpclb's state to %s from new RR policy %p state.",
grpc_connectivity_state_name(rr_state), (void *)glb_policy->rr_policy); grpc_connectivity_state_name(rr_state), (void *)glb_policy->rr_policy);
@ -647,7 +647,7 @@ static bool pick_from_internal_rr_locked(
} }
if (server->drop) { if (server->drop) {
// Not using the RR policy, so unref it. // Not using the RR policy, so unref it.
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Unreffing RR for drop (0x%" PRIxPTR ")", gpr_log(GPR_INFO, "Unreffing RR for drop (0x%" PRIxPTR ")",
(intptr_t)wc_arg->rr_policy); (intptr_t)wc_arg->rr_policy);
} }
@ -676,7 +676,7 @@ static bool pick_from_internal_rr_locked(
(void **)&wc_arg->lb_token, &wc_arg->wrapper_closure); (void **)&wc_arg->lb_token, &wc_arg->wrapper_closure);
if (pick_done) { if (pick_done) {
/* synchronous grpc_lb_policy_pick call. Unref the RR policy. */ /* synchronous grpc_lb_policy_pick call. Unref the RR policy. */
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Unreffing RR (0x%" PRIxPTR ")", gpr_log(GPR_INFO, "Unreffing RR (0x%" PRIxPTR ")",
(intptr_t)wc_arg->rr_policy); (intptr_t)wc_arg->rr_policy);
} }
@ -797,7 +797,7 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy,
pp->wrapped_on_complete_arg.rr_policy = glb_policy->rr_policy; pp->wrapped_on_complete_arg.rr_policy = glb_policy->rr_policy;
pp->wrapped_on_complete_arg.client_stats = pp->wrapped_on_complete_arg.client_stats =
grpc_grpclb_client_stats_ref(glb_policy->client_stats); grpc_grpclb_client_stats_ref(glb_policy->client_stats);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Pending pick about to (async) PICK from %p", gpr_log(GPR_INFO, "Pending pick about to (async) PICK from %p",
(void *)glb_policy->rr_policy); (void *)glb_policy->rr_policy);
} }
@ -811,7 +811,7 @@ static void create_rr_locked(grpc_exec_ctx *exec_ctx, glb_lb_policy *glb_policy,
glb_policy->pending_pings = pping->next; glb_policy->pending_pings = pping->next;
GRPC_LB_POLICY_REF(glb_policy->rr_policy, "rr_handover_pending_ping"); GRPC_LB_POLICY_REF(glb_policy->rr_policy, "rr_handover_pending_ping");
pping->wrapped_notify_arg.rr_policy = glb_policy->rr_policy; pping->wrapped_notify_arg.rr_policy = glb_policy->rr_policy;
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Pending ping about to PING from 0x%" PRIxPTR "", gpr_log(GPR_INFO, "Pending ping about to PING from 0x%" PRIxPTR "",
(intptr_t)glb_policy->rr_policy); (intptr_t)glb_policy->rr_policy);
} }
@ -827,14 +827,14 @@ static void rr_handover_locked(grpc_exec_ctx *exec_ctx,
grpc_lb_policy_args *args = lb_policy_args_create(exec_ctx, glb_policy); grpc_lb_policy_args *args = lb_policy_args_create(exec_ctx, glb_policy);
GPR_ASSERT(args != NULL); GPR_ASSERT(args != NULL);
if (glb_policy->rr_policy != NULL) { if (glb_policy->rr_policy != NULL) {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_DEBUG, "Updating Round Robin policy (%p)", gpr_log(GPR_DEBUG, "Updating Round Robin policy (%p)",
(void *)glb_policy->rr_policy); (void *)glb_policy->rr_policy);
} }
grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args); grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args);
} else { } else {
create_rr_locked(exec_ctx, glb_policy, args); create_rr_locked(exec_ctx, glb_policy, args);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_DEBUG, "Created new Round Robin policy (%p)", gpr_log(GPR_DEBUG, "Created new Round Robin policy (%p)",
(void *)glb_policy->rr_policy); (void *)glb_policy->rr_policy);
} }
@ -1165,7 +1165,7 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
bool pick_done; bool pick_done;
if (glb_policy->rr_policy != NULL) { if (glb_policy->rr_policy != NULL) {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "grpclb %p about to PICK from RR %p", gpr_log(GPR_INFO, "grpclb %p about to PICK from RR %p",
(void *)glb_policy, (void *)glb_policy->rr_policy); (void *)glb_policy, (void *)glb_policy->rr_policy);
} }
@ -1190,7 +1190,7 @@ static int glb_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
pick_from_internal_rr_locked(exec_ctx, glb_policy, pick_args, pick_from_internal_rr_locked(exec_ctx, glb_policy, pick_args,
false /* force_async */, target, wc_arg); false /* force_async */, target, wc_arg);
} else { } else {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"No RR policy in grpclb instance %p. Adding to grpclb's pending " "No RR policy in grpclb instance %p. Adding to grpclb's pending "
"picks", "picks",
@ -1242,7 +1242,7 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx *exec_ctx, void *arg,
glb_lb_policy *glb_policy = (glb_lb_policy *)arg; glb_lb_policy *glb_policy = (glb_lb_policy *)arg;
glb_policy->retry_timer_active = false; glb_policy->retry_timer_active = false;
if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) { if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Restaring call to LB server (grpclb %p)", gpr_log(GPR_INFO, "Restaring call to LB server (grpclb %p)",
(void *)glb_policy); (void *)glb_policy);
} }
@ -1264,7 +1264,7 @@ static void maybe_restart_lb_call(grpc_exec_ctx *exec_ctx,
/* if we aren't shutting down, restart the LB client call after some time */ /* if we aren't shutting down, restart the LB client call after some time */
grpc_millis next_try = grpc_millis next_try =
grpc_backoff_step(exec_ctx, &glb_policy->lb_call_backoff_state); grpc_backoff_step(exec_ctx, &glb_policy->lb_call_backoff_state);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_DEBUG, "Connection to LB server lost (grpclb: %p)...", gpr_log(GPR_DEBUG, "Connection to LB server lost (grpclb: %p)...",
(void *)glb_policy); (void *)glb_policy);
grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx);
@ -1465,7 +1465,7 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx,
lb_call_init_locked(exec_ctx, glb_policy); lb_call_init_locked(exec_ctx, glb_policy);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Query for backends (grpclb: %p, lb_channel: %p, lb_call: %p)", "Query for backends (grpclb: %p, lb_channel: %p, lb_call: %p)",
(void *)glb_policy, (void *)glb_policy->lb_channel, (void *)glb_policy, (void *)glb_policy->lb_channel,
@ -1557,7 +1557,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg,
glb_policy->client_stats_report_interval = GPR_MAX( glb_policy->client_stats_report_interval = GPR_MAX(
GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis(
&response->client_stats_report_interval)); &response->client_stats_report_interval));
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"received initial LB response message; " "received initial LB response message; "
"client load reporting interval = %" PRIdPTR " milliseconds", "client load reporting interval = %" PRIdPTR " milliseconds",
@ -1569,7 +1569,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg,
glb_policy->client_load_report_timer_pending = true; glb_policy->client_load_report_timer_pending = true;
GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "client_load_report"); GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "client_load_report");
schedule_next_client_load_report(exec_ctx, glb_policy); schedule_next_client_load_report(exec_ctx, glb_policy);
} else if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { } else if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"received initial LB response message; " "received initial LB response message; "
"client load reporting NOT enabled"); "client load reporting NOT enabled");
@ -1581,7 +1581,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_grpclb_response_parse_serverlist(response_slice); grpc_grpclb_response_parse_serverlist(response_slice);
if (serverlist != NULL) { if (serverlist != NULL) {
GPR_ASSERT(glb_policy->lb_call != NULL); GPR_ASSERT(glb_policy->lb_call != NULL);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Serverlist with %lu servers received", gpr_log(GPR_INFO, "Serverlist with %lu servers received",
(unsigned long)serverlist->num_servers); (unsigned long)serverlist->num_servers);
for (size_t i = 0; i < serverlist->num_servers; ++i) { for (size_t i = 0; i < serverlist->num_servers; ++i) {
@ -1597,7 +1597,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg,
if (serverlist->num_servers > 0) { if (serverlist->num_servers > 0) {
if (grpc_grpclb_serverlist_equals(glb_policy->serverlist, if (grpc_grpclb_serverlist_equals(glb_policy->serverlist,
serverlist)) { serverlist)) {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Incoming server list identical to current, ignoring."); "Incoming server list identical to current, ignoring.");
} }
@ -1624,7 +1624,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx *exec_ctx, void *arg,
rr_handover_locked(exec_ctx, glb_policy); rr_handover_locked(exec_ctx, glb_policy);
} }
} else { } else {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Received empty server list, ignoring."); gpr_log(GPR_INFO, "Received empty server list, ignoring.");
} }
grpc_grpclb_destroy_serverlist(serverlist); grpc_grpclb_destroy_serverlist(serverlist);
@ -1668,7 +1668,7 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx *exec_ctx, void *arg,
* actually runs, don't fall back. */ * actually runs, don't fall back. */
if (glb_policy->serverlist == NULL) { if (glb_policy->serverlist == NULL) {
if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) { if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Falling back to use backends from resolver (grpclb %p)", "Falling back to use backends from resolver (grpclb %p)",
(void *)glb_policy); (void *)glb_policy);
@ -1685,7 +1685,7 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx *exec_ctx,
void *arg, grpc_error *error) { void *arg, grpc_error *error) {
glb_lb_policy *glb_policy = (glb_lb_policy *)arg; glb_lb_policy *glb_policy = (glb_lb_policy *)arg;
GPR_ASSERT(glb_policy->lb_call != NULL); GPR_ASSERT(glb_policy->lb_call != NULL);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
char *status_details = char *status_details =
grpc_slice_to_c_string(glb_policy->lb_call_status_details); grpc_slice_to_c_string(glb_policy->lb_call_status_details);
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
@ -1869,7 +1869,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(uri->path[0] != '\0'); GPR_ASSERT(uri->path[0] != '\0');
glb_policy->server_name = glb_policy->server_name =
gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path); gpr_strdup(uri->path[0] == '/' ? uri->path + 1 : uri->path);
if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { if (grpc_lb_glb_trace.enabled()) {
gpr_log(GPR_INFO, "Will use '%s' as the server name for LB request.", gpr_log(GPR_INFO, "Will use '%s' as the server name for LB request.",
glb_policy->server_name); glb_policy->server_name);
} }
@ -1962,9 +1962,9 @@ static bool maybe_add_client_load_reporting_filter(
extern "C" void grpc_lb_policy_grpclb_init() { extern "C" void grpc_lb_policy_grpclb_init() {
grpc_register_lb_policy(grpc_glb_lb_factory_create()); grpc_register_lb_policy(grpc_glb_lb_factory_create());
grpc_register_tracer(&grpc_lb_glb_trace);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer(&grpc_trace_lb_policy_refcount);
#endif #endif
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,

@ -28,8 +28,7 @@
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/connectivity_state.h"
grpc_tracer_flag grpc_lb_pick_first_trace = grpc_core::TraceFlag grpc_lb_pick_first_trace(false, "pick_first");
GRPC_TRACER_INITIALIZER(false, "pick_first");
typedef struct pending_pick { typedef struct pending_pick {
struct pending_pick *next; struct pending_pick *next;
@ -97,7 +96,7 @@ static void pf_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
gpr_free(p->subchannels); gpr_free(p->subchannels);
gpr_free(p->new_subchannels); gpr_free(p->new_subchannels);
gpr_free(p); gpr_free(p);
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, "Pick First %p destroyed.", (void *)p); gpr_log(GPR_DEBUG, "Pick First %p destroyed.", (void *)p);
} }
} }
@ -273,7 +272,7 @@ static void stop_connectivity_watchers(grpc_exec_ctx *exec_ctx,
pick_first_lb_policy *p) { pick_first_lb_policy *p) {
if (p->num_subchannels > 0) { if (p->num_subchannels > 0) {
GPR_ASSERT(p->selected == NULL); GPR_ASSERT(p->selected == NULL);
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, "Pick First %p unsubscribing from subchannel %p", gpr_log(GPR_DEBUG, "Pick First %p unsubscribing from subchannel %p",
(void *)p, (void *)p->subchannels[p->checking_subchannel]); (void *)p, (void *)p->subchannels[p->checking_subchannel]);
} }
@ -282,7 +281,7 @@ static void stop_connectivity_watchers(grpc_exec_ctx *exec_ctx,
&p->connectivity_changed); &p->connectivity_changed);
p->updating_subchannels = true; p->updating_subchannels = true;
} else if (p->selected != NULL) { } else if (p->selected != NULL) {
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"Pick First %p unsubscribing from selected subchannel %p", "Pick First %p unsubscribing from selected subchannel %p",
(void *)p, (void *)p->selected); (void *)p, (void *)p->selected);
@ -327,7 +326,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
stop_connectivity_watchers(exec_ctx, p); stop_connectivity_watchers(exec_ctx, p);
return; return;
} }
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_INFO, "Pick First %p received update with %lu addresses", gpr_log(GPR_INFO, "Pick First %p received update with %lu addresses",
(void *)p, (unsigned long)addresses->num_addresses); (void *)p, (unsigned long)addresses->num_addresses);
} }
@ -366,7 +365,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
grpc_subchannel_key_destroy(exec_ctx, ith_sc_key); grpc_subchannel_key_destroy(exec_ctx, ith_sc_key);
if (found_selected) { if (found_selected) {
// The currently selected subchannel is in the update: we are done. // The currently selected subchannel is in the update: we are done.
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p found already selected subchannel %p amongst " "Pick First %p found already selected subchannel %p amongst "
"updates. Update done.", "updates. Update done.",
@ -385,7 +384,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
// steps were successful, the update can be considered done without any // steps were successful, the update can be considered done without any
// interference (ie, no callbacks were scheduled). // interference (ie, no callbacks were scheduled).
if (p->updating_selected || p->updating_subchannels) { if (p->updating_selected || p->updating_subchannels) {
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Update already in progress for pick first %p. Deferring update.", "Update already in progress for pick first %p. Deferring update.",
(void *)p); (void *)p);
@ -409,7 +408,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
for (size_t i = 0; i < sc_args_count; i++) { for (size_t i = 0; i < sc_args_count; i++) {
grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel(
exec_ctx, args->client_channel_factory, &sc_args[i]); exec_ctx, args->client_channel_factory, &sc_args[i]);
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
char *address_uri = char *address_uri =
grpc_sockaddr_to_uri(&addresses->addresses[i].address); grpc_sockaddr_to_uri(&addresses->addresses[i].address);
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
@ -463,7 +462,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_subchannel *selected_subchannel; grpc_subchannel *selected_subchannel;
pending_pick *pp; pending_pick *pp;
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"Pick First %p connectivity changed. Updating selected: %d; Updating " "Pick First %p connectivity changed. Updating selected: %d; Updating "
@ -478,7 +477,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
GPR_ASSERT(p->selected != NULL); GPR_ASSERT(p->selected != NULL);
GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, p->selected, GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, p->selected,
"pf_update_connectivity"); "pf_update_connectivity");
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, "Pick First %p unreffing selected subchannel %p", gpr_log(GPR_DEBUG, "Pick First %p unreffing selected subchannel %p",
(void *)p, (void *)p->selected); (void *)p, (void *)p->selected);
} }
@ -495,7 +494,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
for (size_t i = 0; i < p->num_subchannels; i++) { for (size_t i = 0; i < p->num_subchannels; i++) {
GRPC_SUBCHANNEL_UNREF(exec_ctx, p->subchannels[i], GRPC_SUBCHANNEL_UNREF(exec_ctx, p->subchannels[i],
"pf_update_connectivity"); "pf_update_connectivity");
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, "Pick First %p unreffing subchannel %p", (void *)p, gpr_log(GPR_DEBUG, "Pick First %p unreffing subchannel %p", (void *)p,
(void *)p->subchannels[i]); (void *)p->subchannels[i]);
} }
@ -568,7 +567,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_subchannel_get_connected_subchannel(selected_subchannel), grpc_subchannel_get_connected_subchannel(selected_subchannel),
"picked_first"); "picked_first");
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Pick First %p selected subchannel %p (connected %p)", "Pick First %p selected subchannel %p (connected %p)",
(void *)p, (void *)selected_subchannel, (void *)p->selected); (void *)p, (void *)selected_subchannel, (void *)p->selected);
@ -581,7 +580,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
while ((pp = p->pending_picks)) { while ((pp = p->pending_picks)) {
p->pending_picks = pp->next; p->pending_picks = pp->next;
*pp->target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected, "picked"); *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected, "picked");
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"Servicing pending pick with selected subchannel %p", "Servicing pending pick with selected subchannel %p",
(void *)p->selected); (void *)p->selected);
@ -682,7 +681,7 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx,
grpc_lb_policy_args *args) { grpc_lb_policy_args *args) {
GPR_ASSERT(args->client_channel_factory != NULL); GPR_ASSERT(args->client_channel_factory != NULL);
pick_first_lb_policy *p = (pick_first_lb_policy *)gpr_zalloc(sizeof(*p)); pick_first_lb_policy *p = (pick_first_lb_policy *)gpr_zalloc(sizeof(*p));
if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { if (grpc_lb_pick_first_trace.enabled()) {
gpr_log(GPR_DEBUG, "Pick First %p created.", (void *)p); gpr_log(GPR_DEBUG, "Pick First %p created.", (void *)p);
} }
pf_update_locked(exec_ctx, &p->base, args); pf_update_locked(exec_ctx, &p->base, args);
@ -708,7 +707,6 @@ static grpc_lb_policy_factory *pick_first_lb_factory_create() {
extern "C" void grpc_lb_policy_pick_first_init() { extern "C" void grpc_lb_policy_pick_first_init() {
grpc_register_lb_policy(pick_first_lb_factory_create()); grpc_register_lb_policy(pick_first_lb_factory_create());
grpc_register_tracer(&grpc_lb_pick_first_trace);
} }
extern "C" void grpc_lb_policy_pick_first_shutdown() {} extern "C" void grpc_lb_policy_pick_first_shutdown() {}

@ -38,8 +38,7 @@
#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
grpc_tracer_flag grpc_lb_round_robin_trace = grpc_core::TraceFlag grpc_lb_round_robin_trace(false, "round_robin");
GRPC_TRACER_INITIALIZER(false, "round_robin");
/** List of entities waiting for a pick. /** List of entities waiting for a pick.
* *
@ -152,7 +151,7 @@ static rr_subchannel_list *rr_subchannel_list_create(round_robin_lb_policy *p,
(subchannel_data *)gpr_zalloc(sizeof(subchannel_data) * num_subchannels); (subchannel_data *)gpr_zalloc(sizeof(subchannel_data) * num_subchannels);
subchannel_list->num_subchannels = num_subchannels; subchannel_list->num_subchannels = num_subchannels;
gpr_ref_init(&subchannel_list->refcount, 1); gpr_ref_init(&subchannel_list->refcount, 1);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_INFO, "[RR %p] Created subchannel list %p for %lu subchannels", gpr_log(GPR_INFO, "[RR %p] Created subchannel list %p for %lu subchannels",
(void *)p, (void *)subchannel_list, (unsigned long)num_subchannels); (void *)p, (void *)subchannel_list, (unsigned long)num_subchannels);
} }
@ -162,7 +161,7 @@ static rr_subchannel_list *rr_subchannel_list_create(round_robin_lb_policy *p,
static void rr_subchannel_list_destroy(grpc_exec_ctx *exec_ctx, static void rr_subchannel_list_destroy(grpc_exec_ctx *exec_ctx,
rr_subchannel_list *subchannel_list) { rr_subchannel_list *subchannel_list) {
GPR_ASSERT(subchannel_list->shutting_down); GPR_ASSERT(subchannel_list->shutting_down);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_INFO, "[RR %p] Destroying subchannel_list %p", gpr_log(GPR_INFO, "[RR %p] Destroying subchannel_list %p",
(void *)subchannel_list->policy, (void *)subchannel_list); (void *)subchannel_list->policy, (void *)subchannel_list);
} }
@ -186,7 +185,7 @@ static void rr_subchannel_list_destroy(grpc_exec_ctx *exec_ctx,
static void rr_subchannel_list_ref(rr_subchannel_list *subchannel_list, static void rr_subchannel_list_ref(rr_subchannel_list *subchannel_list,
const char *reason) { const char *reason) {
gpr_ref_non_zero(&subchannel_list->refcount); gpr_ref_non_zero(&subchannel_list->refcount);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count);
gpr_log(GPR_INFO, "[RR %p] subchannel_list %p REF %lu->%lu (%s)", gpr_log(GPR_INFO, "[RR %p] subchannel_list %p REF %lu->%lu (%s)",
(void *)subchannel_list->policy, (void *)subchannel_list, (void *)subchannel_list->policy, (void *)subchannel_list,
@ -198,7 +197,7 @@ static void rr_subchannel_list_unref(grpc_exec_ctx *exec_ctx,
rr_subchannel_list *subchannel_list, rr_subchannel_list *subchannel_list,
const char *reason) { const char *reason) {
const bool done = gpr_unref(&subchannel_list->refcount); const bool done = gpr_unref(&subchannel_list->refcount);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count);
gpr_log(GPR_INFO, "[RR %p] subchannel_list %p UNREF %lu->%lu (%s)", gpr_log(GPR_INFO, "[RR %p] subchannel_list %p UNREF %lu->%lu (%s)",
(void *)subchannel_list->policy, (void *)subchannel_list, (void *)subchannel_list->policy, (void *)subchannel_list,
@ -215,7 +214,7 @@ static void rr_subchannel_list_shutdown_and_unref(
grpc_exec_ctx *exec_ctx, rr_subchannel_list *subchannel_list, grpc_exec_ctx *exec_ctx, rr_subchannel_list *subchannel_list,
const char *reason) { const char *reason) {
GPR_ASSERT(!subchannel_list->shutting_down); GPR_ASSERT(!subchannel_list->shutting_down);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, "[RR %p] Shutting down subchannel_list %p (%s)", gpr_log(GPR_DEBUG, "[RR %p] Shutting down subchannel_list %p (%s)",
(void *)subchannel_list->policy, (void *)subchannel_list, reason); (void *)subchannel_list->policy, (void *)subchannel_list, reason);
} }
@ -224,7 +223,7 @@ static void rr_subchannel_list_shutdown_and_unref(
for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { for (size_t i = 0; i < subchannel_list->num_subchannels; i++) {
subchannel_data *sd = &subchannel_list->subchannels[i]; subchannel_data *sd = &subchannel_list->subchannels[i];
if (sd->subchannel != NULL) { // if subchannel isn't shutdown, unsubscribe. if (sd->subchannel != NULL) { // if subchannel isn't shutdown, unsubscribe.
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] Unsubscribing from subchannel %p as part of shutting down " "[RR %p] Unsubscribing from subchannel %p as part of shutting down "
@ -249,7 +248,7 @@ static void rr_subchannel_list_shutdown_and_unref(
static size_t get_next_ready_subchannel_index_locked( static size_t get_next_ready_subchannel_index_locked(
const round_robin_lb_policy *p) { const round_robin_lb_policy *p) {
GPR_ASSERT(p->subchannel_list != NULL); GPR_ASSERT(p->subchannel_list != NULL);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"[RR %p] getting next ready subchannel (out of %lu), " "[RR %p] getting next ready subchannel (out of %lu), "
"last_ready_subchannel_index=%lu", "last_ready_subchannel_index=%lu",
@ -259,7 +258,7 @@ static size_t get_next_ready_subchannel_index_locked(
for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) {
const size_t index = (i + p->last_ready_subchannel_index + 1) % const size_t index = (i + p->last_ready_subchannel_index + 1) %
p->subchannel_list->num_subchannels; p->subchannel_list->num_subchannels;
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] checking subchannel %p, subchannel_list %p, index %lu: " "[RR %p] checking subchannel %p, subchannel_list %p, index %lu: "
@ -271,7 +270,7 @@ static size_t get_next_ready_subchannel_index_locked(
} }
if (p->subchannel_list->subchannels[index].curr_connectivity_state == if (p->subchannel_list->subchannels[index].curr_connectivity_state ==
GRPC_CHANNEL_READY) { GRPC_CHANNEL_READY) {
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[RR %p] found next ready subchannel (%p) at index %lu of " "[RR %p] found next ready subchannel (%p) at index %lu of "
"subchannel_list %p", "subchannel_list %p",
@ -282,7 +281,7 @@ static size_t get_next_ready_subchannel_index_locked(
return index; return index;
} }
} }
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, "[RR %p] no subchannels in ready state", (void *)p); gpr_log(GPR_DEBUG, "[RR %p] no subchannels in ready state", (void *)p);
} }
return p->subchannel_list->num_subchannels; return p->subchannel_list->num_subchannels;
@ -293,7 +292,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy *p,
size_t last_ready_index) { size_t last_ready_index) {
GPR_ASSERT(last_ready_index < p->subchannel_list->num_subchannels); GPR_ASSERT(last_ready_index < p->subchannel_list->num_subchannels);
p->last_ready_subchannel_index = last_ready_index; p->last_ready_subchannel_index = last_ready_index;
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)", "[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)",
@ -306,7 +305,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy *p,
static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
round_robin_lb_policy *p = (round_robin_lb_policy *)pol; round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p",
(void *)pol, (void *)pol); (void *)pol, (void *)pol);
} }
@ -317,7 +316,7 @@ static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
static void rr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { static void rr_shutdown_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
round_robin_lb_policy *p = (round_robin_lb_policy *)pol; round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, "[RR %p] Shutting down Round Robin policy at %p", gpr_log(GPR_DEBUG, "[RR %p] Shutting down Round Robin policy at %p",
(void *)pol, (void *)pol); (void *)pol, (void *)pol);
} }
@ -424,7 +423,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
grpc_closure *on_complete) { grpc_closure *on_complete) {
round_robin_lb_policy *p = (round_robin_lb_policy *)pol; round_robin_lb_policy *p = (round_robin_lb_policy *)pol;
GPR_ASSERT(!p->shutdown); GPR_ASSERT(!p->shutdown);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_INFO, "[RR %p] Trying to pick", (void *)pol); gpr_log(GPR_INFO, "[RR %p] Trying to pick", (void *)pol);
} }
if (p->subchannel_list != NULL) { if (p->subchannel_list != NULL) {
@ -438,7 +437,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol,
if (user_data != NULL) { if (user_data != NULL) {
*user_data = sd->user_data; *user_data = sd->user_data;
} }
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, " "[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, "
@ -558,7 +557,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) { grpc_error *error) {
subchannel_data *sd = (subchannel_data *)arg; subchannel_data *sd = (subchannel_data *)arg;
round_robin_lb_policy *p = sd->subchannel_list->policy; round_robin_lb_policy *p = sd->subchannel_list->policy;
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"[RR %p] connectivity changed for subchannel %p, subchannel_list %p: " "[RR %p] connectivity changed for subchannel %p, subchannel_list %p: "
@ -644,7 +643,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
// for sds belonging to outdated subchannel lists. // for sds belonging to outdated subchannel lists.
GPR_ASSERT(sd->subchannel_list == p->latest_pending_subchannel_list); GPR_ASSERT(sd->subchannel_list == p->latest_pending_subchannel_list);
GPR_ASSERT(!sd->subchannel_list->shutting_down); GPR_ASSERT(!sd->subchannel_list->shutting_down);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
const unsigned long num_subchannels = const unsigned long num_subchannels =
p->subchannel_list != NULL p->subchannel_list != NULL
? (unsigned long)p->subchannel_list->num_subchannels ? (unsigned long)p->subchannel_list->num_subchannels
@ -684,7 +683,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg,
if (pp->user_data != NULL) { if (pp->user_data != NULL) {
*pp->user_data = selected->user_data; *pp->user_data = selected->user_data;
} }
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[RR %p] Fulfilling pending pick. Target <-- subchannel %p " "[RR %p] Fulfilling pending pick. Target <-- subchannel %p "
"(subchannel_list %p, index %lu)", "(subchannel_list %p, index %lu)",
@ -774,7 +773,7 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
} }
size_t subchannel_index = 0; size_t subchannel_index = 0;
if (p->latest_pending_subchannel_list != NULL && p->started_picking) { if (p->latest_pending_subchannel_list != NULL && p->started_picking) {
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"[RR %p] Shutting down latest pending subchannel list %p, about " "[RR %p] Shutting down latest pending subchannel list %p, about "
"to be replaced by newer latest %p", "to be replaced by newer latest %p",
@ -816,7 +815,7 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
continue; continue;
} }
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
char *address_uri = char *address_uri =
grpc_sockaddr_to_uri(&addresses->addresses[i].address); grpc_sockaddr_to_uri(&addresses->addresses[i].address);
gpr_log( gpr_log(
@ -896,7 +895,7 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx,
grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE,
"round_robin"); "round_robin");
rr_update_locked(exec_ctx, &p->base, args); rr_update_locked(exec_ctx, &p->base, args);
if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { if (grpc_lb_round_robin_trace.enabled()) {
gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void *)p, gpr_log(GPR_DEBUG, "[RR %p] Created with %lu subchannels", (void *)p,
(unsigned long)p->subchannel_list->num_subchannels); (unsigned long)p->subchannel_list->num_subchannels);
} }
@ -918,7 +917,6 @@ static grpc_lb_policy_factory *round_robin_lb_factory_create() {
extern "C" void grpc_lb_policy_round_robin_init() { extern "C" void grpc_lb_policy_round_robin_init() {
grpc_register_lb_policy(round_robin_lb_factory_create()); grpc_register_lb_policy(round_robin_lb_factory_create());
grpc_register_tracer(&grpc_lb_round_robin_trace);
} }
extern "C" void grpc_lb_policy_round_robin_shutdown() {} extern "C" void grpc_lb_policy_round_robin_shutdown() {}

@ -19,10 +19,8 @@
#include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/ext/filters/client_channel/resolver.h"
#include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/combiner.h"
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false,
grpc_tracer_flag grpc_trace_resolver_refcount = "resolver_refcount");
GRPC_TRACER_INITIALIZER(false, "resolver_refcount");
#endif
void grpc_resolver_init(grpc_resolver *resolver, void grpc_resolver_init(grpc_resolver *resolver,
const grpc_resolver_vtable *vtable, const grpc_resolver_vtable *vtable,
@ -35,7 +33,7 @@ void grpc_resolver_init(grpc_resolver *resolver,
#ifndef NDEBUG #ifndef NDEBUG
void grpc_resolver_ref(grpc_resolver *resolver, const char *file, int line, void grpc_resolver_ref(grpc_resolver *resolver, const char *file, int line,
const char *reason) { const char *reason) {
if (GRPC_TRACER_ON(grpc_trace_resolver_refcount)) { if (grpc_trace_resolver_refcount.enabled()) {
gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"RESOLVER:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", resolver, "RESOLVER:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", resolver,
@ -50,7 +48,7 @@ void grpc_resolver_ref(grpc_resolver *resolver) {
#ifndef NDEBUG #ifndef NDEBUG
void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
const char *file, int line, const char *reason) { const char *file, int line, const char *reason) {
if (GRPC_TRACER_ON(grpc_trace_resolver_refcount)) { if (grpc_trace_resolver_refcount.enabled()) {
gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count); gpr_atm old_refs = gpr_atm_no_barrier_load(&resolver->refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"RESOLVER:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", resolver, "RESOLVER:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", resolver,

@ -30,7 +30,7 @@ typedef struct grpc_resolver grpc_resolver;
typedef struct grpc_resolver_vtable grpc_resolver_vtable; typedef struct grpc_resolver_vtable grpc_resolver_vtable;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_resolver_refcount; extern grpc_core::TraceFlag grpc_trace_resolver_refcount;
#endif #endif
/** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */

@ -199,7 +199,7 @@ static gpr_atm ref_mutate(grpc_subchannel *c, gpr_atm delta,
gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta) gpr_atm old_val = barrier ? gpr_atm_full_fetch_add(&c->ref_pair, delta)
: gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta); : gpr_atm_no_barrier_fetch_add(&c->ref_pair, delta);
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { if (grpc_trace_stream_refcount.enabled()) {
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"SUBCHANNEL: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c, "SUBCHANNEL: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c,
purpose, old_val, old_val + delta, reason); purpose, old_val, old_val + delta, reason);

@ -65,7 +65,6 @@ static bool maybe_add_required_filter(grpc_exec_ctx *exec_ctx,
} }
extern "C" void grpc_http_filters_init(void) { extern "C" void grpc_http_filters_init(void) {
grpc_register_tracer(&grpc_compression_trace);
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_optional_filter, &compress_filter); maybe_add_optional_filter, &compress_filter);

@ -243,7 +243,7 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
bool did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm, bool did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm,
&calld->slices, &tmp); &calld->slices, &tmp);
if (did_compress) { if (did_compress) {
if (GRPC_TRACER_ON(grpc_compression_trace)) { if (grpc_compression_trace.enabled()) {
const char *algo_name; const char *algo_name;
const size_t before_size = calld->slices.length; const size_t before_size = calld->slices.length;
const size_t after_size = tmp.length; const size_t after_size = tmp.length;
@ -257,7 +257,7 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
grpc_slice_buffer_swap(&calld->slices, &tmp); grpc_slice_buffer_swap(&calld->slices, &tmp);
send_flags |= GRPC_WRITE_INTERNAL_COMPRESS; send_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
} else { } else {
if (GRPC_TRACER_ON(grpc_compression_trace)) { if (grpc_compression_trace.enabled()) {
const char *algo_name; const char *algo_name;
GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm,
&algo_name)); &algo_name));

@ -21,11 +21,8 @@
#include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/metadata.h"
extern "C" void grpc_chttp2_plugin_init(void) { extern "C" void grpc_chttp2_plugin_init(void) {
grpc_register_tracer(&grpc_http_trace);
grpc_register_tracer(&grpc_flowctl_trace);
grpc_register_tracer(&grpc_trace_http2_stream_state);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer(&grpc_trace_chttp2_refcount);
#endif #endif
} }

@ -90,13 +90,11 @@ static int g_default_max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA;
static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES;
#define MAX_CLIENT_STREAM_ID 0x7fffffffu #define MAX_CLIENT_STREAM_ID 0x7fffffffu
grpc_tracer_flag grpc_http_trace = GRPC_TRACER_INITIALIZER(false, "http"); grpc_core::TraceFlag grpc_http_trace(false, "http");
grpc_tracer_flag grpc_flowctl_trace = GRPC_TRACER_INITIALIZER(false, "flowctl"); grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl");
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false,
grpc_tracer_flag grpc_trace_chttp2_refcount = "chttp2_refcount");
GRPC_TRACER_INITIALIZER(false, "chttp2_refcount");
#endif
/* forward declarations of various callbacks that we'll build closures around */ /* forward declarations of various callbacks that we'll build closures around */
static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *t, static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *t,
@ -233,7 +231,7 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx,
void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx, void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx,
grpc_chttp2_transport *t, const char *reason, grpc_chttp2_transport *t, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_chttp2_refcount)) { if (grpc_trace_chttp2_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count);
gpr_log(GPR_DEBUG, "chttp2:unref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", gpr_log(GPR_DEBUG, "chttp2:unref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]",
t, val, val - 1, reason, file, line); t, val, val - 1, reason, file, line);
@ -244,7 +242,7 @@ void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx,
void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason, void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_chttp2_refcount)) { if (grpc_trace_chttp2_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count); gpr_atm val = gpr_atm_no_barrier_load(&t->refs.count);
gpr_log(GPR_DEBUG, "chttp2: ref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", gpr_log(GPR_DEBUG, "chttp2: ref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]",
t, val, val + 1, reason, file, line); t, val, val + 1, reason, file, line);
@ -1228,7 +1226,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx,
return; return;
} }
closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT; closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT;
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
const char *errstr = grpc_error_string(error); const char *errstr = grpc_error_string(error);
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
@ -1387,7 +1385,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx); GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx);
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
char *str = grpc_transport_stream_op_batch_string(op); char *str = grpc_transport_stream_op_batch_string(op);
gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str, gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str,
op->on_complete); op->on_complete);
@ -1677,7 +1675,7 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
} }
} }
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
char *str = grpc_transport_stream_op_batch_string(op); char *str = grpc_transport_stream_op_batch_string(op);
gpr_log(GPR_DEBUG, "perform_stream_op[s=%p]: %s", s, str); gpr_log(GPR_DEBUG, "perform_stream_op[s=%p]: %s", s, str);
gpr_free(str); gpr_free(str);
@ -2579,7 +2577,7 @@ static void schedule_bdp_ping_locked(grpc_exec_ctx *exec_ctx,
static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
grpc_error *error) { grpc_error *error) {
grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp;
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string, gpr_log(GPR_DEBUG, "%s: Start BDP ping err=%s", t->peer_string,
grpc_error_string(error)); grpc_error_string(error));
} }
@ -2593,7 +2591,7 @@ static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
grpc_error *error) { grpc_error *error) {
grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp;
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string, gpr_log(GPR_DEBUG, "%s: Complete BDP ping err=%s", t->peer_string,
grpc_error_string(error)); grpc_error_string(error));
} }
@ -3093,7 +3091,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_chttp2_stream_map_size(&t->stream_map) == 0) { grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
/* Channel with no active streams: send a goaway to try and make it /* Channel with no active streams: send a goaway to try and make it
* disconnect cleanly */ * disconnect cleanly */
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory", gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory",
t->peer_string); t->peer_string);
} }
@ -3101,8 +3099,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error_set_int( grpc_error_set_int(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
} else if (error == GRPC_ERROR_NONE && } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace.enabled()) {
GRPC_TRACER_ON(grpc_resource_quota_trace)) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
" streams", " streams",
@ -3124,7 +3121,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
if (error == GRPC_ERROR_NONE && n > 0) { if (error == GRPC_ERROR_NONE && n > 0) {
grpc_chttp2_stream *s = grpc_chttp2_stream *s =
(grpc_chttp2_stream *)grpc_chttp2_stream_map_rand(&t->stream_map); (grpc_chttp2_stream *)grpc_chttp2_stream_map_rand(&t->stream_map);
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string, gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string,
s->id); s->id);
} }

@ -27,12 +27,12 @@
extern "C" { extern "C" {
#endif #endif
extern grpc_tracer_flag grpc_http_trace; extern grpc_core::TraceFlag grpc_http_trace;
extern grpc_tracer_flag grpc_flowctl_trace; extern grpc_core::TraceFlag grpc_flowctl_trace;
extern grpc_tracer_flag grpc_trace_http2_stream_state; extern grpc_core::TraceFlag grpc_trace_http2_stream_state;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_chttp2_refcount; extern grpc_core::TraceFlag grpc_trace_chttp2_refcount;
#endif #endif
grpc_transport *grpc_create_chttp2_transport( grpc_transport *grpc_create_chttp2_transport(

@ -204,20 +204,19 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p,
parser->incoming_settings[id] != parser->value) { parser->incoming_settings[id] != parser->value) {
t->initial_window_update += t->initial_window_update +=
(int64_t)parser->value - parser->incoming_settings[id]; (int64_t)parser->value - parser->incoming_settings[id];
if (GRPC_TRACER_ON(grpc_http_trace) || if (grpc_http_trace.enabled() || grpc_flowctl_trace.enabled()) {
GRPC_TRACER_ON(grpc_flowctl_trace)) {
gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change", gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change",
t, t->is_client ? "cli" : "svr", t, t->is_client ? "cli" : "svr",
(int)t->initial_window_update); (int)t->initial_window_update);
} }
} }
parser->incoming_settings[id] = parser->value; parser->incoming_settings[id] = parser->value;
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "CHTTP2:%s:%s: got setting %s = %d", gpr_log(GPR_DEBUG, "CHTTP2:%s:%s: got setting %s = %d",
t->is_client ? "CLI" : "SVR", t->peer_string, sp->name, t->is_client ? "CLI" : "SVR", t->peer_string, sp->name,
parser->value); parser->value);
} }
} else if (GRPC_TRACER_ON(grpc_http_trace)) { } else if (grpc_http_trace.enabled()) {
gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)", gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)",
parser->id, parser->value); parser->id, parser->value);
} }

@ -57,7 +57,7 @@ static const grpc_slice terminal_slice = {
{{0, 0}} /* data.refcounted */ {{0, 0}} /* data.refcounted */
}; };
extern "C" grpc_tracer_flag grpc_http_trace; extern grpc_core::TraceFlag grpc_http_trace;
typedef struct { typedef struct {
int is_first_frame; int is_first_frame;
@ -475,7 +475,7 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c,
"Reserved header (colon-prefixed) happening after regular ones."); "Reserved header (colon-prefixed) happening after regular ones.");
} }
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem));
char *v = NULL; char *v = NULL;
if (grpc_is_binary_header(GRPC_MDKEY(elem))) { if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
@ -670,7 +670,7 @@ void grpc_chttp2_hpack_compressor_set_max_table_size(
} }
} }
c->advertise_table_size_change = 1; c->advertise_table_size_change = 1;
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "set max table size from encoder to %d", max_table_size); gpr_log(GPR_DEBUG, "set max table size from encoder to %d", max_table_size);
} }
} }

@ -650,7 +650,7 @@ static const uint8_t inverse_base64[256] = {
/* emission helpers */ /* emission helpers */
static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p,
grpc_mdelem md, int add_to_table) { grpc_mdelem md, int add_to_table) {
if (GRPC_TRACER_ON(grpc_http_trace) && !GRPC_MDELEM_IS_INTERNED(md)) { if (grpc_http_trace.enabled() && !GRPC_MDELEM_IS_INTERNED(md)) {
char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); char *k = grpc_slice_to_c_string(GRPC_MDKEY(md));
char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md));
gpr_log( gpr_log(
@ -1041,7 +1041,7 @@ static grpc_error *parse_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx,
static grpc_error *finish_max_tbl_size(grpc_exec_ctx *exec_ctx, static grpc_error *finish_max_tbl_size(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser *p,
const uint8_t *cur, const uint8_t *end) { const uint8_t *cur, const uint8_t *end) {
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
} }
grpc_error *err = grpc_error *err =

@ -28,7 +28,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/support/murmur_hash.h" #include "src/core/lib/support/murmur_hash.h"
extern "C" grpc_tracer_flag grpc_http_trace; extern grpc_core::TraceFlag grpc_http_trace;
static struct { static struct {
const char *key; const char *key;
@ -246,7 +246,7 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx,
if (tbl->max_bytes == max_bytes) { if (tbl->max_bytes == max_bytes) {
return; return;
} }
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes); gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes);
} }
while (tbl->mem_used > max_bytes) { while (tbl->mem_used > max_bytes) {
@ -270,7 +270,7 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx,
gpr_free(msg); gpr_free(msg);
return err; return err;
} }
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes); gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes);
} }
while (tbl->mem_used > bytes) { while (tbl->mem_used > bytes) {

@ -678,11 +678,11 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx,
#define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \
(sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1)
extern grpc_tracer_flag grpc_http_trace; extern grpc_core::TraceFlag grpc_http_trace;
extern grpc_tracer_flag grpc_flowctl_trace; extern grpc_core::TraceFlag grpc_flowctl_trace;
#define GRPC_CHTTP2_IF_TRACING(stmt) \ #define GRPC_CHTTP2_IF_TRACING(stmt) \
if (!(GRPC_TRACER_ON(grpc_http_trace))) \ if (!grpc_http_trace.enabled()) \
; \ ; \
else \ else \
stmt stmt

@ -310,7 +310,7 @@ static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx,
case GRPC_CHTTP2_FRAME_GOAWAY: case GRPC_CHTTP2_FRAME_GOAWAY:
return init_goaway_parser(exec_ctx, t); return init_goaway_parser(exec_ctx, t);
default: default:
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
gpr_log(GPR_ERROR, "Unknown frame type %02x", t->incoming_frame_type); gpr_log(GPR_ERROR, "Unknown frame type %02x", t->incoming_frame_type);
} }
return init_skip_frame_parser(exec_ctx, t, 0); return init_skip_frame_parser(exec_ctx, t, 0);
@ -415,7 +415,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp,
GPR_ASSERT(s != NULL); GPR_ASSERT(s != NULL);
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char *key = grpc_slice_to_c_string(GRPC_MDKEY(md));
char *value = char *value =
grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -497,7 +497,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp,
GPR_ASSERT(s != NULL); GPR_ASSERT(s != NULL);
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char *key = grpc_slice_to_c_string(GRPC_MDKEY(md));
char *value = char *value =
grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII);
@ -750,7 +750,7 @@ static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx,
if (err == GRPC_ERROR_NONE) { if (err == GRPC_ERROR_NONE) {
return err; return err;
} else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) { } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) {
if (GRPC_TRACER_ON(grpc_http_trace)) { if (grpc_http_trace.enabled()) {
const char *msg = grpc_error_string(err); const char *msg = grpc_error_string(err);
gpr_log(GPR_ERROR, "%s", msg); gpr_log(GPR_ERROR, "%s", msg);
} }

@ -39,8 +39,7 @@ static const char *stream_list_id_string(grpc_chttp2_stream_list_id id) {
GPR_UNREACHABLE_CODE(return "unknown"); GPR_UNREACHABLE_CODE(return "unknown");
} }
grpc_tracer_flag grpc_trace_http2_stream_state = grpc_core::TraceFlag grpc_trace_http2_stream_state(false, "http2_stream_state");
GRPC_TRACER_INITIALIZER(false, "http2_stream_state");
/* core list management */ /* core list management */
@ -66,7 +65,7 @@ static bool stream_list_pop(grpc_chttp2_transport *t,
s->included[id] = 0; s->included[id] = 0;
} }
*stream = s; *stream = s;
if (s && GRPC_TRACER_ON(grpc_trace_http2_stream_state)) { if (s && grpc_trace_http2_stream_state.enabled()) {
gpr_log(GPR_DEBUG, "%p[%d][%s]: pop from %s", t, s->id, gpr_log(GPR_DEBUG, "%p[%d][%s]: pop from %s", t, s->id,
t->is_client ? "cli" : "svr", stream_list_id_string(id)); t->is_client ? "cli" : "svr", stream_list_id_string(id));
} }
@ -88,7 +87,7 @@ static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s,
} else { } else {
t->lists[id].tail = s->links[id].prev; t->lists[id].tail = s->links[id].prev;
} }
if (GRPC_TRACER_ON(grpc_trace_http2_stream_state)) { if (grpc_trace_http2_stream_state.enabled()) {
gpr_log(GPR_DEBUG, "%p[%d][%s]: remove from %s", t, s->id, gpr_log(GPR_DEBUG, "%p[%d][%s]: remove from %s", t, s->id,
t->is_client ? "cli" : "svr", stream_list_id_string(id)); t->is_client ? "cli" : "svr", stream_list_id_string(id));
} }
@ -120,7 +119,7 @@ static void stream_list_add_tail(grpc_chttp2_transport *t,
} }
t->lists[id].tail = s; t->lists[id].tail = s;
s->included[id] = 1; s->included[id] = 1;
if (GRPC_TRACER_ON(grpc_trace_http2_stream_state)) { if (grpc_trace_http2_stream_state.enabled()) {
gpr_log(GPR_DEBUG, "%p[%d][%s]: add to %s", t, s->id, gpr_log(GPR_DEBUG, "%p[%d][%s]: add to %s", t, s->id,
t->is_client ? "cli" : "svr", stream_list_id_string(id)); t->is_client ? "cli" : "svr", stream_list_id_string(id));
} }

@ -51,8 +51,7 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx,
} }
if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_INFLIGHT])) { if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_INFLIGHT])) {
/* ping already in-flight: wait */ /* ping already in-flight: wait */
if (GRPC_TRACER_ON(grpc_http_trace) || if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) {
GRPC_TRACER_ON(grpc_bdp_estimator_trace)) {
gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: already pinging", gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: already pinging",
t->is_client ? "CLIENT" : "SERVER", t->peer_string); t->is_client ? "CLIENT" : "SERVER", t->peer_string);
} }
@ -61,8 +60,7 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx,
if (t->ping_state.pings_before_data_required == 0 && if (t->ping_state.pings_before_data_required == 0 &&
t->ping_policy.max_pings_without_data != 0) { t->ping_policy.max_pings_without_data != 0) {
/* need to receive something of substance before sending a ping again */ /* need to receive something of substance before sending a ping again */
if (GRPC_TRACER_ON(grpc_http_trace) || if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) {
GRPC_TRACER_ON(grpc_bdp_estimator_trace)) {
gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: too many recent pings: %d/%d", gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: too many recent pings: %d/%d",
t->is_client ? "CLIENT" : "SERVER", t->peer_string, t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->ping_state.pings_before_data_required, t->ping_state.pings_before_data_required,
@ -81,8 +79,7 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx,
} }
if (next_allowed_ping > now) { if (next_allowed_ping > now) {
/* not enough elapsed time between successive pings */ /* not enough elapsed time between successive pings */
if (GRPC_TRACER_ON(grpc_http_trace) || if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) {
GRPC_TRACER_ON(grpc_bdp_estimator_trace)) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"%s: Ping delayed [%p]: not enough time elapsed since last ping", "%s: Ping delayed [%p]: not enough time elapsed since last ping",
t->is_client ? "CLIENT" : "SERVER", t->peer_string); t->is_client ? "CLIENT" : "SERVER", t->peer_string);
@ -103,8 +100,7 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx,
grpc_chttp2_ping_create(false, pq->inflight_id)); grpc_chttp2_ping_create(false, pq->inflight_id));
GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx); GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx);
t->ping_state.last_ping_sent_time = now; t->ping_state.last_ping_sent_time = now;
if (GRPC_TRACER_ON(grpc_http_trace) || if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) {
GRPC_TRACER_ON(grpc_bdp_estimator_trace)) {
gpr_log(GPR_DEBUG, "%s: Ping sent [%p]: %d/%d", gpr_log(GPR_DEBUG, "%s: Ping sent [%p]: %d/%d",
t->is_client ? "CLIENT" : "SERVER", t->peer_string, t->is_client ? "CLIENT" : "SERVER", t->peer_string,
t->ping_state.pings_before_data_required, t->ping_state.pings_before_data_required,

@ -19,12 +19,9 @@
#include "src/core/ext/transport/inproc/inproc_transport.h" #include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
grpc_tracer_flag grpc_inproc_trace = GRPC_TRACER_INITIALIZER(false, "inproc"); grpc_core::TraceFlag grpc_inproc_trace(false, "inproc");
extern "C" void grpc_inproc_plugin_init(void) { extern "C" void grpc_inproc_plugin_init(void) { grpc_inproc_transport_init(); }
grpc_register_tracer(&grpc_inproc_trace);
grpc_inproc_transport_init();
}
extern "C" void grpc_inproc_plugin_shutdown(void) { extern "C" void grpc_inproc_plugin_shutdown(void) {
grpc_inproc_transport_shutdown(); grpc_inproc_transport_shutdown();

@ -34,7 +34,7 @@
#define INPROC_LOG(...) \ #define INPROC_LOG(...) \
do { \ do { \
if (GRPC_TRACER_ON(grpc_inproc_trace)) gpr_log(__VA_ARGS__); \ if (grpc_inproc_trace.enabled()) gpr_log(__VA_ARGS__); \
} while (0) } while (0)
static grpc_slice g_empty_slice; static grpc_slice g_empty_slice;
@ -199,7 +199,7 @@ static grpc_error *fill_in_metadata(grpc_exec_ctx *exec_ctx, inproc_stream *s,
const grpc_metadata_batch *metadata, const grpc_metadata_batch *metadata,
uint32_t flags, grpc_metadata_batch *out_md, uint32_t flags, grpc_metadata_batch *out_md,
uint32_t *outflags, bool *markfilled) { uint32_t *outflags, bool *markfilled) {
if (GRPC_TRACER_ON(grpc_inproc_trace)) { if (grpc_inproc_trace.enabled()) {
log_metadata(metadata, s->t->is_client, outflags != NULL); log_metadata(metadata, s->t->is_client, outflags != NULL);
} }
@ -870,7 +870,7 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
gpr_mu *mu = &s->t->mu->mu; // save aside in case s gets closed gpr_mu *mu = &s->t->mu->mu; // save aside in case s gets closed
gpr_mu_lock(mu); gpr_mu_lock(mu);
if (GRPC_TRACER_ON(grpc_inproc_trace)) { if (grpc_inproc_trace.enabled()) {
if (op->send_initial_metadata) { if (op->send_initial_metadata) {
log_metadata(op->payload->send_initial_metadata.send_initial_metadata, log_metadata(op->payload->send_initial_metadata.send_initial_metadata,
s->t->is_client, true); s->t->is_client, true);

@ -29,7 +29,7 @@ grpc_channel *grpc_inproc_channel_create(grpc_server *server,
grpc_channel_args *args, grpc_channel_args *args,
void *reserved); void *reserved);
extern grpc_tracer_flag grpc_inproc_trace; extern grpc_core::TraceFlag grpc_inproc_trace;
void grpc_inproc_transport_init(void); void grpc_inproc_transport_init(void);
void grpc_inproc_transport_shutdown(void); void grpc_inproc_transport_shutdown(void);

@ -23,7 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
grpc_tracer_flag grpc_trace_channel = GRPC_TRACER_INITIALIZER(false, "channel"); grpc_core::TraceFlag grpc_trace_channel(false, "channel");
/* Memory layouts. /* Memory layouts.

@ -285,10 +285,10 @@ void grpc_call_log_op(const char *file, int line, gpr_log_severity severity,
grpc_call_element *elem, grpc_call_element *elem,
grpc_transport_stream_op_batch *op); grpc_transport_stream_op_batch *op);
extern grpc_tracer_flag grpc_trace_channel; extern grpc_core::TraceFlag grpc_trace_channel;
#define GRPC_CALL_LOG_OP(sev, elem, op) \ #define GRPC_CALL_LOG_OP(sev, elem, op) \
if (GRPC_TRACER_ON(grpc_trace_channel)) grpc_call_log_op(sev, elem, op) if (grpc_trace_channel.enabled()) grpc_call_log_op(sev, elem, op)
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -23,8 +23,8 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
grpc_tracer_flag grpc_trace_channel_stack_builder = grpc_core::TraceFlag grpc_trace_channel_stack_builder(false,
GRPC_TRACER_INITIALIZER(false, "channel_stack_builder"); "channel_stack_builder");
typedef struct filter_node { typedef struct filter_node {
struct filter_node *next; struct filter_node *next;

@ -160,7 +160,7 @@ grpc_error *grpc_channel_stack_builder_finish(
void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx, void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder); grpc_channel_stack_builder *builder);
extern grpc_tracer_flag grpc_trace_channel_stack_builder; extern grpc_core::TraceFlag grpc_trace_channel_stack_builder;
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -27,26 +27,53 @@
int grpc_tracer_set_enabled(const char *name, int enabled); int grpc_tracer_set_enabled(const char *name, int enabled);
typedef struct tracer { namespace grpc_core {
grpc_tracer_flag *flag;
struct tracer *next; TraceFlag::TraceFlag(bool default_enabled, const char *name)
} tracer; : next_tracer_(root_tracer_), name_(name), value_(default_enabled) {
static tracer *tracers; root_tracer_ = this;
}
#ifdef GRPC_THREADSAFE_TRACER
#define TRACER_SET(flag, on) gpr_atm_no_barrier_store(&(flag).value, (on)) void TraceFlag::List() {
#else gpr_log(GPR_DEBUG, "available tracers:");
#define TRACER_SET(flag, on) (flag).value = (on) TraceFlag *t;
#endif for (t = root_tracer_; t != nullptr; t = t->next_tracer_) {
gpr_log(GPR_DEBUG, "\t%s", t->name_);
void grpc_register_tracer(grpc_tracer_flag *flag) { }
tracer *t = (tracer *)gpr_malloc(sizeof(*t)); }
t->flag = flag;
t->next = tracers; bool TraceFlag::Set(const char *name, bool enabled) {
TRACER_SET(*flag, false); TraceFlag *t;
tracers = t; if (0 == strcmp(name, "all")) {
for (t = root_tracer_; t; t = t->next_tracer_) {
t->set_enabled(enabled);
}
} else if (0 == strcmp(name, "list_tracers")) {
List();
} else if (0 == strcmp(name, "refcount")) {
for (t = root_tracer_; t; t = t->next_tracer_) {
if (strstr(t->name_, "refcount") != NULL) {
t->set_enabled(enabled);
}
}
} else {
bool found = false;
for (t = root_tracer_; t; t = t->next_tracer_) {
if (0 == strcmp(name, t->name_)) {
t->set_enabled(enabled);
found = true;
}
}
if (!found) {
gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
return false; /* early return */
}
}
return true;
} }
} // 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) {
size_t n = *ns; size_t n = *ns;
size_t np = n + 1; size_t np = n + 1;
@ -80,9 +107,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_tracer_set_enabled(strings[i] + 1, 0); grpc_core::TraceFlag::Set(strings[i] + 1, false);
} else { } else {
grpc_tracer_set_enabled(strings[i], 1); grpc_core::TraceFlag::Set(strings[i], true);
} }
} }
@ -92,14 +119,6 @@ static void parse(const char *s) {
gpr_free(strings); gpr_free(strings);
} }
static void list_tracers() {
gpr_log(GPR_DEBUG, "available tracers:");
tracer *t;
for (t = tracers; t; t = t->next) {
gpr_log(GPR_DEBUG, "\t%s", t->flag->name);
}
}
void grpc_tracer_init(const char *env_var) { void grpc_tracer_init(const char *env_var) {
char *e = gpr_getenv(env_var); char *e = gpr_getenv(env_var);
if (e != NULL) { if (e != NULL) {
@ -108,40 +127,8 @@ void grpc_tracer_init(const char *env_var) {
} }
} }
void grpc_tracer_shutdown(void) { void grpc_tracer_shutdown(void) {}
while (tracers) {
tracer *t = tracers;
tracers = t->next;
gpr_free(t);
}
}
int grpc_tracer_set_enabled(const char *name, int enabled) { int grpc_tracer_set_enabled(const char *name, int enabled) {
tracer *t; return grpc_core::TraceFlag::Set(name, enabled != 0);
if (0 == strcmp(name, "all")) {
for (t = tracers; t; t = t->next) {
TRACER_SET(*t->flag, enabled);
}
} else if (0 == strcmp(name, "list_tracers")) {
list_tracers();
} else if (0 == strcmp(name, "refcount")) {
for (t = tracers; t; t = t->next) {
if (strstr(t->flag->name, "refcount") != NULL) {
TRACER_SET(*t->flag, enabled);
}
}
} else {
int found = 0;
for (t = tracers; t; t = t->next) {
if (0 == strcmp(name, t->flag->name)) {
TRACER_SET(*t->flag, enabled);
found = 1;
}
}
if (!found) {
gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
return 0; /* early return */
}
}
return 1;
} }

@ -27,37 +27,71 @@
extern "C" { extern "C" {
#endif #endif
void grpc_tracer_init(const char *env_var_name);
void grpc_tracer_shutdown(void);
#ifdef __cplusplus
}
#endif
#if defined(__has_feature) #if defined(__has_feature)
#if __has_feature(thread_sanitizer) #if __has_feature(thread_sanitizer)
#define GRPC_THREADSAFE_TRACER #define GRPC_THREADSAFE_TRACER
#endif #endif
#endif #endif
typedef struct { #ifdef __cplusplus
namespace grpc_core {
class TraceFlag {
public:
TraceFlag(bool default_enabled, const char *name);
~TraceFlag();
static bool Set(const char *tracer, bool enabled);
bool enabled() {
#ifdef GRPC_THREADSAFE_TRACER #ifdef GRPC_THREADSAFE_TRACER
gpr_atm value; gpr_atm_no_barrier_load(&value_) != 0
#else #else
bool value; return value_;
#endif #endif
const char *name; }
} grpc_tracer_flag;
private:
static void List();
void set_enabled(bool enabled) {
#ifdef GRPC_THREADSAFE_TRACER #ifdef GRPC_THREADSAFE_TRACER
#define GRPC_TRACER_ON(flag) (gpr_atm_no_barrier_load(&(flag).value) != 0) gpr_atm_no_barrier_store(&value, enabled);
#define GRPC_TRACER_INITIALIZER(on, name) \
{ (gpr_atm)(on), (name) }
#else #else
#define GRPC_TRACER_ON(flag) ((flag).value) value_ = enabled;
#define GRPC_TRACER_INITIALIZER(on, name) \
{ (on), (name) }
#endif #endif
}
void grpc_register_tracer(grpc_tracer_flag *flag); static TraceFlag *root_tracer_;
void grpc_tracer_init(const char *env_var_name); TraceFlag *next_tracer_;
void grpc_tracer_shutdown(void); const char *const name_;
#ifdef GRPC_THREADSAFE_TRACER
gpr_atm value_;
#else
bool value_;
#endif
};
#ifdef __cplusplus #ifndef NDEBUG
} typedef TraceFlag DebugOnlyTraceFlag;
#else
class DebugOnlyTraceFlag {
public:
DebugOnlyTraceFlag(bool default_enabled, const char *name) {}
bool enabled() { return false; }
};
#endif #endif
} // namespace grpc_core
#endif // __cplusplus
#endif /* GRPC_CORE_LIB_DEBUG_TRACE_H */ #endif /* GRPC_CORE_LIB_DEBUG_TRACE_H */

@ -25,7 +25,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/useful.h> #include <grpc/support/useful.h>
grpc_tracer_flag grpc_http1_trace = GRPC_TRACER_INITIALIZER(false, "http1"); grpc_core::TraceFlag grpc_http1_trace(false, "http1");
static char *buf2str(void *buffer, size_t length) { static char *buf2str(void *buffer, size_t length) {
char *out = (char *)gpr_malloc(length + 1); char *out = (char *)gpr_malloc(length + 1);
@ -294,7 +294,7 @@ static grpc_error *addbyte(grpc_http_parser *parser, uint8_t byte,
case GRPC_HTTP_FIRST_LINE: case GRPC_HTTP_FIRST_LINE:
case GRPC_HTTP_HEADERS: case GRPC_HTTP_HEADERS:
if (parser->cur_line_length >= GRPC_HTTP_PARSER_MAX_HEADER_LENGTH) { if (parser->cur_line_length >= GRPC_HTTP_PARSER_MAX_HEADER_LENGTH) {
if (GRPC_TRACER_ON(grpc_http1_trace)) if (grpc_http1_trace.enabled())
gpr_log(GPR_ERROR, "HTTP header max line length (%d) exceeded", gpr_log(GPR_ERROR, "HTTP header max line length (%d) exceeded",
GRPC_HTTP_PARSER_MAX_HEADER_LENGTH); GRPC_HTTP_PARSER_MAX_HEADER_LENGTH);
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE_FROM_STATIC_STRING(

@ -111,7 +111,7 @@ grpc_error *grpc_http_parser_eof(grpc_http_parser *parser);
void grpc_http_request_destroy(grpc_http_request *request); void grpc_http_request_destroy(grpc_http_request *request);
void grpc_http_response_destroy(grpc_http_response *response); void grpc_http_response_destroy(grpc_http_response *response);
extern grpc_tracer_flag grpc_http1_trace; extern grpc_core::TraceFlag grpc_http1_trace;
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -24,8 +24,7 @@
#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/stats.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
grpc_tracer_flag grpc_call_combiner_trace = grpc_core::TraceFlag grpc_call_combiner_trace(false, "call_combiner");
GRPC_TRACER_INITIALIZER(false, "call_combiner");
static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) { static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) {
if (cancel_state & 1) { if (cancel_state & 1) {
@ -63,7 +62,7 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx,
grpc_error* error DEBUG_ARGS, grpc_error* error DEBUG_ARGS,
const char* reason) { const char* reason) {
GPR_TIMER_BEGIN("call_combiner_start", 0); GPR_TIMER_BEGIN("call_combiner_start", 0);
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"==> grpc_call_combiner_start() [%p] closure=%p [" DEBUG_FMT_STR "==> grpc_call_combiner_start() [%p] closure=%p [" DEBUG_FMT_STR
"%s] error=%s", "%s] error=%s",
@ -72,7 +71,7 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx,
} }
size_t prev_size = size_t prev_size =
(size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1); (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)1);
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size + 1); prev_size + 1);
} }
@ -80,13 +79,13 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx,
if (prev_size == 0) { if (prev_size == 0) {
GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx); GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx);
GPR_TIMER_MARK("call_combiner_initiate", 0); GPR_TIMER_MARK("call_combiner_initiate", 0);
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " EXECUTING IMMEDIATELY"); gpr_log(GPR_DEBUG, " EXECUTING IMMEDIATELY");
} }
// Queue was empty, so execute this closure immediately. // Queue was empty, so execute this closure immediately.
GRPC_CLOSURE_SCHED(exec_ctx, closure, error); GRPC_CLOSURE_SCHED(exec_ctx, closure, error);
} else { } else {
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_INFO, " QUEUING"); gpr_log(GPR_INFO, " QUEUING");
} }
// Queue was not empty, so add closure to queue. // Queue was not empty, so add closure to queue.
@ -100,21 +99,21 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx,
grpc_call_combiner* call_combiner DEBUG_ARGS, grpc_call_combiner* call_combiner DEBUG_ARGS,
const char* reason) { const char* reason) {
GPR_TIMER_BEGIN("call_combiner_stop", 0); GPR_TIMER_BEGIN("call_combiner_stop", 0);
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"==> grpc_call_combiner_stop() [%p] [" DEBUG_FMT_STR "%s]", "==> grpc_call_combiner_stop() [%p] [" DEBUG_FMT_STR "%s]",
call_combiner DEBUG_FMT_ARGS, reason); call_combiner DEBUG_FMT_ARGS, reason);
} }
size_t prev_size = size_t prev_size =
(size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1); (size_t)gpr_atm_full_fetch_add(&call_combiner->size, (gpr_atm)-1);
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size, gpr_log(GPR_DEBUG, " size: %" PRIdPTR " -> %" PRIdPTR, prev_size,
prev_size - 1); prev_size - 1);
} }
GPR_ASSERT(prev_size >= 1); GPR_ASSERT(prev_size >= 1);
if (prev_size > 1) { if (prev_size > 1) {
while (true) { while (true) {
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " checking queue"); gpr_log(GPR_DEBUG, " checking queue");
} }
bool empty; bool empty;
@ -123,19 +122,19 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx,
if (closure == NULL) { if (closure == NULL) {
// This can happen either due to a race condition within the mpscq // This can happen either due to a race condition within the mpscq
// code or because of a race with grpc_call_combiner_start(). // code or because of a race with grpc_call_combiner_start().
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " queue returned no result; checking again"); gpr_log(GPR_DEBUG, " queue returned no result; checking again");
} }
continue; continue;
} }
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " EXECUTING FROM QUEUE: closure=%p error=%s", gpr_log(GPR_DEBUG, " EXECUTING FROM QUEUE: closure=%p error=%s",
closure, grpc_error_string(closure->error_data.error)); closure, grpc_error_string(closure->error_data.error));
} }
GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error); GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error);
break; break;
} }
} else if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { } else if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, " queue empty"); gpr_log(GPR_DEBUG, " queue empty");
} }
GPR_TIMER_END("call_combiner_stop", 0); GPR_TIMER_END("call_combiner_stop", 0);
@ -152,7 +151,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx,
// If error is set, invoke the cancellation closure immediately. // If error is set, invoke the cancellation closure immediately.
// Otherwise, store the new closure. // Otherwise, store the new closure.
if (original_error != GRPC_ERROR_NONE) { if (original_error != GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"call_combiner=%p: scheduling notify_on_cancel callback=%p " "call_combiner=%p: scheduling notify_on_cancel callback=%p "
"for pre-existing cancellation", "for pre-existing cancellation",
@ -163,7 +162,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx,
} else { } else {
if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state, if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state,
(gpr_atm)closure)) { (gpr_atm)closure)) {
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, "call_combiner=%p: setting notify_on_cancel=%p", gpr_log(GPR_DEBUG, "call_combiner=%p: setting notify_on_cancel=%p",
call_combiner, closure); call_combiner, closure);
} }
@ -172,7 +171,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx,
// up any resources they may be holding for the callback. // up any resources they may be holding for the callback.
if (original_state != 0) { if (original_state != 0) {
closure = (grpc_closure*)original_state; closure = (grpc_closure*)original_state;
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"call_combiner=%p: scheduling old cancel callback=%p", "call_combiner=%p: scheduling old cancel callback=%p",
call_combiner, closure); call_combiner, closure);
@ -201,7 +200,7 @@ void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx,
encode_cancel_state_error(error))) { encode_cancel_state_error(error))) {
if (original_state != 0) { if (original_state != 0) {
grpc_closure* notify_on_cancel = (grpc_closure*)original_state; grpc_closure* notify_on_cancel = (grpc_closure*)original_state;
if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { if (grpc_call_combiner_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"call_combiner=%p: scheduling notify_on_cancel callback=%p", "call_combiner=%p: scheduling notify_on_cancel callback=%p",
call_combiner, notify_on_cancel); call_combiner, notify_on_cancel);

@ -40,7 +40,7 @@ extern "C" {
// when it is done with the action that was kicked off by the original // when it is done with the action that was kicked off by the original
// callback. // callback.
extern grpc_tracer_flag grpc_call_combiner_trace; extern grpc_core::TraceFlag grpc_call_combiner_trace;
typedef struct { typedef struct {
gpr_atm size; // size_t, num closures in queue or currently executing gpr_atm size; // size_t, num closures in queue or currently executing

@ -24,9 +24,7 @@
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_closure(false, "closure");
grpc_tracer_flag grpc_trace_closure = GRPC_TRACER_INITIALIZER(false, "closure");
#endif
#ifndef NDEBUG #ifndef NDEBUG
grpc_closure *grpc_closure_init(const char *file, int line, grpc_closure *grpc_closure_init(const char *file, int line,

@ -34,7 +34,7 @@ struct grpc_closure;
typedef struct grpc_closure grpc_closure; typedef struct grpc_closure grpc_closure;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_closure; extern grpc_core::TraceFlag grpc_trace_closure;
#endif #endif
typedef struct grpc_closure_list { typedef struct grpc_closure_list {

@ -29,12 +29,11 @@
#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
grpc_tracer_flag grpc_combiner_trace = grpc_core::TraceFlag grpc_combiner_trace(false, "combiner");
GRPC_TRACER_INITIALIZER(false, "combiner");
#define GRPC_COMBINER_TRACE(fn) \ #define GRPC_COMBINER_TRACE(fn) \
do { \ do { \
if (GRPC_TRACER_ON(grpc_combiner_trace)) { \ if (grpc_combiner_trace.enabled()) { \
fn; \ fn; \
} \ } \
} while (0) } while (0)
@ -106,7 +105,7 @@ static void start_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock) {
#ifndef NDEBUG #ifndef NDEBUG
#define GRPC_COMBINER_DEBUG_SPAM(op, delta) \ #define GRPC_COMBINER_DEBUG_SPAM(op, delta) \
if (GRPC_TRACER_ON(grpc_combiner_trace)) { \ if (grpc_combiner_trace.enabled()) { \
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, \ gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, \
"C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \ "C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \
gpr_atm_no_barrier_load(&lock->refs.count), \ gpr_atm_no_barrier_load(&lock->refs.count), \

@ -65,7 +65,7 @@ grpc_closure_scheduler *grpc_combiner_finally_scheduler(grpc_combiner *lock);
bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx *exec_ctx); bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx *exec_ctx);
extern grpc_tracer_flag grpc_combiner_trace; extern grpc_core::TraceFlag grpc_combiner_trace;
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -37,10 +37,8 @@
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_internal.h"
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount(false,
grpc_tracer_flag grpc_trace_error_refcount = "error_refcount");
GRPC_TRACER_INITIALIZER(false, "error_refcount");
#endif
static const char *error_int_name(grpc_error_ints key) { static const char *error_int_name(grpc_error_ints key) {
switch (key) { switch (key) {
@ -130,7 +128,7 @@ bool grpc_error_is_special(grpc_error *err) {
#ifndef NDEBUG #ifndef NDEBUG
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line) { grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line) {
if (grpc_error_is_special(err)) return err; if (grpc_error_is_special(err)) return err;
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line); gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line);
@ -183,7 +181,7 @@ static void error_destroy(grpc_error *err) {
#ifndef NDEBUG #ifndef NDEBUG
void grpc_error_unref(grpc_error *err, const char *file, int line) { void grpc_error_unref(grpc_error *err, const char *file, int line) {
if (grpc_error_is_special(err)) return; if (grpc_error_is_special(err)) return;
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line); gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line);
@ -216,7 +214,7 @@ static uint8_t get_placement(grpc_error **err, size_t size) {
*err = (grpc_error *)gpr_realloc( *err = (grpc_error *)gpr_realloc(
*err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)); *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t));
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (grpc_trace_error_refcount.enabled()) {
if (*err != orig) { if (*err != orig) {
gpr_log(GPR_DEBUG, "realloc %p -> %p", orig, *err); gpr_log(GPR_DEBUG, "realloc %p -> %p", orig, *err);
} }
@ -329,7 +327,7 @@ grpc_error *grpc_error_create(const char *file, int line, grpc_slice desc,
return GRPC_ERROR_OOM; return GRPC_ERROR_OOM;
} }
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line); gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line);
} }
#endif #endif
@ -411,7 +409,7 @@ static grpc_error *copy_error_and_unref(grpc_error *in) {
out = (grpc_error *)gpr_malloc(sizeof(*in) + out = (grpc_error *)gpr_malloc(sizeof(*in) +
new_arena_capacity * sizeof(intptr_t)); new_arena_capacity * sizeof(intptr_t));
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (grpc_trace_error_refcount.enabled()) {
gpr_log(GPR_DEBUG, "%p create copying %p", out, in); gpr_log(GPR_DEBUG, "%p create copying %p", out, in);
} }
#endif #endif

@ -39,7 +39,7 @@ extern "C" {
typedef struct grpc_error grpc_error; typedef struct grpc_error grpc_error;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_error_refcount; extern grpc_core::TraceFlag grpc_trace_error_refcount;
#endif #endif
typedef enum { typedef enum {

@ -274,7 +274,7 @@ static grpc_fd *fd_create(int fd, const char *name) {
gpr_asprintf(&fd_name, "%s fd=%d", name, fd); gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name); gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name);
} }
#endif #endif
@ -650,7 +650,7 @@ static grpc_error *do_epoll_wait(grpc_exec_ctx *exec_ctx, grpc_pollset *ps,
GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, r); GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, r);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "ps: %p poll got %d events", ps, r); gpr_log(GPR_DEBUG, "ps: %p poll got %d events", ps, r);
} }
@ -672,7 +672,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT;
pollset->begin_refs++; pollset->begin_refs++;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "PS:%p BEGIN_STARTS:%p", pollset, worker); gpr_log(GPR_ERROR, "PS:%p BEGIN_STARTS:%p", pollset, worker);
} }
@ -691,7 +691,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
retry_lock_neighborhood: retry_lock_neighborhood:
gpr_mu_lock(&neighborhood->mu); gpr_mu_lock(&neighborhood->mu);
gpr_mu_lock(&pollset->mu); gpr_mu_lock(&pollset->mu);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d", gpr_log(GPR_ERROR, "PS:%p BEGIN_REORG:%p kick_state=%s is_reassigning=%d",
pollset, worker, kick_state_string(worker->state), pollset, worker, kick_state_string(worker->state),
is_reassigning); is_reassigning);
@ -743,7 +743,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
worker->initialized_cv = true; worker->initialized_cv = true;
gpr_cv_init(&worker->cv); gpr_cv_init(&worker->cv);
while (worker->state == UNKICKED && !pollset->shutting_down) { while (worker->state == UNKICKED && !pollset->shutting_down) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d", gpr_log(GPR_ERROR, "PS:%p BEGIN_WAIT:%p kick_state=%s shutdown=%d",
pollset, worker, kick_state_string(worker->state), pollset, worker, kick_state_string(worker->state),
pollset->shutting_down); pollset->shutting_down);
@ -760,7 +760,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
grpc_exec_ctx_invalidate_now(exec_ctx); grpc_exec_ctx_invalidate_now(exec_ctx);
} }
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " "PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d "
"kicked_without_poller: %d", "kicked_without_poller: %d",
@ -805,7 +805,7 @@ static bool check_neighborhood_for_available_poller(
case UNKICKED: case UNKICKED:
if (gpr_atm_no_barrier_cas(&g_active_poller, 0, if (gpr_atm_no_barrier_cas(&g_active_poller, 0,
(gpr_atm)inspect_worker)) { (gpr_atm)inspect_worker)) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. choose next poller to be %p", gpr_log(GPR_DEBUG, " .. choose next poller to be %p",
inspect_worker); inspect_worker);
} }
@ -816,7 +816,7 @@ static bool check_neighborhood_for_available_poller(
gpr_cv_signal(&inspect_worker->cv); gpr_cv_signal(&inspect_worker->cv);
} }
} else { } else {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. beaten to choose next poller"); gpr_log(GPR_DEBUG, " .. beaten to choose next poller");
} }
} }
@ -834,7 +834,7 @@ static bool check_neighborhood_for_available_poller(
} while (!found_worker && inspect_worker != inspect->root_worker); } while (!found_worker && inspect_worker != inspect->root_worker);
} }
if (!found_worker) { if (!found_worker) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. mark pollset %p inactive", inspect); gpr_log(GPR_DEBUG, " .. mark pollset %p inactive", inspect);
} }
inspect->seen_inactive = true; inspect->seen_inactive = true;
@ -856,7 +856,7 @@ static void end_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
grpc_pollset_worker *worker, grpc_pollset_worker *worker,
grpc_pollset_worker **worker_hdl) { grpc_pollset_worker **worker_hdl) {
GPR_TIMER_BEGIN("end_worker", 0); GPR_TIMER_BEGIN("end_worker", 0);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p END_WORKER:%p", pollset, worker); gpr_log(GPR_DEBUG, "PS:%p END_WORKER:%p", pollset, worker);
} }
if (worker_hdl != NULL) *worker_hdl = NULL; if (worker_hdl != NULL) *worker_hdl = NULL;
@ -866,7 +866,7 @@ static void end_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
&exec_ctx->closure_list); &exec_ctx->closure_list);
if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) {
if (worker->next != worker && worker->next->state == UNKICKED) { if (worker->next != worker && worker->next->state == UNKICKED) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. choose next poller to be peer %p", worker); gpr_log(GPR_DEBUG, " .. choose next poller to be peer %p", worker);
} }
GPR_ASSERT(worker->next->initialized_cv); GPR_ASSERT(worker->next->initialized_cv);
@ -920,7 +920,7 @@ static void end_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
if (worker->initialized_cv) { if (worker->initialized_cv) {
gpr_cv_destroy(&worker->cv); gpr_cv_destroy(&worker->cv);
} }
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. remove worker"); gpr_log(GPR_DEBUG, " .. remove worker");
} }
if (EMPTIED == worker_remove(pollset, worker)) { if (EMPTIED == worker_remove(pollset, worker)) {
@ -992,7 +992,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
GPR_TIMER_BEGIN("pollset_kick", 0); GPR_TIMER_BEGIN("pollset_kick", 0);
GRPC_STATS_INC_POLLSET_KICK(exec_ctx); GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
grpc_error *ret_err = GRPC_ERROR_NONE; grpc_error *ret_err = GRPC_ERROR_NONE;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_strvec log; gpr_strvec log;
gpr_strvec_init(&log); gpr_strvec_init(&log);
char *tmp; char *tmp;
@ -1025,7 +1025,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
if (root_worker == NULL) { if (root_worker == NULL) {
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx);
pollset->kicked_without_poller = true; pollset->kicked_without_poller = true;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kicked_without_poller"); gpr_log(GPR_ERROR, " .. kicked_without_poller");
} }
goto done; goto done;
@ -1033,14 +1033,14 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
grpc_pollset_worker *next_worker = root_worker->next; grpc_pollset_worker *next_worker = root_worker->next;
if (root_worker->state == KICKED) { if (root_worker->state == KICKED) {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. already kicked %p", root_worker); gpr_log(GPR_ERROR, " .. already kicked %p", root_worker);
} }
SET_KICK_STATE(root_worker, KICKED); SET_KICK_STATE(root_worker, KICKED);
goto done; goto done;
} else if (next_worker->state == KICKED) { } else if (next_worker->state == KICKED) {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. already kicked %p", next_worker); gpr_log(GPR_ERROR, " .. already kicked %p", next_worker);
} }
SET_KICK_STATE(next_worker, KICKED); SET_KICK_STATE(next_worker, KICKED);
@ -1051,7 +1051,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
root_worker == (grpc_pollset_worker *)gpr_atm_no_barrier_load( root_worker == (grpc_pollset_worker *)gpr_atm_no_barrier_load(
&g_active_poller)) { &g_active_poller)) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kicked %p", root_worker); gpr_log(GPR_ERROR, " .. kicked %p", root_worker);
} }
SET_KICK_STATE(root_worker, KICKED); SET_KICK_STATE(root_worker, KICKED);
@ -1059,7 +1059,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
goto done; goto done;
} else if (next_worker->state == UNKICKED) { } else if (next_worker->state == UNKICKED) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kicked %p", next_worker); gpr_log(GPR_ERROR, " .. kicked %p", next_worker);
} }
GPR_ASSERT(next_worker->initialized_cv); GPR_ASSERT(next_worker->initialized_cv);
@ -1068,7 +1068,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
goto done; goto done;
} else if (next_worker->state == DESIGNATED_POLLER) { } else if (next_worker->state == DESIGNATED_POLLER) {
if (root_worker->state != DESIGNATED_POLLER) { if (root_worker->state != DESIGNATED_POLLER) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log( gpr_log(
GPR_ERROR, GPR_ERROR,
" .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)", " .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)",
@ -1082,7 +1082,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
goto done; goto done;
} else { } else {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker, gpr_log(GPR_ERROR, " .. non-root poller %p (root=%p)", next_worker,
root_worker); root_worker);
} }
@ -1098,7 +1098,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
} }
} else { } else {
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kicked while waking up"); gpr_log(GPR_ERROR, " .. kicked while waking up");
} }
goto done; goto done;
@ -1108,14 +1108,14 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
} }
if (specific_worker->state == KICKED) { if (specific_worker->state == KICKED) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. specific worker already kicked"); gpr_log(GPR_ERROR, " .. specific worker already kicked");
} }
goto done; goto done;
} else if (gpr_tls_get(&g_current_thread_worker) == } else if (gpr_tls_get(&g_current_thread_worker) ==
(intptr_t)specific_worker) { (intptr_t)specific_worker) {
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker); gpr_log(GPR_ERROR, " .. mark %p kicked", specific_worker);
} }
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
@ -1123,7 +1123,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
} else if (specific_worker == } else if (specific_worker ==
(grpc_pollset_worker *)gpr_atm_no_barrier_load(&g_active_poller)) { (grpc_pollset_worker *)gpr_atm_no_barrier_load(&g_active_poller)) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kick active poller"); gpr_log(GPR_ERROR, " .. kick active poller");
} }
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
@ -1131,7 +1131,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
goto done; goto done;
} else if (specific_worker->initialized_cv) { } else if (specific_worker->initialized_cv) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kick waiting worker"); gpr_log(GPR_ERROR, " .. kick waiting worker");
} }
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);
@ -1139,7 +1139,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
goto done; goto done;
} else { } else {
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, " .. kick non-waiting worker"); gpr_log(GPR_ERROR, " .. kick non-waiting worker");
} }
SET_KICK_STATE(specific_worker, KICKED); SET_KICK_STATE(specific_worker, KICKED);

@ -57,10 +57,8 @@
#define MAX_EPOLL_EVENTS 100 #define MAX_EPOLL_EVENTS 100
#define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5 #define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false,
grpc_tracer_flag grpc_trace_pollable_refcount = "pollable_refcount");
GRPC_TRACER_INITIALIZER(false, "pollable_refcount");
#endif
/******************************************************************************* /*******************************************************************************
* pollable Declarations * pollable Declarations
@ -261,7 +259,7 @@ static gpr_mu fd_freelist_mu;
unref_by(ec, fd, n, reason, __FILE__, __LINE__) unref_by(ec, fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
@ -295,7 +293,7 @@ static void fd_destroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
#ifndef NDEBUG #ifndef NDEBUG
static void unref_by(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int n, static void unref_by(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int n,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
@ -357,7 +355,7 @@ static grpc_fd *fd_create(int fd, const char *name) {
gpr_asprintf(&fd_name, "%s fd=%d", name, fd); gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name); gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, new_fd, fd_name);
} }
#endif #endif
@ -481,7 +479,7 @@ static grpc_error *pollable_create(pollable_type type, pollable **p) {
static pollable *pollable_ref(pollable *p) { static pollable *pollable_ref(pollable *p) {
#else #else
static pollable *pollable_ref(pollable *p, int line, const char *reason) { static pollable *pollable_ref(pollable *p, int line, const char *reason) {
if (GRPC_TRACER_ON(grpc_trace_pollable_refcount)) { if (grpc_trace_pollable_refcount.enabled()) {
int r = (int)gpr_atm_no_barrier_load(&p->refs.count); int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
"POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason); "POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason);
@ -496,7 +494,7 @@ static void pollable_unref(pollable *p) {
#else #else
static void pollable_unref(pollable *p, int line, const char *reason) { static void pollable_unref(pollable *p, int line, const char *reason) {
if (p == NULL) return; if (p == NULL) return;
if (GRPC_TRACER_ON(grpc_trace_pollable_refcount)) { if (grpc_trace_pollable_refcount.enabled()) {
int r = (int)gpr_atm_no_barrier_load(&p->refs.count); int r = (int)gpr_atm_no_barrier_load(&p->refs.count);
gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG,
"POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason);
@ -514,7 +512,7 @@ static grpc_error *pollable_add_fd(pollable *p, grpc_fd *fd) {
static const char *err_desc = "pollable_add_fd"; static const char *err_desc = "pollable_add_fd";
const int epfd = p->epfd; const int epfd = p->epfd;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "add fd %p (%d) to pollable %p", fd, fd->fd, p); gpr_log(GPR_DEBUG, "add fd %p (%d) to pollable %p", fd, fd->fd, p);
} }
@ -556,7 +554,7 @@ static void pollset_global_shutdown(void) {
/* pollset->mu must be held while calling this function */ /* pollset->mu must be held while calling this function */
static void pollset_maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, static void pollset_maybe_finish_shutdown(grpc_exec_ctx *exec_ctx,
grpc_pollset *pollset) { grpc_pollset *pollset) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) " "PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) "
"rw=%p (target:NULL) cpsc=%d (target:0)", "rw=%p (target:NULL) cpsc=%d (target:0)",
@ -580,14 +578,14 @@ static grpc_error *kick_one_worker(grpc_exec_ctx *exec_ctx,
GRPC_STATS_INC_POLLSET_KICK(exec_ctx); GRPC_STATS_INC_POLLSET_KICK(exec_ctx);
GPR_ASSERT(specific_worker != NULL); GPR_ASSERT(specific_worker != NULL);
if (specific_worker->kicked) { if (specific_worker->kicked) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p); gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p);
} }
GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx);
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p); gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_awake", p);
} }
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
@ -596,7 +594,7 @@ static grpc_error *kick_one_worker(grpc_exec_ctx *exec_ctx,
} }
if (specific_worker == p->root_worker) { if (specific_worker == p->root_worker) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_FD(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p); gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p);
} }
specific_worker->kicked = true; specific_worker->kicked = true;
@ -605,7 +603,7 @@ static grpc_error *kick_one_worker(grpc_exec_ctx *exec_ctx,
} }
if (specific_worker->initialized_cv) { if (specific_worker->initialized_cv) {
GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_WAKEUP_CV(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p); gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p);
} }
specific_worker->kicked = true; specific_worker->kicked = true;
@ -619,7 +617,7 @@ static grpc_error *kick_one_worker(grpc_exec_ctx *exec_ctx,
static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
grpc_pollset_worker *specific_worker) { grpc_pollset_worker *specific_worker) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p",
pollset, specific_worker, pollset, specific_worker,
@ -630,7 +628,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
if (specific_worker == NULL) { if (specific_worker == NULL) {
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) {
if (pollset->root_worker == NULL) { if (pollset->root_worker == NULL) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset); gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset);
} }
GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx);
@ -656,7 +654,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next); exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next);
} }
} else { } else {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset); gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset);
} }
GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx);
@ -763,7 +761,7 @@ static grpc_error *pollable_process_events(grpc_exec_ctx *exec_ctx,
struct epoll_event *ev = &pollable_obj->events[n]; struct epoll_event *ev = &pollable_obj->events[n];
void *data_ptr = ev->data.ptr; void *data_ptr = ev->data.ptr;
if (1 & (intptr_t)data_ptr) { if (1 & (intptr_t)data_ptr) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p got pollset_wakeup %p", pollset, data_ptr); gpr_log(GPR_DEBUG, "PS:%p got pollset_wakeup %p", pollset, data_ptr);
} }
append_error(&error, append_error(&error,
@ -775,7 +773,7 @@ static grpc_error *pollable_process_events(grpc_exec_ctx *exec_ctx,
bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0; bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0;
bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0;
bool write_ev = (ev->events & EPOLLOUT) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"PS:%p got fd %p: cancel=%d read=%d " "PS:%p got fd %p: cancel=%d read=%d "
"write=%d", "write=%d",
@ -803,7 +801,7 @@ static grpc_error *pollable_epoll(grpc_exec_ctx *exec_ctx, pollable *p,
grpc_millis deadline) { grpc_millis deadline) {
int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline); int timeout = poll_deadline_to_millis_timeout(exec_ctx, deadline);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
char *desc = pollable_desc(p); char *desc = pollable_desc(p);
gpr_log(GPR_DEBUG, "POLLABLE:%p[%s] poll for %dms", p, desc, timeout); gpr_log(GPR_DEBUG, "POLLABLE:%p[%s] poll for %dms", p, desc, timeout);
gpr_free(desc); gpr_free(desc);
@ -823,7 +821,7 @@ static grpc_error *pollable_epoll(grpc_exec_ctx *exec_ctx, pollable *p,
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait"); if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "POLLABLE:%p got %d events", p, r); gpr_log(GPR_DEBUG, "POLLABLE:%p got %d events", p, r);
} }
@ -891,7 +889,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
worker->initialized_cv = true; worker->initialized_cv = true;
gpr_cv_init(&worker->cv); gpr_cv_init(&worker->cv);
gpr_mu_unlock(&pollset->mu); gpr_mu_unlock(&pollset->mu);
if (GRPC_TRACER_ON(grpc_polling_trace) && if (grpc_polling_trace.enabled() &&
worker->pollable_obj->root_worker != worker) { worker->pollable_obj->root_worker != worker) {
gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset, gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset,
worker->pollable_obj, worker, worker->pollable_obj, worker,
@ -900,18 +898,18 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
while (do_poll && worker->pollable_obj->root_worker != worker) { while (do_poll && worker->pollable_obj->root_worker != worker) {
if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu, if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu,
grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) { grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME))) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p timeout_wait %p w=%p", pollset, gpr_log(GPR_DEBUG, "PS:%p timeout_wait %p w=%p", pollset,
worker->pollable_obj, worker); worker->pollable_obj, worker);
} }
do_poll = false; do_poll = false;
} else if (worker->kicked) { } else if (worker->kicked) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p wakeup %p w=%p", pollset, gpr_log(GPR_DEBUG, "PS:%p wakeup %p w=%p", pollset,
worker->pollable_obj, worker); worker->pollable_obj, worker);
} }
do_poll = false; do_poll = false;
} else if (GRPC_TRACER_ON(grpc_polling_trace) && } else if (grpc_polling_trace.enabled() &&
worker->pollable_obj->root_worker != worker) { worker->pollable_obj->root_worker != worker) {
gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset, gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset,
worker->pollable_obj, worker); worker->pollable_obj, worker);
@ -982,7 +980,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
#ifndef NDEBUG #ifndef NDEBUG
WORKER_PTR->originator = gettid(); WORKER_PTR->originator = gettid();
#endif #endif
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR
" deadline=%" PRIdPTR " kwp=%d pollable=%p", " deadline=%" PRIdPTR " kwp=%d pollable=%p",
pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(exec_ctx), pollset, worker_hdl, WORKER_PTR, grpc_exec_ctx_now(exec_ctx),
@ -1023,7 +1021,7 @@ static grpc_error *pollset_transition_pollable_from_empty_to_fd_locked(
grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_fd *fd) { grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_fd *fd) {
static const char *err_desc = "pollset_transition_pollable_from_empty_to_fd"; static const char *err_desc = "pollset_transition_pollable_from_empty_to_fd";
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"PS:%p add fd %p (%d); transition pollable from empty to fd", "PS:%p add fd %p (%d); transition pollable from empty to fd",
pollset, fd, fd->fd); pollset, fd, fd->fd);
@ -1039,7 +1037,7 @@ static grpc_error *pollset_transition_pollable_from_fd_to_multi_locked(
grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_fd *and_add_fd) { grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_fd *and_add_fd) {
static const char *err_desc = "pollset_transition_pollable_from_fd_to_multi"; static const char *err_desc = "pollset_transition_pollable_from_fd_to_multi";
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,
"PS:%p add fd %p (%d); transition pollable from fd %p to multipoller", "PS:%p add fd %p (%d); transition pollable from fd %p to multipoller",
@ -1189,7 +1187,7 @@ static void pollset_set_unref(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss) {
static void pollset_set_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss, static void pollset_set_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
grpc_fd *fd) { grpc_fd *fd) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd); gpr_log(GPR_DEBUG, "PSS:%p: add fd %p (%d)", pss, fd, fd->fd);
} }
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
@ -1213,7 +1211,7 @@ static void pollset_set_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
static void pollset_set_del_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss, static void pollset_set_del_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
grpc_fd *fd) { grpc_fd *fd) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS:%p: del fd %p", pss, fd); gpr_log(GPR_DEBUG, "PSS:%p: del fd %p", pss, fd);
} }
pss = pss_lock_adam(pss); pss = pss_lock_adam(pss);
@ -1234,7 +1232,7 @@ static void pollset_set_del_fd(grpc_exec_ctx *exec_ctx, grpc_pollset_set *pss,
static void pollset_set_del_pollset(grpc_exec_ctx *exec_ctx, static void pollset_set_del_pollset(grpc_exec_ctx *exec_ctx,
grpc_pollset_set *pss, grpc_pollset *ps) { grpc_pollset_set *pss, grpc_pollset *ps) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS:%p: del pollset %p", pss, ps); gpr_log(GPR_DEBUG, "PSS:%p: del pollset %p", pss, ps);
} }
pss = pss_lock_adam(pss); pss = pss_lock_adam(pss);
@ -1285,7 +1283,7 @@ static grpc_error *add_fds_to_pollsets(grpc_exec_ctx *exec_ctx, grpc_fd **fds,
static void pollset_set_add_pollset(grpc_exec_ctx *exec_ctx, static void pollset_set_add_pollset(grpc_exec_ctx *exec_ctx,
grpc_pollset_set *pss, grpc_pollset *ps) { grpc_pollset_set *pss, grpc_pollset *ps) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS:%p: add pollset %p", pss, ps); gpr_log(GPR_DEBUG, "PSS:%p: add pollset %p", pss, ps);
} }
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
@ -1322,7 +1320,7 @@ static void pollset_set_add_pollset(grpc_exec_ctx *exec_ctx,
static void pollset_set_add_pollset_set(grpc_exec_ctx *exec_ctx, static void pollset_set_add_pollset_set(grpc_exec_ctx *exec_ctx,
grpc_pollset_set *a, grpc_pollset_set *a,
grpc_pollset_set *b) { grpc_pollset_set *b) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS: merge (%p, %p)", a, b); gpr_log(GPR_DEBUG, "PSS: merge (%p, %p)", a, b);
} }
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
@ -1356,7 +1354,7 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx *exec_ctx,
if (b_size > a_size) { if (b_size > a_size) {
GPR_SWAP(grpc_pollset_set *, a, b); GPR_SWAP(grpc_pollset_set *, a, b);
} }
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "PSS: parent %p to %p", b, a); gpr_log(GPR_DEBUG, "PSS: parent %p to %p", b, a);
} }
gpr_ref(&a->refs); gpr_ref(&a->refs);
@ -1453,10 +1451,6 @@ const grpc_event_engine_vtable *grpc_init_epollex_linux(
return NULL; return NULL;
} }
#ifndef NDEBUG
grpc_register_tracer(&grpc_trace_pollable_refcount);
#endif
fd_global_init(); fd_global_init();
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {

@ -54,7 +54,7 @@
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
#define GRPC_POLLING_TRACE(...) \ #define GRPC_POLLING_TRACE(...) \
if (GRPC_TRACER_ON(grpc_polling_trace)) { \ if (grpc_polling_trace.enabled()) { \
gpr_log(GPR_INFO, __VA_ARGS__); \ gpr_log(GPR_INFO, __VA_ARGS__); \
} }
@ -288,7 +288,7 @@ static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi);
#ifndef NDEBUG #ifndef NDEBUG
static void pi_add_ref_dbg(polling_island *pi, const char *reason, static void pi_add_ref_dbg(polling_island *pi, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count); gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count);
gpr_log(GPR_DEBUG, "Add ref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR gpr_log(GPR_DEBUG, "Add ref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR
" (%s) - (%s, %d)", " (%s) - (%s, %d)",
@ -299,7 +299,7 @@ static void pi_add_ref_dbg(polling_island *pi, const char *reason,
static void pi_unref_dbg(grpc_exec_ctx *exec_ctx, polling_island *pi, static void pi_unref_dbg(grpc_exec_ctx *exec_ctx, polling_island *pi,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count); gpr_atm old_cnt = gpr_atm_acq_load(&pi->ref_count);
gpr_log(GPR_DEBUG, "Unref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR gpr_log(GPR_DEBUG, "Unref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR
" (%s) - (%s, %d)", " (%s) - (%s, %d)",
@ -730,7 +730,7 @@ static gpr_mu fd_freelist_mu;
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
@ -747,7 +747,7 @@ static void ref_by(grpc_fd *fd, int n) {
#ifndef NDEBUG #ifndef NDEBUG
static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),

@ -288,7 +288,7 @@ cv_fd_table g_cvfds;
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
@ -305,7 +305,7 @@ static void ref_by(grpc_fd *fd, int n) {
#ifndef NDEBUG #ifndef NDEBUG
static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { if (grpc_trace_fd_refcount.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]",
fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst),
@ -992,7 +992,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
r = grpc_poll_function(pfds, pfd_count, timeout); r = grpc_poll_function(pfds, pfd_count, timeout);
GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx); GRPC_SCHEDULING_END_BLOCKING_REGION_WITH_EXEC_CTX(exec_ctx);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r);
} }
@ -1016,7 +1016,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
} }
} else { } else {
if (pfds[0].revents & POLLIN_CHECK) { if (pfds[0].revents & POLLIN_CHECK) {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "%p: got_wakeup", pollset); gpr_log(GPR_DEBUG, "%p: got_wakeup", pollset);
} }
work_combine_error( work_combine_error(
@ -1026,7 +1026,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
if (watchers[i].fd == NULL) { if (watchers[i].fd == NULL) {
fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL);
} else { } else {
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset,
pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0,
(pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents);

@ -36,12 +36,11 @@
#include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/iomgr/ev_poll_posix.h"
#include "src/core/lib/support/env.h" #include "src/core/lib/support/env.h"
grpc_tracer_flag grpc_polling_trace = grpc_core::TraceFlag grpc_polling_trace(false,
GRPC_TRACER_INITIALIZER(false, "polling"); /* Disabled by default */ "polling"); /* Disabled by default */
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_fd_refcount = grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount");
GRPC_TRACER_INITIALIZER(false, "fd_refcount");
#endif #endif
/** Default poll() function - a pointer so that it can be overridden by some /** Default poll() function - a pointer so that it can be overridden by some
@ -153,8 +152,6 @@ const grpc_event_engine_vtable *grpc_get_event_engine_test_only() {
const char *grpc_get_poll_strategy_name() { return g_poll_strategy_name; } const char *grpc_get_poll_strategy_name() { return g_poll_strategy_name; }
void grpc_event_engine_init(void) { void grpc_event_engine_init(void) {
grpc_register_tracer(&grpc_polling_trace);
char *s = gpr_getenv("GRPC_POLL_STRATEGY"); char *s = gpr_getenv("GRPC_POLL_STRATEGY");
if (s == NULL) { if (s == NULL) {
s = gpr_strdup("all"); s = gpr_strdup("all");

@ -31,7 +31,7 @@
extern "C" { extern "C" {
#endif #endif
extern grpc_tracer_flag grpc_polling_trace; /* Disabled by default */ extern grpc_core::TraceFlag grpc_polling_trace; /* Disabled by default */
typedef struct grpc_fd grpc_fd; typedef struct grpc_fd grpc_fd;

@ -22,7 +22,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
grpc_tracer_flag grpc_polling_trace = grpc_core::TraceFlag grpc_polling_trace(false,
GRPC_TRACER_INITIALIZER(false, "polling"); /* Disabled by default */ "polling"); /* Disabled by default */
#endif // GRPC_WINSOCK_SOCKET #endif // GRPC_WINSOCK_SOCKET

@ -60,7 +60,7 @@ static void exec_ctx_run(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
grpc_error *error) { grpc_error *error) {
#ifndef NDEBUG #ifndef NDEBUG
closure->scheduled = false; closure->scheduled = false;
if (GRPC_TRACER_ON(grpc_trace_closure)) { if (grpc_trace_closure.enabled()) {
gpr_log(GPR_DEBUG, "running closure %p: created [%s:%d]: %s [%s:%d]", gpr_log(GPR_DEBUG, "running closure %p: created [%s:%d]: %s [%s:%d]",
closure, closure->file_created, closure->line_created, closure, closure->file_created, closure->line_created,
closure->run ? "run" : "scheduled", closure->file_initiated, closure->run ? "run" : "scheduled", closure->file_initiated,
@ -69,7 +69,7 @@ static void exec_ctx_run(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
#endif #endif
closure->cb(exec_ctx, closure->cb_arg, error); closure->cb(exec_ctx, closure->cb_arg, error);
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_closure)) { if (grpc_trace_closure.enabled()) {
gpr_log(GPR_DEBUG, "closure %p finished", closure); gpr_log(GPR_DEBUG, "closure %p finished", closure);
} }
#endif #endif

@ -51,8 +51,7 @@ static gpr_spinlock g_adding_thread_lock = GPR_SPINLOCK_STATIC_INITIALIZER;
GPR_TLS_DECL(g_this_thread_state); GPR_TLS_DECL(g_this_thread_state);
static grpc_tracer_flag executor_trace = static grpc_core::TraceFlag executor_trace(false, "executor");
GRPC_TRACER_INITIALIZER(false, "executor");
static void executor_thread(void *arg); static void executor_thread(void *arg);
@ -63,7 +62,7 @@ static size_t run_closures(grpc_exec_ctx *exec_ctx, grpc_closure_list list) {
while (c != NULL) { while (c != NULL) {
grpc_closure *next = c->next_data.next; grpc_closure *next = c->next_data.next;
grpc_error *error = c->error_data.error; grpc_error *error = c->error_data.error;
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
#ifndef NDEBUG #ifndef NDEBUG
gpr_log(GPR_DEBUG, "EXECUTOR: run %p [created by %s:%d]", c, gpr_log(GPR_DEBUG, "EXECUTOR: run %p [created by %s:%d]", c,
c->file_created, c->line_created); c->file_created, c->line_created);
@ -134,7 +133,6 @@ void grpc_executor_set_threading(grpc_exec_ctx *exec_ctx, bool threading) {
} }
void grpc_executor_init(grpc_exec_ctx *exec_ctx) { void grpc_executor_init(grpc_exec_ctx *exec_ctx) {
grpc_register_tracer(&executor_trace);
gpr_atm_no_barrier_store(&g_cur_threads, 0); gpr_atm_no_barrier_store(&g_cur_threads, 0);
grpc_executor_set_threading(exec_ctx, true); grpc_executor_set_threading(exec_ctx, true);
} }
@ -152,7 +150,7 @@ static void executor_thread(void *arg) {
size_t subtract_depth = 0; size_t subtract_depth = 0;
for (;;) { for (;;) {
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")", gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")",
(int)(ts - g_thread_state), subtract_depth); (int)(ts - g_thread_state), subtract_depth);
} }
@ -163,7 +161,7 @@ static void executor_thread(void *arg) {
gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME));
} }
if (ts->shutdown) { if (ts->shutdown) {
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown", gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown",
(int)(ts - g_thread_state)); (int)(ts - g_thread_state));
} }
@ -174,7 +172,7 @@ static void executor_thread(void *arg) {
grpc_closure_list exec = ts->elems; grpc_closure_list exec = ts->elems;
ts->elems = GRPC_CLOSURE_LIST_INIT; ts->elems = GRPC_CLOSURE_LIST_INIT;
gpr_mu_unlock(&ts->mu); gpr_mu_unlock(&ts->mu);
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state)); gpr_log(GPR_DEBUG, "EXECUTOR[%d]: execute", (int)(ts - g_thread_state));
} }
@ -196,7 +194,7 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
retry_push = false; retry_push = false;
size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads); size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads);
if (cur_thread_count == 0) { if (cur_thread_count == 0) {
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
#ifndef NDEBUG #ifndef NDEBUG
gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p (created %s:%d) inline", gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p (created %s:%d) inline",
closure, closure->file_created, closure->line_created); closure, closure->file_created, closure->line_created);
@ -217,7 +215,7 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
bool try_new_thread; bool try_new_thread;
for (;;) { for (;;) {
if (GRPC_TRACER_ON(executor_trace)) { if (executor_trace.enabled()) {
#ifndef NDEBUG #ifndef NDEBUG
gpr_log( gpr_log(
GPR_DEBUG, GPR_DEBUG,

@ -28,7 +28,6 @@
void grpc_iomgr_platform_init(void) { void grpc_iomgr_platform_init(void) {
grpc_wakeup_fd_global_init(); grpc_wakeup_fd_global_init();
grpc_event_engine_init(); grpc_event_engine_init();
grpc_register_tracer(&grpc_tcp_trace);
} }
void grpc_iomgr_platform_flush(void) {} void grpc_iomgr_platform_flush(void) {}

@ -31,7 +31,7 @@ gpr_thd_id g_init_thread;
void grpc_iomgr_platform_init(void) { void grpc_iomgr_platform_init(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_pollset_global_init(); grpc_pollset_global_init();
grpc_register_tracer(&grpc_tcp_trace);
grpc_executor_set_threading(&exec_ctx, false); grpc_executor_set_threading(&exec_ctx, false);
g_init_thread = gpr_thd_currentid(); g_init_thread = gpr_thd_currentid();
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);

@ -22,7 +22,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
extern grpc_tracer_flag grpc_polling_trace; extern grpc_core::TraceFlag grpc_polling_trace;
/* 'state' holds the to call when the fd is readable or writable respectively. /* 'state' holds the to call when the fd is readable or writable respectively.
It can contain one of the following values: It can contain one of the following values:
@ -82,7 +82,7 @@ void grpc_lfev_notify_on(grpc_exec_ctx *exec_ctx, gpr_atm *state,
grpc_closure *closure, const char *variable) { grpc_closure *closure, const char *variable) {
while (true) { while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state); gpr_atm curr = gpr_atm_no_barrier_load(state);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "lfev_notify_on[%s]: %p curr=%p closure=%p", variable, gpr_log(GPR_ERROR, "lfev_notify_on[%s]: %p curr=%p closure=%p", variable,
state, (void *)curr, closure); state, (void *)curr, closure);
} }
@ -148,7 +148,7 @@ bool grpc_lfev_set_shutdown(grpc_exec_ctx *exec_ctx, gpr_atm *state,
while (true) { while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state); gpr_atm curr = gpr_atm_no_barrier_load(state);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "lfev_set_shutdown: %p curr=%p err=%s", state, gpr_log(GPR_ERROR, "lfev_set_shutdown: %p curr=%p err=%s", state,
(void *)curr, grpc_error_string(shutdown_err)); (void *)curr, grpc_error_string(shutdown_err));
} }
@ -198,7 +198,7 @@ void grpc_lfev_set_ready(grpc_exec_ctx *exec_ctx, gpr_atm *state,
while (true) { while (true) {
gpr_atm curr = gpr_atm_no_barrier_load(state); gpr_atm curr = gpr_atm_no_barrier_load(state);
if (GRPC_TRACER_ON(grpc_polling_trace)) { if (grpc_polling_trace.enabled()) {
gpr_log(GPR_ERROR, "lfev_set_ready[%s]: %p curr=%p", variable, state, gpr_log(GPR_ERROR, "lfev_set_ready[%s]: %p curr=%p", variable, state,
(void *)curr); (void *)curr);
} }

@ -30,7 +30,7 @@ extern "C" {
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_fd_refcount; extern grpc_core::TraceFlag grpc_trace_fd_refcount;
#endif #endif
/* A grpc_pollset is a set of file descriptors that a higher level item is /* A grpc_pollset is a set of file descriptors that a higher level item is

@ -34,10 +34,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount");
grpc_tracer_flag grpc_trace_fd_refcount =
GRPC_TRACER_INITIALIZER(false, "fd_refcount");
#endif
struct grpc_pollset { struct grpc_pollset {
uv_timer_t timer; uv_timer_t timer;

@ -30,10 +30,7 @@
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
#ifndef NDEBUG grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount");
grpc_tracer_flag grpc_trace_fd_refcount =
GRPC_TRACER_INITIALIZER(false, "fd_refcount");
#endif
gpr_mu grpc_polling_mu; gpr_mu grpc_polling_mu;
static grpc_pollset_worker *g_active_poller; static grpc_pollset_worker *g_active_poller;

@ -31,8 +31,7 @@
#include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/combiner.h"
grpc_tracer_flag grpc_resource_quota_trace = grpc_core::TraceFlag grpc_resource_quota_trace(false, "resource_quota");
GRPC_TRACER_INITIALIZER(false, "resource_quota");
#define MEMORY_USAGE_ESTIMATION_MAX 65536 #define MEMORY_USAGE_ESTIMATION_MAX 65536
@ -294,7 +293,7 @@ static bool rq_alloc(grpc_exec_ctx *exec_ctx,
while ((resource_user = rulist_pop_head(resource_quota, while ((resource_user = rulist_pop_head(resource_quota,
GRPC_RULIST_AWAITING_ALLOCATION))) { GRPC_RULIST_AWAITING_ALLOCATION))) {
gpr_mu_lock(&resource_user->mu); gpr_mu_lock(&resource_user->mu);
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ: check allocation for user %p shutdown=%" PRIdPTR gpr_log(GPR_DEBUG, "RQ: check allocation for user %p shutdown=%" PRIdPTR
" free_pool=%" PRId64, " free_pool=%" PRId64,
resource_user, gpr_atm_no_barrier_load(&resource_user->shutdown), resource_user, gpr_atm_no_barrier_load(&resource_user->shutdown),
@ -319,13 +318,13 @@ static bool rq_alloc(grpc_exec_ctx *exec_ctx,
resource_user->free_pool = 0; resource_user->free_pool = 0;
resource_quota->free_pool -= amt; resource_quota->free_pool -= amt;
rq_update_estimate(resource_quota); rq_update_estimate(resource_quota);
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: grant alloc %" PRId64 gpr_log(GPR_DEBUG, "RQ %s %s: grant alloc %" PRId64
" bytes; rq_free_pool -> %" PRId64, " bytes; rq_free_pool -> %" PRId64,
resource_quota->name, resource_user->name, amt, resource_quota->name, resource_user->name, amt,
resource_quota->free_pool); resource_quota->free_pool);
} }
} else if (GRPC_TRACER_ON(grpc_resource_quota_trace) && } else if (grpc_resource_quota_trace.enabled() &&
resource_user->free_pool >= 0) { resource_user->free_pool >= 0) {
gpr_log(GPR_DEBUG, "RQ %s %s: discard already satisfied alloc request", gpr_log(GPR_DEBUG, "RQ %s %s: discard already satisfied alloc request",
resource_quota->name, resource_user->name); resource_quota->name, resource_user->name);
@ -356,7 +355,7 @@ static bool rq_reclaim_from_per_user_free_pool(
resource_user->free_pool = 0; resource_user->free_pool = 0;
resource_quota->free_pool += amt; resource_quota->free_pool += amt;
rq_update_estimate(resource_quota); rq_update_estimate(resource_quota);
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: reclaim_from_per_user_free_pool %" PRId64 gpr_log(GPR_DEBUG, "RQ %s %s: reclaim_from_per_user_free_pool %" PRId64
" bytes; rq_free_pool -> %" PRId64, " bytes; rq_free_pool -> %" PRId64,
resource_quota->name, resource_user->name, amt, resource_quota->name, resource_user->name, amt,
@ -379,7 +378,7 @@ static bool rq_reclaim(grpc_exec_ctx *exec_ctx,
: GRPC_RULIST_RECLAIMER_BENIGN; : GRPC_RULIST_RECLAIMER_BENIGN;
grpc_resource_user *resource_user = rulist_pop_head(resource_quota, list); grpc_resource_user *resource_user = rulist_pop_head(resource_quota, list);
if (resource_user == NULL) return false; if (resource_user == NULL) return false;
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation", gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation",
resource_quota->name, resource_user->name, resource_quota->name, resource_user->name,
destructive ? "destructive" : "benign"); destructive ? "destructive" : "benign");
@ -513,7 +512,7 @@ static void ru_post_destructive_reclaimer(grpc_exec_ctx *exec_ctx, void *ru,
} }
static void ru_shutdown(grpc_exec_ctx *exec_ctx, void *ru, grpc_error *error) { static void ru_shutdown(grpc_exec_ctx *exec_ctx, void *ru, grpc_error *error) {
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RU shutdown %p", ru); gpr_log(GPR_DEBUG, "RU shutdown %p", ru);
} }
grpc_resource_user *resource_user = (grpc_resource_user *)ru; grpc_resource_user *resource_user = (grpc_resource_user *)ru;
@ -811,7 +810,7 @@ void grpc_resource_user_alloc(grpc_exec_ctx *exec_ctx,
ru_ref_by(resource_user, (gpr_atm)size); ru_ref_by(resource_user, (gpr_atm)size);
resource_user->free_pool -= (int64_t)size; resource_user->free_pool -= (int64_t)size;
resource_user->outstanding_allocations += (int64_t)size; resource_user->outstanding_allocations += (int64_t)size;
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64, gpr_log(GPR_DEBUG, "RQ %s %s: alloc %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name, resource_user->name, size, resource_user->resource_quota->name, resource_user->name, size,
resource_user->free_pool); resource_user->free_pool);
@ -836,7 +835,7 @@ void grpc_resource_user_free(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(&resource_user->mu); gpr_mu_lock(&resource_user->mu);
bool was_zero_or_negative = resource_user->free_pool <= 0; bool was_zero_or_negative = resource_user->free_pool <= 0;
resource_user->free_pool += (int64_t)size; resource_user->free_pool += (int64_t)size;
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64, gpr_log(GPR_DEBUG, "RQ %s %s: free %" PRIdPTR "; free_pool -> %" PRId64,
resource_user->resource_quota->name, resource_user->name, size, resource_user->resource_quota->name, resource_user->name, size,
resource_user->free_pool); resource_user->free_pool);
@ -865,7 +864,7 @@ void grpc_resource_user_post_reclaimer(grpc_exec_ctx *exec_ctx,
void grpc_resource_user_finish_reclamation(grpc_exec_ctx *exec_ctx, void grpc_resource_user_finish_reclamation(grpc_exec_ctx *exec_ctx,
grpc_resource_user *resource_user) { grpc_resource_user *resource_user) {
if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { if (grpc_resource_quota_trace.enabled()) {
gpr_log(GPR_DEBUG, "RQ %s %s: reclamation complete", gpr_log(GPR_DEBUG, "RQ %s %s: reclamation complete",
resource_user->resource_quota->name, resource_user->name); resource_user->resource_quota->name, resource_user->name);
} }

@ -65,7 +65,7 @@ extern "C" {
maintain lists of users (which users arrange to leave before they are maintain lists of users (which users arrange to leave before they are
destroyed) */ destroyed) */
extern grpc_tracer_flag grpc_resource_quota_trace; extern grpc_core::TraceFlag grpc_resource_quota_trace;
grpc_resource_quota *grpc_resource_quota_ref_internal( grpc_resource_quota *grpc_resource_quota_ref_internal(
grpc_resource_quota *resource_quota); grpc_resource_quota *resource_quota);

@ -43,7 +43,7 @@
#include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
extern grpc_tracer_flag grpc_tcp_trace; extern grpc_core::TraceFlag grpc_tcp_trace;
typedef struct { typedef struct {
gpr_mu mu; gpr_mu mu;
@ -99,7 +99,7 @@ done:
static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
int done; int done;
async_connect *ac = (async_connect *)acp; async_connect *ac = (async_connect *)acp;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str,
str); str);
@ -137,7 +137,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
GRPC_ERROR_REF(error); GRPC_ERROR_REF(error);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s", gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s",
ac->addr_str, str); ac->addr_str, str);
@ -317,7 +317,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
ac->channel_args = grpc_channel_args_copy(channel_args); ac->channel_args = grpc_channel_args_copy(channel_args);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting fd %p", gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting fd %p",
ac->addr_str, fdobj); ac->addr_str, fdobj);
} }

@ -32,7 +32,7 @@
#include "src/core/lib/iomgr/tcp_uv.h" #include "src/core/lib/iomgr/tcp_uv.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
extern grpc_tracer_flag grpc_tcp_trace; extern grpc_core::TraceFlag grpc_tcp_trace;
typedef struct grpc_uv_tcp_connect { typedef struct grpc_uv_tcp_connect {
uv_connect_t connect_req; uv_connect_t connect_req;
@ -59,7 +59,7 @@ static void uv_tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp,
grpc_error *error) { grpc_error *error) {
int done; int done;
grpc_uv_tcp_connect *connect = (grpc_uv_tcp_connect *)acp; grpc_uv_tcp_connect *connect = (grpc_uv_tcp_connect *)acp;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s",
connect->addr_name, str); connect->addr_name, str);
@ -147,7 +147,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx,
connect->connect_req.data = connect; connect->connect_req.data = connect;
connect->refs = 2; // One for the connect operation, one for the timer. connect->refs = 2; // One for the connect operation, one for the timer.
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting", gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting",
connect->addr_name); connect->addr_name);
} }

@ -61,7 +61,7 @@ typedef GRPC_MSG_IOVLEN_TYPE msg_iovlen_type;
typedef size_t msg_iovlen_type; typedef size_t msg_iovlen_type;
#endif #endif
grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); grpc_core::TraceFlag grpc_tcp_trace(false, "tcp");
typedef struct { typedef struct {
grpc_endpoint base; grpc_endpoint base;
@ -121,7 +121,7 @@ static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx *exec_ctx,
static void done_poller(grpc_exec_ctx *exec_ctx, void *bp, static void done_poller(grpc_exec_ctx *exec_ctx, void *bp,
grpc_error *error_ignored) { grpc_error *error_ignored) {
backup_poller *p = (backup_poller *)bp; backup_poller *p = (backup_poller *)bp;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p);
} }
grpc_pollset_destroy(exec_ctx, BACKUP_POLLER_POLLSET(p)); grpc_pollset_destroy(exec_ctx, BACKUP_POLLER_POLLSET(p));
@ -131,7 +131,7 @@ static void done_poller(grpc_exec_ctx *exec_ctx, void *bp,
static void run_poller(grpc_exec_ctx *exec_ctx, void *bp, static void run_poller(grpc_exec_ctx *exec_ctx, void *bp,
grpc_error *error_ignored) { grpc_error *error_ignored) {
backup_poller *p = (backup_poller *)bp; backup_poller *p = (backup_poller *)bp;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p);
} }
gpr_mu_lock(p->pollset_mu); gpr_mu_lock(p->pollset_mu);
@ -147,18 +147,18 @@ static void run_poller(grpc_exec_ctx *exec_ctx, void *bp,
gpr_atm_full_cas(&g_uncovered_notifications_pending, 1, 0)) { gpr_atm_full_cas(&g_uncovered_notifications_pending, 1, 0)) {
gpr_mu_lock(p->pollset_mu); gpr_mu_lock(p->pollset_mu);
bool cas_ok = gpr_atm_full_cas(&g_backup_poller, (gpr_atm)p, 0); bool cas_ok = gpr_atm_full_cas(&g_backup_poller, (gpr_atm)p, 0);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok);
} }
gpr_mu_unlock(p->pollset_mu); gpr_mu_unlock(p->pollset_mu);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p);
} }
grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p), grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p),
GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p,
grpc_schedule_on_exec_ctx)); grpc_schedule_on_exec_ctx));
} else { } else {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p);
} }
GRPC_CLOSURE_SCHED(exec_ctx, &p->run_poller, GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(exec_ctx, &p->run_poller, GRPC_ERROR_NONE);
@ -169,7 +169,7 @@ static void drop_uncovered(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
backup_poller *p = (backup_poller *)gpr_atm_acq_load(&g_backup_poller); backup_poller *p = (backup_poller *)gpr_atm_acq_load(&g_backup_poller);
gpr_atm old_count = gpr_atm old_count =
gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count, gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count,
(int)old_count - 1); (int)old_count - 1);
} }
@ -180,14 +180,14 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
backup_poller *p; backup_poller *p;
gpr_atm old_count = gpr_atm old_count =
gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count, gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count,
2 + (int)old_count); 2 + (int)old_count);
} }
if (old_count == 0) { if (old_count == 0) {
GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx); GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx);
p = (backup_poller *)gpr_zalloc(sizeof(*p) + grpc_pollset_size()); p = (backup_poller *)gpr_zalloc(sizeof(*p) + grpc_pollset_size());
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p);
} }
grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu);
@ -202,7 +202,7 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
// spin waiting for backup poller // spin waiting for backup poller
} }
} }
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp);
} }
grpc_pollset_add_fd(exec_ctx, BACKUP_POLLER_POLLSET(p), tcp->em_fd); grpc_pollset_add_fd(exec_ctx, BACKUP_POLLER_POLLSET(p), tcp->em_fd);
@ -212,7 +212,7 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
} }
static void notify_on_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void notify_on_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp); gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp);
} }
GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp, GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp,
@ -221,7 +221,7 @@ static void notify_on_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
} }
static void notify_on_write(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void notify_on_write(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp); gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp);
} }
cover_self(exec_ctx, tcp); cover_self(exec_ctx, tcp);
@ -233,7 +233,7 @@ static void notify_on_write(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx *exec_ctx, static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx *exec_ctx,
void *arg, grpc_error *error) { void *arg, grpc_error *error) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error));
} }
drop_uncovered(exec_ctx, (grpc_tcp *)arg); drop_uncovered(exec_ctx, (grpc_tcp *)arg);
@ -310,7 +310,7 @@ static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__)
static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@ -323,7 +323,7 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file, static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@ -354,7 +354,7 @@ static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
grpc_error *error) { grpc_error *error) {
grpc_closure *cb = tcp->read_cb; grpc_closure *cb = tcp->read_cb;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg);
size_t i; size_t i;
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
@ -450,7 +450,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
static void tcp_read_allocation_done(grpc_exec_ctx *exec_ctx, void *tcpp, static void tcp_read_allocation_done(grpc_exec_ctx *exec_ctx, void *tcpp,
grpc_error *error) { grpc_error *error) {
grpc_tcp *tcp = (grpc_tcp *)tcpp; grpc_tcp *tcp = (grpc_tcp *)tcpp;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp,
grpc_error_string(error)); grpc_error_string(error));
} }
@ -469,13 +469,13 @@ static void tcp_continue_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
size_t target_read_size = get_target_read_size(tcp); size_t target_read_size = get_target_read_size(tcp);
if (tcp->incoming_buffer->length < target_read_size && if (tcp->incoming_buffer->length < target_read_size &&
tcp->incoming_buffer->count < MAX_READ_IOVEC) { tcp->incoming_buffer->count < MAX_READ_IOVEC) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp); gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp);
} }
grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator,
target_read_size, 1, tcp->incoming_buffer); target_read_size, 1, tcp->incoming_buffer);
} else { } else {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp); gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp);
} }
tcp_do_read(exec_ctx, tcp); tcp_do_read(exec_ctx, tcp);
@ -486,7 +486,7 @@ static void tcp_handle_read(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
grpc_error *error) { grpc_error *error) {
grpc_tcp *tcp = (grpc_tcp *)arg; grpc_tcp *tcp = (grpc_tcp *)arg;
GPR_ASSERT(!tcp->finished_edge); GPR_ASSERT(!tcp->finished_edge);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error)); gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error));
} }
@ -624,14 +624,14 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
} }
if (!tcp_flush(exec_ctx, tcp, &error)) { if (!tcp_flush(exec_ctx, tcp, &error)) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "write: delayed"); gpr_log(GPR_DEBUG, "write: delayed");
} }
notify_on_write(exec_ctx, tcp); notify_on_write(exec_ctx, tcp);
} else { } else {
cb = tcp->write_cb; cb = tcp->write_cb;
tcp->write_cb = NULL; tcp->write_cb = NULL;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "write: %s", str); gpr_log(GPR_DEBUG, "write: %s", str);
} }
@ -646,7 +646,7 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_tcp *tcp = (grpc_tcp *)ep; grpc_tcp *tcp = (grpc_tcp *)ep;
grpc_error *error = GRPC_ERROR_NONE; grpc_error *error = GRPC_ERROR_NONE;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
size_t i; size_t i;
for (i = 0; i < buf->count; i++) { for (i = 0; i < buf->count; i++) {
@ -677,12 +677,12 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
if (!tcp_flush(exec_ctx, tcp, &error)) { if (!tcp_flush(exec_ctx, tcp, &error)) {
TCP_REF(tcp, "write"); TCP_REF(tcp, "write");
tcp->write_cb = cb; tcp->write_cb = cb;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "write: delayed"); gpr_log(GPR_DEBUG, "write: delayed");
} }
notify_on_write(exec_ctx, tcp); notify_on_write(exec_ctx, tcp);
} else { } else {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "write: %s", str); gpr_log(GPR_DEBUG, "write: %s", str);
} }

@ -37,7 +37,7 @@
extern "C" { extern "C" {
#endif #endif
extern grpc_tracer_flag grpc_tcp_trace; extern grpc_core::TraceFlag grpc_tcp_trace;
/* Create a tcp endpoint given a file desciptor and a read slice size. /* Create a tcp endpoint given a file desciptor and a read slice size.
Takes ownership of fd. */ Takes ownership of fd. */

@ -242,7 +242,7 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *err) {
addr_str = grpc_sockaddr_to_uri(&addr); addr_str = grpc_sockaddr_to_uri(&addr);
gpr_asprintf(&name, "tcp-server-connection:%s", addr_str); gpr_asprintf(&name, "tcp-server-connection:%s", addr_str);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "SERVER_CONNECT: incoming connection: %s", addr_str); gpr_log(GPR_DEBUG, "SERVER_CONNECT: incoming connection: %s", addr_str);
} }

@ -213,7 +213,7 @@ static void finish_accept(grpc_exec_ctx *exec_ctx, grpc_tcp_listener *sp) {
} else { } else {
gpr_log(GPR_INFO, "uv_tcp_getpeername error: %s", uv_strerror(err)); gpr_log(GPR_INFO, "uv_tcp_getpeername error: %s", uv_strerror(err));
} }
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
if (peer_name_string) { if (peer_name_string) {
gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s",
sp->server, peer_name_string); sp->server, peer_name_string);
@ -247,7 +247,7 @@ static void on_connect(uv_stream_t *server, int status) {
GPR_ASSERT(!sp->has_pending_connection); GPR_ASSERT(!sp->has_pending_connection);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p incoming connection", sp->server); gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p incoming connection", sp->server);
} }
@ -403,7 +403,7 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s,
gpr_free(allocated_addr); gpr_free(allocated_addr);
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
char *port_string; char *port_string;
grpc_sockaddr_to_string(&port_string, addr, 0); grpc_sockaddr_to_string(&port_string, addr, 0);
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
@ -435,7 +435,7 @@ void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *server,
(void)pollsets; (void)pollsets;
(void)pollset_count; (void)pollset_count;
GRPC_UV_ASSERT_SAME_THREAD(); GRPC_UV_ASSERT_SAME_THREAD();
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "SERVER_START %p", server); gpr_log(GPR_DEBUG, "SERVER_START %p", server);
} }
GPR_ASSERT(on_accept_cb); GPR_ASSERT(on_accept_cb);

@ -38,7 +38,7 @@
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); grpc_core::TraceFlag grpc_tcp_trace(false, "tcp");
typedef struct { typedef struct {
grpc_endpoint base; grpc_endpoint base;
@ -79,7 +79,7 @@ static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__)
static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@ -92,7 +92,7 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file, static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@ -158,7 +158,7 @@ static void read_callback(uv_stream_t *stream, ssize_t nread,
grpc_slice_buffer_add(tcp->read_slices, sub); grpc_slice_buffer_add(tcp->read_slices, sub);
tcp->read_slice = alloc_read_slice(&exec_ctx, tcp->resource_user); tcp->read_slice = alloc_read_slice(&exec_ctx, tcp->resource_user);
error = GRPC_ERROR_NONE; error = GRPC_ERROR_NONE;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
size_t i; size_t i;
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "read: error=%s", str); gpr_log(GPR_DEBUG, "read: error=%s", str);
@ -200,7 +200,7 @@ static void uv_endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_slice_from_static_string(uv_strerror(status))); grpc_slice_from_static_string(uv_strerror(status)));
GRPC_CLOSURE_SCHED(exec_ctx, cb, error); GRPC_CLOSURE_SCHED(exec_ctx, cb, error);
} }
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp, str); gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp, str);
} }
@ -218,7 +218,7 @@ static void write_callback(uv_write_t *req, int status) {
} else { } else {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed"); error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed");
} }
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(error); const char *str = grpc_error_string(error);
gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str); gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str);
} }
@ -240,7 +240,7 @@ static void uv_endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
uv_write_t *write_req; uv_write_t *write_req;
GRPC_UV_ASSERT_SAME_THREAD(); GRPC_UV_ASSERT_SAME_THREAD();
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
size_t j; size_t j;
for (j = 0; j < write_slices->count; j++) { for (j = 0; j < write_slices->count; j++) {
@ -310,7 +310,7 @@ static void uv_endpoint_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_error *why) { grpc_error *why) {
grpc_tcp *tcp = (grpc_tcp *)ep; grpc_tcp *tcp = (grpc_tcp *)ep;
if (!tcp->shutting_down) { if (!tcp->shutting_down) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
const char *str = grpc_error_string(why); const char *str = grpc_error_string(why);
gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->handle, str); gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->handle, str);
} }
@ -351,7 +351,7 @@ grpc_endpoint *grpc_tcp_create(uv_tcp_t *handle,
grpc_tcp *tcp = (grpc_tcp *)gpr_malloc(sizeof(grpc_tcp)); grpc_tcp *tcp = (grpc_tcp *)gpr_malloc(sizeof(grpc_tcp));
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp);
} }

@ -34,7 +34,7 @@
#include <uv.h> #include <uv.h>
extern grpc_tracer_flag grpc_tcp_trace; extern grpc_core::TraceFlag grpc_tcp_trace;
#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 #define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192

@ -49,7 +49,7 @@
#define GRPC_FIONBIO FIONBIO #define GRPC_FIONBIO FIONBIO
#endif #endif
grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); grpc_core::TraceFlag grpc_tcp_trace(false, "tcp");
static grpc_error *set_non_block(SOCKET sock) { static grpc_error *set_non_block(SOCKET sock) {
int status; int status;
@ -124,7 +124,7 @@ static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) #define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__)
static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
@ -137,7 +137,7 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file, static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (grpc_tcp_trace.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,

@ -44,9 +44,8 @@
#define MAX_QUEUE_WINDOW_DURATION 1 #define MAX_QUEUE_WINDOW_DURATION 1
extern "C" { extern "C" {
grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); grpc_core::TraceFlag grpc_timer_trace(false, "timer");
grpc_tracer_flag grpc_timer_check_trace = grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check");
GRPC_TRACER_INITIALIZER(false, "timer_check");
} }
/* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with /* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with
@ -247,8 +246,6 @@ void grpc_timer_list_init(grpc_exec_ctx *exec_ctx) {
g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx);
gpr_tls_init(&g_last_seen_min_timer); gpr_tls_init(&g_last_seen_min_timer);
gpr_tls_set(&g_last_seen_min_timer, 0); gpr_tls_set(&g_last_seen_min_timer, 0);
grpc_register_tracer(&grpc_timer_trace);
grpc_register_tracer(&grpc_timer_check_trace);
for (i = 0; i < NUM_SHARDS; i++) { for (i = 0; i < NUM_SHARDS; i++) {
timer_shard *shard = &g_shards[i]; timer_shard *shard = &g_shards[i];
@ -331,7 +328,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer,
timer->hash_table_next = NULL; timer->hash_table_next = NULL;
#endif #endif
if (GRPC_TRACER_ON(grpc_timer_trace)) { if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer,
deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb);
@ -367,7 +364,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer,
timer->heap_index = INVALID_HEAP_INDEX; timer->heap_index = INVALID_HEAP_INDEX;
list_join(&shard->list, timer); list_join(&shard->list, timer);
} }
if (GRPC_TRACER_ON(grpc_timer_trace)) { if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. add to shard %d with queue_deadline_cap=%" PRIdPTR gpr_log(GPR_DEBUG, " .. add to shard %d with queue_deadline_cap=%" PRIdPTR
" => is_first_timer=%s", " => is_first_timer=%s",
(int)(shard - g_shards), shard->queue_deadline_cap, (int)(shard - g_shards), shard->queue_deadline_cap,
@ -388,7 +385,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer,
grpc_timer_check. */ grpc_timer_check. */
if (is_first_timer) { if (is_first_timer) {
gpr_mu_lock(&g_shared_mutables.mu); gpr_mu_lock(&g_shared_mutables.mu);
if (GRPC_TRACER_ON(grpc_timer_trace)) { if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. old shard min_deadline=%" PRIdPTR, gpr_log(GPR_DEBUG, " .. old shard min_deadline=%" PRIdPTR,
shard->min_deadline); shard->min_deadline);
} }
@ -418,7 +415,7 @@ void grpc_timer_cancel(grpc_exec_ctx *exec_ctx, grpc_timer *timer) {
timer_shard *shard = &g_shards[GPR_HASH_POINTER(timer, NUM_SHARDS)]; timer_shard *shard = &g_shards[GPR_HASH_POINTER(timer, NUM_SHARDS)];
gpr_mu_lock(&shard->mu); gpr_mu_lock(&shard->mu);
if (GRPC_TRACER_ON(grpc_timer_trace)) { if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG, "TIMER %p: CANCEL pending=%s", timer, gpr_log(GPR_DEBUG, "TIMER %p: CANCEL pending=%s", timer,
timer->pending ? "true" : "false"); timer->pending ? "true" : "false");
} }
@ -459,7 +456,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) {
saturating_add(GPR_MAX(now, shard->queue_deadline_cap), saturating_add(GPR_MAX(now, shard->queue_deadline_cap),
(gpr_atm)(deadline_delta * 1000.0)); (gpr_atm)(deadline_delta * 1000.0));
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]->queue_deadline_cap --> %" PRIdPTR, gpr_log(GPR_DEBUG, " .. shard[%d]->queue_deadline_cap --> %" PRIdPTR,
(int)(shard - g_shards), shard->queue_deadline_cap); (int)(shard - g_shards), shard->queue_deadline_cap);
} }
@ -467,7 +464,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) {
next = timer->next; next = timer->next;
if (timer->deadline < shard->queue_deadline_cap) { if (timer->deadline < shard->queue_deadline_cap) {
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. add timer with deadline %" PRIdPTR " to heap", gpr_log(GPR_DEBUG, " .. add timer with deadline %" PRIdPTR " to heap",
timer->deadline); timer->deadline);
} }
@ -484,7 +481,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) {
static grpc_timer *pop_one(timer_shard *shard, gpr_atm now) { static grpc_timer *pop_one(timer_shard *shard, gpr_atm now) {
grpc_timer *timer; grpc_timer *timer;
for (;;) { for (;;) {
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s", gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s",
(int)(shard - g_shards), (int)(shard - g_shards),
grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false");
@ -494,13 +491,13 @@ static grpc_timer *pop_one(timer_shard *shard, gpr_atm now) {
if (!refill_heap(shard, now)) return NULL; if (!refill_heap(shard, now)) return NULL;
} }
timer = grpc_timer_heap_top(&shard->heap); timer = grpc_timer_heap_top(&shard->heap);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
" .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR, " .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR,
timer->deadline, now); timer->deadline, now);
} }
if (timer->deadline > now) return NULL; if (timer->deadline > now) return NULL;
if (GRPC_TRACER_ON(grpc_timer_trace)) { if (grpc_timer_trace.enabled()) {
gpr_log(GPR_DEBUG, "TIMER %p: FIRE %" PRIdPTR "ms late via %s scheduler", gpr_log(GPR_DEBUG, "TIMER %p: FIRE %" PRIdPTR "ms late via %s scheduler",
timer, now - timer->deadline, timer, now - timer->deadline,
timer->closure->scheduler->vtable->name); timer->closure->scheduler->vtable->name);
@ -525,7 +522,7 @@ static size_t pop_timers(grpc_exec_ctx *exec_ctx, timer_shard *shard,
} }
*new_min_deadline = compute_min_deadline(shard); *new_min_deadline = compute_min_deadline(shard);
gpr_mu_unlock(&shard->mu); gpr_mu_unlock(&shard->mu);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d] popped %" PRIdPTR, gpr_log(GPR_DEBUG, " .. shard[%d] popped %" PRIdPTR,
(int)(shard - g_shards), n); (int)(shard - g_shards), n);
} }
@ -549,7 +546,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(&g_shared_mutables.mu); gpr_mu_lock(&g_shared_mutables.mu);
result = GRPC_TIMERS_CHECKED_AND_EMPTY; result = GRPC_TIMERS_CHECKED_AND_EMPTY;
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, " .. shard[%d]->min_deadline = %" PRIdPTR, gpr_log(GPR_DEBUG, " .. shard[%d]->min_deadline = %" PRIdPTR,
(int)(g_shard_queue[0] - g_shards), (int)(g_shard_queue[0] - g_shards),
g_shard_queue[0]->min_deadline); g_shard_queue[0]->min_deadline);
@ -567,7 +564,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx *exec_ctx,
result = GRPC_TIMERS_FIRED; result = GRPC_TIMERS_FIRED;
} }
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
" .. result --> %d" " .. result --> %d"
", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR ", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR
@ -612,7 +609,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx,
if (next != NULL) { if (next != NULL) {
*next = GPR_MIN(*next, min_timer); *next = GPR_MIN(*next, min_timer);
} }
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"TIMER CHECK SKIP: now=%" PRIdPTR " min_timer=%" PRIdPTR, now, "TIMER CHECK SKIP: now=%" PRIdPTR " min_timer=%" PRIdPTR, now,
min_timer); min_timer);
@ -626,7 +623,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx,
: GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system"); : GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system");
// tracing // tracing
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
char *next_str; char *next_str;
if (next == NULL) { if (next == NULL) {
next_str = gpr_strdup("NULL"); next_str = gpr_strdup("NULL");
@ -643,7 +640,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx,
grpc_timer_check_result r = grpc_timer_check_result r =
run_some_expired_timers(exec_ctx, now, next, shutdown_error); run_some_expired_timers(exec_ctx, now, next, shutdown_error);
// tracing // tracing
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
char *next_str; char *next_str;
if (next == NULL) { if (next == NULL) {
next_str = gpr_strdup("NULL"); next_str = gpr_strdup("NULL");

@ -33,7 +33,7 @@ typedef struct completed_thread {
struct completed_thread *next; struct completed_thread *next;
} completed_thread; } completed_thread;
extern "C" grpc_tracer_flag grpc_timer_check_trace; extern grpc_core::TraceFlag grpc_timer_check_trace;
// global mutex // global mutex
static gpr_mu g_mu; static gpr_mu g_mu;
@ -81,7 +81,7 @@ static void start_timer_thread_and_unlock(void) {
++g_waiter_count; ++g_waiter_count;
++g_thread_count; ++g_thread_count;
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "Spawn timer thread"); gpr_log(GPR_DEBUG, "Spawn timer thread");
} }
gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options opt = gpr_thd_options_default();
@ -115,7 +115,7 @@ static void run_some_timers(grpc_exec_ctx *exec_ctx) {
// if there's no thread waiting with a timeout, kick an existing // if there's no thread waiting with a timeout, kick an existing
// waiter so that the next deadline is not missed // waiter so that the next deadline is not missed
if (!g_has_timed_waiter) { if (!g_has_timed_waiter) {
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "kick untimed waiter"); gpr_log(GPR_DEBUG, "kick untimed waiter");
} }
gpr_cv_signal(&g_cv_wait); gpr_cv_signal(&g_cv_wait);
@ -123,7 +123,7 @@ static void run_some_timers(grpc_exec_ctx *exec_ctx) {
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
} }
// without our lock, flush the exec_ctx // without our lock, flush the exec_ctx
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "flush exec_ctx"); gpr_log(GPR_DEBUG, "flush exec_ctx");
} }
grpc_exec_ctx_flush(exec_ctx); grpc_exec_ctx_flush(exec_ctx);
@ -178,7 +178,7 @@ static bool wait_until(grpc_exec_ctx *exec_ctx, grpc_millis next) {
g_has_timed_waiter = true; g_has_timed_waiter = true;
g_timed_waiter_deadline = next; g_timed_waiter_deadline = next;
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx); grpc_millis wait_time = next - grpc_exec_ctx_now(exec_ctx);
gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds",
wait_time); wait_time);
@ -188,15 +188,14 @@ static bool wait_until(grpc_exec_ctx *exec_ctx, grpc_millis next) {
} }
} }
if (GRPC_TRACER_ON(grpc_timer_check_trace) && if (grpc_timer_check_trace.enabled() && next == GRPC_MILLIS_INF_FUTURE) {
next == GRPC_MILLIS_INF_FUTURE) {
gpr_log(GPR_DEBUG, "sleep until kicked"); gpr_log(GPR_DEBUG, "sleep until kicked");
} }
gpr_cv_wait(&g_cv_wait, &g_mu, gpr_cv_wait(&g_cv_wait, &g_mu,
grpc_millis_to_timespec(next, GPR_CLOCK_REALTIME)); grpc_millis_to_timespec(next, GPR_CLOCK_REALTIME));
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "wait ended: was_timed:%d kicked:%d", gpr_log(GPR_DEBUG, "wait ended: was_timed:%d kicked:%d",
my_timed_waiter_generation == g_timed_waiter_generation, my_timed_waiter_generation == g_timed_waiter_generation,
g_kicked); g_kicked);
@ -240,7 +239,7 @@ static void timer_main_loop(grpc_exec_ctx *exec_ctx) {
Consequently, we can just sleep forever here and be happy at some Consequently, we can just sleep forever here and be happy at some
saved wakeup cycles. */ saved wakeup cycles. */
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "timers not checked: expect another thread to"); gpr_log(GPR_DEBUG, "timers not checked: expect another thread to");
} }
next = GRPC_MILLIS_INF_FUTURE; next = GRPC_MILLIS_INF_FUTURE;
@ -266,7 +265,7 @@ static void timer_thread_cleanup(completed_thread *ct) {
ct->next = g_completed_threads; ct->next = g_completed_threads;
g_completed_threads = ct; g_completed_threads = ct;
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "End timer thread"); gpr_log(GPR_DEBUG, "End timer thread");
} }
} }
@ -309,18 +308,18 @@ void grpc_timer_manager_init(void) {
static void stop_threads(void) { static void stop_threads(void) {
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "stop timer threads: threaded=%d", g_threaded); gpr_log(GPR_DEBUG, "stop timer threads: threaded=%d", g_threaded);
} }
if (g_threaded) { if (g_threaded) {
g_threaded = false; g_threaded = false;
gpr_cv_broadcast(&g_cv_wait); gpr_cv_broadcast(&g_cv_wait);
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count); gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
} }
while (g_thread_count > 0) { while (g_thread_count > 0) {
gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); gpr_cv_wait(&g_cv_shutdown, &g_mu, gpr_inf_future(GPR_CLOCK_REALTIME));
if (GRPC_TRACER_ON(grpc_timer_check_trace)) { if (grpc_timer_check_trace.enabled()) {
gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count); gpr_log(GPR_DEBUG, "num timer threads: %d", g_thread_count);
} }
gc_completed_threads(); gc_completed_threads();

@ -30,9 +30,8 @@
#include <uv.h> #include <uv.h>
extern "C" { extern "C" {
grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); grpc_core::TraceFlag grpc_timer_trace(false, "timer");
grpc_tracer_flag grpc_timer_check_trace = grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check");
GRPC_TRACER_INITIALIZER(false, "timer_check");
} }
static void timer_close_callback(uv_handle_t *handle) { gpr_free(handle); } static void timer_close_callback(uv_handle_t *handle) { gpr_free(handle); }

@ -30,8 +30,8 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_auth_context_refcount = grpc_core::TraceFlag grpc_trace_auth_context_refcount(false,
GRPC_TRACER_INITIALIZER(false, "auth_context_refcount"); "auth_context_refcount");
#endif #endif
/* --- grpc_call --- */ /* --- grpc_call --- */
@ -135,7 +135,7 @@ grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx,
const char *file, int line, const char *file, int line,
const char *reason) { const char *reason) {
if (ctx == NULL) return NULL; if (ctx == NULL) return NULL;
if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) { if (grpc_trace_auth_context_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"AUTH_CONTEXT:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val, "AUTH_CONTEXT:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val,
@ -153,7 +153,7 @@ grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx) {
void grpc_auth_context_unref(grpc_auth_context *ctx, const char *file, int line, void grpc_auth_context_unref(grpc_auth_context *ctx, const char *file, int line,
const char *reason) { const char *reason) {
if (ctx == NULL) return; if (ctx == NULL) return;
if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) { if (grpc_trace_auth_context_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"AUTH_CONTEXT:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val, "AUTH_CONTEXT:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val,

@ -23,7 +23,7 @@
#include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/credentials.h"
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_auth_context_refcount; extern grpc_core::TraceFlag grpc_trace_auth_context_refcount;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

@ -172,7 +172,7 @@ static char *redact_private_key(const char *json_key) {
grpc_call_credentials *grpc_service_account_jwt_access_credentials_create( grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
const char *json_key, gpr_timespec token_lifetime, void *reserved) { const char *json_key, gpr_timespec token_lifetime, void *reserved) {
if (GRPC_TRACER_ON(grpc_api_trace)) { if (grpc_api_trace.enabled()) {
char *clean_json = redact_private_key(json_key); char *clean_json = redact_private_key(json_key);
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"grpc_service_account_jwt_access_credentials_create(" "grpc_service_account_jwt_access_credentials_create("

@ -467,7 +467,7 @@ grpc_call_credentials *grpc_google_refresh_token_credentials_create(
const char *json_refresh_token, void *reserved) { const char *json_refresh_token, void *reserved) {
grpc_auth_refresh_token token = grpc_auth_refresh_token token =
grpc_auth_refresh_token_create_from_string(json_refresh_token); grpc_auth_refresh_token_create_from_string(json_refresh_token);
if (GRPC_TRACER_ON(grpc_api_trace)) { if (grpc_api_trace.enabled()) {
char *loggable_token = create_loggable_refresh_token(&token); char *loggable_token = create_loggable_refresh_token(&token);
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"grpc_refresh_token_credentials_create(json_refresh_token=%s, " "grpc_refresh_token_credentials_create(json_refresh_token=%s, "

@ -31,8 +31,7 @@
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/validate_metadata.h" #include "src/core/lib/surface/validate_metadata.h"
grpc_tracer_flag grpc_plugin_credentials_trace = grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials");
GRPC_TRACER_INITIALIZER(false, "plugin_credentials");
static void plugin_destruct(grpc_exec_ctx *exec_ctx, static void plugin_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) { grpc_call_credentials *creds) {
@ -123,7 +122,7 @@ static void plugin_md_request_metadata_ready(void *request,
NULL, NULL); NULL, NULL);
grpc_plugin_credentials_pending_request *r = grpc_plugin_credentials_pending_request *r =
(grpc_plugin_credentials_pending_request *)request; (grpc_plugin_credentials_pending_request *)request;
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned " "plugin_credentials[%p]: request %p: plugin returned "
"asynchronously", "asynchronously",
@ -136,7 +135,7 @@ static void plugin_md_request_metadata_ready(void *request,
grpc_error *error = grpc_error *error =
process_plugin_result(&exec_ctx, r, md, num_md, status, error_details); process_plugin_result(&exec_ctx, r, md, num_md, status, error_details);
GRPC_CLOSURE_SCHED(&exec_ctx, r->on_request_metadata, error); GRPC_CLOSURE_SCHED(&exec_ctx, r->on_request_metadata, error);
} else if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { } else if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin was previously " "plugin_credentials[%p]: request %p: plugin was previously "
"cancelled", "cancelled",
@ -172,7 +171,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx,
c->pending_requests = pending_request; c->pending_requests = pending_request;
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
// Invoke the plugin. The callback holds a ref to us. // Invoke the plugin. The callback holds a ref to us.
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin", gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
c, pending_request); c, pending_request);
} }
@ -185,7 +184,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx,
plugin_md_request_metadata_ready, plugin_md_request_metadata_ready,
pending_request, creds_md, &num_creds_md, pending_request, creds_md, &num_creds_md,
&status, &error_details)) { &status, &error_details)) {
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin will return " "plugin_credentials[%p]: request %p: plugin will return "
"asynchronously", "asynchronously",
@ -200,7 +199,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx,
// asynchronously by plugin_cancel_get_request_metadata(), so return // asynchronously by plugin_cancel_get_request_metadata(), so return
// false. Otherwise, process the result. // false. Otherwise, process the result.
if (pending_request->cancelled) { if (pending_request->cancelled) {
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p was cancelled, error " "plugin_credentials[%p]: request %p was cancelled, error "
"will be returned asynchronously", "will be returned asynchronously",
@ -208,7 +207,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx,
} }
retval = false; retval = false;
} else { } else {
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
"plugin_credentials[%p]: request %p: plugin returned " "plugin_credentials[%p]: request %p: plugin returned "
"synchronously", "synchronously",
@ -237,7 +236,7 @@ static void plugin_cancel_get_request_metadata(
c->pending_requests; c->pending_requests;
pending_request != NULL; pending_request = pending_request->next) { pending_request != NULL; pending_request = pending_request->next) {
if (pending_request->md_array == md_array) { if (pending_request->md_array == md_array) {
if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { if (grpc_plugin_credentials_trace.enabled()) {
gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", c, gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", c,
pending_request); pending_request);
} }

@ -21,7 +21,7 @@
#include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/credentials.h"
extern grpc_tracer_flag grpc_plugin_credentials_trace; extern grpc_core::TraceFlag grpc_plugin_credentials_trace;
struct grpc_plugin_credentials; struct grpc_plugin_credentials;

@ -61,8 +61,7 @@ typedef struct {
gpr_refcount ref; gpr_refcount ref;
} secure_endpoint; } secure_endpoint;
grpc_tracer_flag grpc_trace_secure_endpoint = grpc_core::TraceFlag grpc_trace_secure_endpoint(false, "secure_endpoint");
GRPC_TRACER_INITIALIZER(false, "secure_endpoint");
static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) { static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
secure_endpoint *ep = secure_ep; secure_endpoint *ep = secure_ep;
@ -86,7 +85,7 @@ static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
static void secure_endpoint_unref(grpc_exec_ctx *exec_ctx, secure_endpoint *ep, static void secure_endpoint_unref(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
const char *reason, const char *file, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (grpc_trace_secure_endpoint.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val, "SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
@ -99,7 +98,7 @@ static void secure_endpoint_unref(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
static void secure_endpoint_ref(secure_endpoint *ep, const char *reason, static void secure_endpoint_ref(secure_endpoint *ep, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (grpc_trace_secure_endpoint.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val, "SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
@ -131,7 +130,7 @@ static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur,
static void call_read_cb(grpc_exec_ctx *exec_ctx, secure_endpoint *ep, static void call_read_cb(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
grpc_error *error) { grpc_error *error) {
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (grpc_trace_secure_endpoint.enabled()) {
size_t i; size_t i;
for (i = 0; i < ep->read_buffer->count; i++) { for (i = 0; i < ep->read_buffer->count; i++) {
char *data = grpc_dump_slice(ep->read_buffer->slices[i], char *data = grpc_dump_slice(ep->read_buffer->slices[i],
@ -270,7 +269,7 @@ static void endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer);
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (grpc_trace_secure_endpoint.enabled()) {
for (i = 0; i < slices->count; i++) { for (i = 0; i < slices->count; i++) {
char *data = char *data =
grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);

@ -29,7 +29,7 @@ extern "C" {
struct tsi_frame_protector; struct tsi_frame_protector;
struct tsi_zero_copy_grpc_protector; struct tsi_zero_copy_grpc_protector;
extern grpc_tracer_flag grpc_trace_secure_endpoint; extern grpc_core::TraceFlag grpc_trace_secure_endpoint;
/* Takes ownership of protector, zero_copy_protector, and to_wrap, and refs /* Takes ownership of protector, zero_copy_protector, and to_wrap, and refs
* leftover_slices. If zero_copy_protector is not NULL, protector will never be * leftover_slices. If zero_copy_protector is not NULL, protector will never be

@ -44,8 +44,8 @@
#include "src/core/tsi/transport_security_adapter.h" #include "src/core/tsi/transport_security_adapter.h"
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_security_connector_refcount = grpc_core::TraceFlag grpc_trace_security_connector_refcount(
GRPC_TRACER_INITIALIZER(false, "security_connector_refcount"); false, "security_connector_refcount");
#endif #endif
/* -- Constants. -- */ /* -- Constants. -- */
@ -197,7 +197,7 @@ grpc_security_connector *grpc_security_connector_ref(
grpc_security_connector *sc, const char *file, int line, grpc_security_connector *sc, const char *file, int line,
const char *reason) { const char *reason) {
if (sc == NULL) return NULL; if (sc == NULL) return NULL;
if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) { if (grpc_trace_security_connector_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"SECURITY_CONNECTOR:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", sc, "SECURITY_CONNECTOR:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", sc,
@ -218,7 +218,7 @@ void grpc_security_connector_unref(grpc_exec_ctx *exec_ctx,
const char *file, int line, const char *file, int line,
const char *reason) { const char *reason) {
if (sc == NULL) return; if (sc == NULL) return;
if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) { if (grpc_trace_security_connector_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"SECURITY_CONNECTOR:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", sc, "SECURITY_CONNECTOR:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", sc,

@ -34,7 +34,7 @@ extern "C" {
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_security_connector_refcount; extern grpc_core::TraceFlag grpc_trace_security_connector_refcount;
#endif #endif
/* --- status enum. --- */ /* --- status enum. --- */

@ -28,8 +28,7 @@
#include "src/core/lib/surface/completion_queue.h" #include "src/core/lib/surface/completion_queue.h"
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_alarm_refcount = grpc_core::TraceFlag grpc_trace_alarm_refcount(false, "alarm_refcount");
GRPC_TRACER_INITIALIZER(false, "alarm_refcount");
#endif #endif
struct grpc_alarm { struct grpc_alarm {
@ -59,7 +58,7 @@ static void alarm_unref(grpc_alarm *alarm) {
#ifndef NDEBUG #ifndef NDEBUG
static void alarm_ref_dbg(grpc_alarm *alarm, const char *reason, static void alarm_ref_dbg(grpc_alarm *alarm, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_alarm_refcount)) { if (grpc_trace_alarm_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count); gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"Alarm:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, "Alarm:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val,
@ -71,7 +70,7 @@ static void alarm_ref_dbg(grpc_alarm *alarm, const char *reason,
static void alarm_unref_dbg(grpc_alarm *alarm, const char *reason, static void alarm_unref_dbg(grpc_alarm *alarm, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_alarm_refcount)) { if (grpc_trace_alarm_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count); gpr_atm val = gpr_atm_no_barrier_load(&alarm->refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"Alarm:%p Unref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, "Alarm:%p Unref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val,
@ -103,7 +102,7 @@ grpc_alarm *grpc_alarm_create(void *reserved) {
grpc_alarm *alarm = (grpc_alarm *)gpr_malloc(sizeof(grpc_alarm)); grpc_alarm *alarm = (grpc_alarm *)gpr_malloc(sizeof(grpc_alarm));
#ifndef NDEBUG #ifndef NDEBUG
if (GRPC_TRACER_ON(grpc_trace_alarm_refcount)) { if (grpc_trace_alarm_refcount.enabled()) {
gpr_log(GPR_DEBUG, "Alarm:%p created (ref: 1)", alarm); gpr_log(GPR_DEBUG, "Alarm:%p created (ref: 1)", alarm);
} }
#endif #endif

@ -28,7 +28,7 @@ extern "C" {
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_alarm_refcount; extern grpc_core::TraceFlag grpc_trace_alarm_refcount;
#define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__) #define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__)
#define GRPC_ALARM_UNREF(a, reason) \ #define GRPC_ALARM_UNREF(a, reason) \

@ -19,4 +19,4 @@
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
grpc_tracer_flag grpc_api_trace = GRPC_TRACER_INITIALIZER(false, "api"); grpc_core::TraceFlag grpc_api_trace(false, "api");

@ -26,7 +26,7 @@
extern "C" { extern "C" {
#endif #endif
extern grpc_tracer_flag grpc_api_trace; extern grpc_core::TraceFlag grpc_api_trace;
/* Provide unwrapping macros because we're in C89 and variadic macros weren't /* Provide unwrapping macros because we're in C89 and variadic macros weren't
introduced until C99... */ introduced until C99... */
@ -47,7 +47,7 @@ extern grpc_tracer_flag grpc_api_trace;
/* Due to the limitations of C89's preprocessor, the arity of the var-arg list /* Due to the limitations of C89's preprocessor, the arity of the var-arg list
'nargs' must be specified. */ 'nargs' must be specified. */
#define GRPC_API_TRACE(fmt, nargs, args) \ #define GRPC_API_TRACE(fmt, nargs, args) \
if (GRPC_TRACER_ON(grpc_api_trace)) { \ if (grpc_api_trace.enabled()) { \
gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \ gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \
} }

@ -259,10 +259,8 @@ struct grpc_call {
gpr_atm recv_state; gpr_atm recv_state;
}; };
grpc_tracer_flag grpc_call_error_trace = grpc_core::TraceFlag grpc_call_error_trace(false, "call_error");
GRPC_TRACER_INITIALIZER(false, "call_error"); grpc_core::TraceFlag grpc_compression_trace(false, "compression");
grpc_tracer_flag grpc_compression_trace =
GRPC_TRACER_INITIALIZER(false, "compression");
#define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1)) #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1))
#define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1) #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1)
@ -764,7 +762,7 @@ static void get_final_status(grpc_exec_ctx *exec_ctx, grpc_call *call,
for (i = 0; i < STATUS_SOURCE_COUNT; i++) { for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
status[i] = unpack_received_status(gpr_atm_acq_load(&call->status[i])); status[i] = unpack_received_status(gpr_atm_acq_load(&call->status[i]));
} }
if (GRPC_TRACER_ON(grpc_call_error_trace)) { if (grpc_call_error_trace.enabled()) {
gpr_log(GPR_DEBUG, "get_final_status %s", call->is_client ? "CLI" : "SVR"); gpr_log(GPR_DEBUG, "get_final_status %s", call->is_client ? "CLI" : "SVR");
for (i = 0; i < STATUS_SOURCE_COUNT; i++) { for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
if (status[i].is_set) { if (status[i].is_set) {
@ -1426,7 +1424,7 @@ static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp,
} }
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
if (GRPC_TRACER_ON(grpc_trace_operation_failures)) { if (grpc_trace_operation_failures.enabled()) {
GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error)); GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error));
} }
grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); grpc_byte_stream_destroy(exec_ctx, call->receiving_stream);
@ -1530,7 +1528,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(call->stream_encodings_accepted_by_peer != 0); GPR_ASSERT(call->stream_encodings_accepted_by_peer != 0);
if (!GPR_BITGET(call->stream_encodings_accepted_by_peer, if (!GPR_BITGET(call->stream_encodings_accepted_by_peer,
call->incoming_stream_compression_algorithm)) { call->incoming_stream_compression_algorithm)) {
if (GRPC_TRACER_ON(grpc_compression_trace)) { if (grpc_compression_trace.enabled()) {
const char *algo_name = NULL; const char *algo_name = NULL;
grpc_stream_compression_algorithm_name( grpc_stream_compression_algorithm_name(
call->incoming_stream_compression_algorithm, &algo_name); call->incoming_stream_compression_algorithm, &algo_name);
@ -1573,7 +1571,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(call->encodings_accepted_by_peer != 0); GPR_ASSERT(call->encodings_accepted_by_peer != 0);
if (!GPR_BITGET(call->encodings_accepted_by_peer, if (!GPR_BITGET(call->encodings_accepted_by_peer,
call->incoming_compression_algorithm)) { call->incoming_compression_algorithm)) {
if (GRPC_TRACER_ON(grpc_compression_trace)) { if (grpc_compression_trace.enabled()) {
const char *algo_name = NULL; const char *algo_name = NULL;
grpc_compression_algorithm_name(call->incoming_compression_algorithm, grpc_compression_algorithm_name(call->incoming_compression_algorithm,
&algo_name); &algo_name);

@ -102,8 +102,7 @@ void grpc_call_context_set(grpc_call *call, grpc_context_index elem,
void *grpc_call_context_get(grpc_call *call, grpc_context_index elem); void *grpc_call_context_get(grpc_call *call, grpc_context_index elem);
#define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \ #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \
if (GRPC_TRACER_ON(grpc_api_trace)) \ if (grpc_api_trace.enabled()) grpc_call_log_batch(sev, call, ops, nops, tag)
grpc_call_log_batch(sev, call, ops, nops, tag)
uint8_t grpc_call_is_client(grpc_call *call); uint8_t grpc_call_is_client(grpc_call *call);
@ -112,8 +111,8 @@ uint8_t grpc_call_is_client(grpc_call *call);
grpc_compression_algorithm grpc_call_compression_for_level( grpc_compression_algorithm grpc_call_compression_for_level(
grpc_call *call, grpc_compression_level level); grpc_call *call, grpc_compression_level level);
extern grpc_tracer_flag grpc_call_error_trace; extern grpc_core::TraceFlag grpc_call_error_trace;
extern grpc_tracer_flag grpc_compression_trace; extern grpc_core::TraceFlag grpc_compression_trace;
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -39,13 +39,10 @@
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/event_string.h" #include "src/core/lib/surface/event_string.h"
grpc_tracer_flag grpc_trace_operation_failures = grpc_core::TraceFlag grpc_trace_operation_failures(false, "op_failure");
GRPC_TRACER_INITIALIZER(false, "op_failure");
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_pending_tags = grpc_core::TraceFlag grpc_trace_pending_tags(false, "pending_tags");
GRPC_TRACER_INITIALIZER(false, "pending_tags"); grpc_core::TraceFlag grpc_trace_cq_refcount(false, "cq_refcount");
grpc_tracer_flag grpc_trace_cq_refcount =
GRPC_TRACER_INITIALIZER(false, "cq_refcount");
#endif #endif
typedef struct { typedef struct {
@ -328,14 +325,11 @@ static const cq_vtable g_cq_vtable[] = {
#define POLLSET_FROM_CQ(cq) \ #define POLLSET_FROM_CQ(cq) \
((grpc_pollset *)(cq->vtable->data_size + (char *)DATA_FROM_CQ(cq))) ((grpc_pollset *)(cq->vtable->data_size + (char *)DATA_FROM_CQ(cq)))
grpc_tracer_flag grpc_cq_pluck_trace = grpc_core::TraceFlag grpc_cq_pluck_trace(true, "queue_pluck");
GRPC_TRACER_INITIALIZER(true, "queue_pluck"); grpc_core::TraceFlag grpc_cq_event_timeout_trace(true, "queue_timeout");
grpc_tracer_flag grpc_cq_event_timeout_trace =
GRPC_TRACER_INITIALIZER(true, "queue_timeout");
#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ #define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \
if (GRPC_TRACER_ON(grpc_api_trace) && \ if (grpc_api_trace.enabled() && (grpc_cq_pluck_trace.enabled() || \
(GRPC_TRACER_ON(grpc_cq_pluck_trace) || \
(event)->type != GRPC_QUEUE_TIMEOUT)) { \ (event)->type != GRPC_QUEUE_TIMEOUT)) { \
char *_ev = grpc_event_string(event); \ char *_ev = grpc_event_string(event); \
gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \
@ -481,7 +475,7 @@ int grpc_get_cq_poll_num(grpc_completion_queue *cq) {
#ifndef NDEBUG #ifndef NDEBUG
void grpc_cq_internal_ref(grpc_completion_queue *cq, const char *reason, void grpc_cq_internal_ref(grpc_completion_queue *cq, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_cq_refcount)) { if (grpc_trace_cq_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"CQ:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val + 1, "CQ:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val + 1,
@ -502,7 +496,7 @@ static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *arg,
#ifndef NDEBUG #ifndef NDEBUG
void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_cq_refcount)) { if (grpc_trace_cq_refcount.enabled()) {
gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
"CQ:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val - 1, "CQ:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val - 1,
@ -604,16 +598,14 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx,
void *done_arg, grpc_cq_completion *storage) { void *done_arg, grpc_cq_completion *storage) {
GPR_TIMER_BEGIN("cq_end_op_for_next", 0); GPR_TIMER_BEGIN("cq_end_op_for_next", 0);
if (GRPC_TRACER_ON(grpc_api_trace) || if (grpc_api_trace.enabled() ||
(GRPC_TRACER_ON(grpc_trace_operation_failures) && (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) {
error != GRPC_ERROR_NONE)) {
const char *errmsg = grpc_error_string(error); const char *errmsg = grpc_error_string(error);
GRPC_API_TRACE( GRPC_API_TRACE(
"cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, "
"done=%p, done_arg=%p, storage=%p)", "done=%p, done_arg=%p, storage=%p)",
7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage));
if (GRPC_TRACER_ON(grpc_trace_operation_failures) && if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) {
error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg);
} }
} }
@ -688,16 +680,14 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx,
GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0); GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0);
if (GRPC_TRACER_ON(grpc_api_trace) || if (grpc_api_trace.enabled() ||
(GRPC_TRACER_ON(grpc_trace_operation_failures) && (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) {
error != GRPC_ERROR_NONE)) {
const char *errmsg = grpc_error_string(error); const char *errmsg = grpc_error_string(error);
GRPC_API_TRACE( GRPC_API_TRACE(
"cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, "
"done=%p, done_arg=%p, storage=%p)", "done=%p, done_arg=%p, storage=%p)",
7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage));
if (GRPC_TRACER_ON(grpc_trace_operation_failures) && if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) {
error != GRPC_ERROR_NONE) {
gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg);
} }
} }
@ -791,7 +781,7 @@ static bool cq_is_next_finished(grpc_exec_ctx *exec_ctx, void *arg) {
#ifndef NDEBUG #ifndef NDEBUG
static void dump_pending_tags(grpc_completion_queue *cq) { static void dump_pending_tags(grpc_completion_queue *cq) {
if (!GRPC_TRACER_ON(grpc_trace_pending_tags)) return; if (!grpc_trace_pending_tags.enabled()) return;
gpr_strvec v; gpr_strvec v;
gpr_strvec_init(&v); gpr_strvec_init(&v);
@ -1054,7 +1044,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag,
GPR_TIMER_BEGIN("grpc_completion_queue_pluck", 0); GPR_TIMER_BEGIN("grpc_completion_queue_pluck", 0);
if (GRPC_TRACER_ON(grpc_cq_pluck_trace)) { if (grpc_cq_pluck_trace.enabled()) {
GRPC_API_TRACE( GRPC_API_TRACE(
"grpc_completion_queue_pluck(" "grpc_completion_queue_pluck("
"cq=%p, tag=%p, " "cq=%p, tag=%p, "

@ -27,13 +27,13 @@
/* These trace flags default to 1. The corresponding lines are only traced /* These trace flags default to 1. The corresponding lines are only traced
if grpc_api_trace is also truthy */ if grpc_api_trace is also truthy */
extern grpc_tracer_flag grpc_cq_pluck_trace; extern grpc_core::TraceFlag grpc_cq_pluck_trace;
extern grpc_tracer_flag grpc_cq_event_timeout_trace; extern grpc_core::TraceFlag grpc_cq_event_timeout_trace;
extern grpc_tracer_flag grpc_trace_operation_failures; extern grpc_core::TraceFlag grpc_trace_operation_failures;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_pending_tags; extern grpc_core::TraceFlag grpc_trace_pending_tags;
extern grpc_tracer_flag grpc_trace_cq_refcount; extern grpc_core::TraceFlag grpc_trace_cq_refcount;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

@ -125,29 +125,9 @@ void grpc_init(void) {
grpc_slice_intern_init(); grpc_slice_intern_init();
grpc_mdctx_global_init(); grpc_mdctx_global_init();
grpc_channel_init_init(); grpc_channel_init_init();
grpc_register_tracer(&grpc_api_trace);
grpc_register_tracer(&grpc_trace_channel);
grpc_register_tracer(&grpc_connectivity_state_trace);
grpc_register_tracer(&grpc_trace_channel_stack_builder);
grpc_register_tracer(&grpc_http1_trace);
grpc_register_tracer(&grpc_cq_pluck_trace); // default on
grpc_register_tracer(&grpc_call_combiner_trace);
grpc_register_tracer(&grpc_combiner_trace);
grpc_register_tracer(&grpc_server_channel_trace);
grpc_register_tracer(&grpc_bdp_estimator_trace);
grpc_register_tracer(&grpc_cq_event_timeout_trace); // default on
grpc_register_tracer(&grpc_trace_operation_failures);
grpc_register_tracer(&grpc_resource_quota_trace);
grpc_register_tracer(&grpc_call_error_trace);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer(&grpc_trace_pending_tags);
grpc_register_tracer(&grpc_trace_alarm_refcount);
grpc_register_tracer(&grpc_trace_cq_refcount);
grpc_register_tracer(&grpc_trace_closure);
grpc_register_tracer(&grpc_trace_error_refcount);
grpc_register_tracer(&grpc_trace_stream_refcount);
grpc_register_tracer(&grpc_trace_fd_refcount);
grpc_register_tracer(&grpc_trace_metadata);
#endif #endif
grpc_security_pre_init(); grpc_security_pre_init();
grpc_iomgr_init(&exec_ctx); grpc_iomgr_init(&exec_ctx);

@ -38,11 +38,8 @@
#endif #endif
void grpc_security_pre_init(void) { void grpc_security_pre_init(void) {
grpc_register_tracer(&grpc_trace_secure_endpoint);
grpc_register_tracer(&tsi_tracing_enabled);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer(&grpc_trace_auth_context_refcount);
grpc_register_tracer(&grpc_trace_security_connector_refcount);
#endif #endif
} }
@ -85,7 +82,4 @@ void grpc_register_security_filters(void) {
maybe_prepend_server_auth_filter, NULL); maybe_prepend_server_auth_filter, NULL);
} }
void grpc_security_init() { void grpc_security_init() { grpc_security_register_handshaker_factories(); }
grpc_security_register_handshaker_factories();
grpc_register_tracer(&grpc_plugin_credentials_trace);
}

@ -59,8 +59,7 @@ typedef struct registered_method registered_method;
typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type;
grpc_tracer_flag grpc_server_channel_trace = grpc_core::TraceFlag grpc_server_channel_trace(false, "server_channel");
GRPC_TRACER_INITIALIZER(false, "server_channel");
typedef struct requested_call { typedef struct requested_call {
requested_call_type type; requested_call_type type;
@ -445,7 +444,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure,
finish_destroy_channel, chand, grpc_schedule_on_exec_ctx); finish_destroy_channel, chand, grpc_schedule_on_exec_ctx);
if (GRPC_TRACER_ON(grpc_server_channel_trace) && error != GRPC_ERROR_NONE) { if (grpc_server_channel_trace.enabled() && error != GRPC_ERROR_NONE) {
const char *msg = grpc_error_string(error); const char *msg = grpc_error_string(error);
gpr_log(GPR_INFO, "Disconnected client: %s", msg); gpr_log(GPR_INFO, "Disconnected client: %s", msg);
} }

@ -31,7 +31,7 @@ extern "C" {
extern const grpc_channel_filter grpc_server_top_filter; extern const grpc_channel_filter grpc_server_top_filter;
/** Lightweight tracing of server channel state */ /** Lightweight tracing of server channel state */
extern grpc_tracer_flag grpc_server_channel_trace; extern grpc_core::TraceFlag grpc_server_channel_trace;
/* Add a listener to the server: when the server starts, it will call start, /* Add a listener to the server: when the server starts, it will call start,
and when it shuts down, it will call destroy */ and when it shuts down, it will call destroy */

@ -23,8 +23,7 @@
#include <grpc/support/useful.h> #include <grpc/support/useful.h>
grpc_tracer_flag grpc_bdp_estimator_trace = grpc_core::TraceFlag grpc_bdp_estimator_trace(false, "bdp_estimator");
GRPC_TRACER_INITIALIZER(false, "bdp_estimator");
namespace grpc_core { namespace grpc_core {
@ -44,7 +43,7 @@ grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec; double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec;
double bw = dt > 0 ? ((double)accumulator_ / dt) : 0; double bw = dt > 0 ? ((double)accumulator_ / dt) : 0;
int start_inter_ping_delay = inter_ping_delay_; int start_inter_ping_delay = inter_ping_delay_;
if (GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64 gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64
" dt=%lf bw=%lfMbs bw_est=%lfMbs", " dt=%lf bw=%lfMbs bw_est=%lfMbs",
name_, accumulator_, estimate_, dt, bw / 125000.0, name_, accumulator_, estimate_, dt, bw / 125000.0,
@ -54,7 +53,7 @@ grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) { if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) {
estimate_ = GPR_MAX(accumulator_, estimate_ * 2); estimate_ = GPR_MAX(accumulator_, estimate_ * 2);
bw_est_ = bw; bw_est_ = bw;
if (GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64, name_, gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64, name_,
estimate_); estimate_);
} }
@ -71,7 +70,7 @@ grpc_millis BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) {
} }
if (start_inter_ping_delay != inter_ping_delay_) { if (start_inter_ping_delay != inter_ping_delay_) {
stable_estimate_count_ = 0; stable_estimate_count_ = 0;
if (GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG, "bdp[%s]:update_inter_time to %dms", name_, gpr_log(GPR_DEBUG, "bdp[%s]:update_inter_time to %dms", name_,
inter_ping_delay_); inter_ping_delay_);
} }

@ -31,7 +31,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
extern grpc_tracer_flag grpc_bdp_estimator_trace; extern grpc_core::TraceFlag grpc_bdp_estimator_trace;
namespace grpc_core { namespace grpc_core {
@ -49,7 +49,7 @@ class BdpEstimator {
// grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a // grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a
// transport (but not necessarily started) // transport (but not necessarily started)
void SchedulePing() { void SchedulePing() {
if (GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64, name_, gpr_log(GPR_DEBUG, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64, name_,
accumulator_, estimate_); accumulator_, estimate_);
} }
@ -62,7 +62,7 @@ class BdpEstimator {
// once // once
// the ping is on the wire // the ping is on the wire
void StartPing() { void StartPing() {
if (GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { if (grpc_bdp_estimator_trace.enabled()) {
gpr_log(GPR_DEBUG, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64, name_, gpr_log(GPR_DEBUG, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64, name_,
accumulator_, estimate_); accumulator_, estimate_);
} }

@ -24,8 +24,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
grpc_tracer_flag grpc_connectivity_state_trace = grpc_core::TraceFlag grpc_connectivity_state_trace(false, "connectivity_state");
GRPC_TRACER_INITIALIZER(false, "connectivity_state");
const char *grpc_connectivity_state_name(grpc_connectivity_state state) { const char *grpc_connectivity_state_name(grpc_connectivity_state state) {
switch (state) { switch (state) {
@ -80,7 +79,7 @@ grpc_connectivity_state grpc_connectivity_state_check(
grpc_connectivity_state cur = grpc_connectivity_state cur =
(grpc_connectivity_state)gpr_atm_no_barrier_load( (grpc_connectivity_state)gpr_atm_no_barrier_load(
&tracker->current_state_atm); &tracker->current_state_atm);
if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { if (grpc_connectivity_state_trace.enabled()) {
gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
grpc_connectivity_state_name(cur)); grpc_connectivity_state_name(cur));
} }
@ -92,7 +91,7 @@ grpc_connectivity_state grpc_connectivity_state_get(
grpc_connectivity_state cur = grpc_connectivity_state cur =
(grpc_connectivity_state)gpr_atm_no_barrier_load( (grpc_connectivity_state)gpr_atm_no_barrier_load(
&tracker->current_state_atm); &tracker->current_state_atm);
if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { if (grpc_connectivity_state_trace.enabled()) {
gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
grpc_connectivity_state_name(cur)); grpc_connectivity_state_name(cur));
} }
@ -113,7 +112,7 @@ bool grpc_connectivity_state_notify_on_state_change(
grpc_connectivity_state cur = grpc_connectivity_state cur =
(grpc_connectivity_state)gpr_atm_no_barrier_load( (grpc_connectivity_state)gpr_atm_no_barrier_load(
&tracker->current_state_atm); &tracker->current_state_atm);
if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { if (grpc_connectivity_state_trace.enabled()) {
if (current == NULL) { if (current == NULL) {
gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker,
tracker->name, notify); tracker->name, notify);
@ -167,7 +166,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx,
(grpc_connectivity_state)gpr_atm_no_barrier_load( (grpc_connectivity_state)gpr_atm_no_barrier_load(
&tracker->current_state_atm); &tracker->current_state_atm);
grpc_connectivity_state_watcher *w; grpc_connectivity_state_watcher *w;
if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { if (grpc_connectivity_state_trace.enabled()) {
const char *error_string = grpc_error_string(error); const char *error_string = grpc_error_string(error);
gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker, gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker,
tracker->name, grpc_connectivity_state_name(cur), tracker->name, grpc_connectivity_state_name(cur),
@ -195,7 +194,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx,
while ((w = tracker->watchers) != NULL) { while ((w = tracker->watchers) != NULL) {
*w->current = state; *w->current = state;
tracker->watchers = w->next; tracker->watchers = w->next;
if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { if (grpc_connectivity_state_trace.enabled()) {
gpr_log(GPR_DEBUG, "NOTIFY: %p %s: %p", tracker, tracker->name, gpr_log(GPR_DEBUG, "NOTIFY: %p %s: %p", tracker, tracker->name,
w->notify); w->notify);
} }

@ -47,7 +47,7 @@ typedef struct {
char *name; char *name;
} grpc_connectivity_state_tracker; } grpc_connectivity_state_tracker;
extern grpc_tracer_flag grpc_connectivity_state_trace; extern grpc_core::TraceFlag grpc_connectivity_state_trace;
/** enum --> string conversion */ /** enum --> string conversion */
const char *grpc_connectivity_state_name(grpc_connectivity_state state); const char *grpc_connectivity_state_name(grpc_connectivity_state state);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save