diff options
Diffstat (limited to 'src/core/ext')
33 files changed, 179 insertions, 224 deletions
diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index d3627a237f..7eaf5d98cd 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -122,7 +122,7 @@ static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, gpr_mu_lock(&w->mu); 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_ERROR_UNREF(error); diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 8b8d512432..03c1b6f4bd 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -56,8 +56,7 @@ /* Client channel implementation */ -grpc_tracer_flag grpc_client_channel_trace = - GRPC_TRACER_INITIALIZER(false, "client_channel"); +grpc_core::TraceFlag grpc_client_channel_trace(false, "client_channel"); /************************************************************************* * METHOD-CONFIG TABLE @@ -248,7 +247,7 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, 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, grpc_connectivity_state_name(state)); } @@ -262,7 +261,7 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, grpc_connectivity_state publish_state = w->state; /* check if the notification is for the latest 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, w->lb_policy, grpc_connectivity_state_name(w->state)); } @@ -300,7 +299,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, 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_ASSERT(!chand->started_resolving); @@ -373,7 +372,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, void* arg, grpc_error* error) { 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, 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); chand->resolver_result = nullptr; } - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: resolver result: lb_policy_name=\"%s\"%s, " "service_config=\"%s\"", @@ -524,7 +523,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, if (new_lb_policy != nullptr || error != GRPC_ERROR_NONE || chand->resolver == nullptr) { if (chand->lb_policy != nullptr) { - 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, 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 // error or shutdown. if (error != GRPC_ERROR_NONE || chand->resolver == nullptr) { - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand); } if (chand->resolver != nullptr) { - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); } 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_CREATE_FROM_STATIC_STRING("No load balancing policy"); if (new_lb_policy != nullptr) { - 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); } GRPC_ERROR_UNREF(state_error); @@ -899,7 +898,7 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_error* error) { 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: failing %" PRIuPTR " pending batches: %s", elem->channel_data, calld, calld->waiting_for_pick_batches_count, @@ -942,7 +941,7 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_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 %" PRIuPTR " pending batches to subchannel_call=%p", @@ -969,7 +968,7 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_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", chand, calld); } @@ -1015,7 +1014,7 @@ static void create_subchannel_call_locked(grpc_exec_ctx* exec_ctx, grpc_error* new_error = grpc_connected_subchannel_create_call( exec_ctx, calld->connected_subchannel, &call_args, &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", chand, calld, calld->subchannel_call, grpc_error_string(new_error)); } @@ -1041,7 +1040,7 @@ static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, "Call dropped by load balancing policy") : GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed to create subchannel", &error, 1); - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: failed to create subchannel: error=%s", chand, calld, grpc_error_string(calld->error)); @@ -1075,7 +1074,7 @@ static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; if (calld->lb_policy != nullptr) { - 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", chand, calld, calld->lb_policy); } @@ -1093,7 +1092,7 @@ static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_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", chand, calld); } @@ -1110,7 +1109,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_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", chand, calld, chand->lb_policy); } @@ -1148,7 +1147,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, calld->subchannel_call_context, nullptr, &calld->lb_pick_closure); if (pick_done) { /* 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", chand, calld); } @@ -1193,7 +1192,7 @@ static void pick_after_resolver_result_cancel_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem = args->elem; channel_data* chand = (channel_data*)elem->channel_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: cancelling pick waiting for resolver result", chand, calld); @@ -1217,7 +1216,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, pick_after_resolver_result_args* args = (pick_after_resolver_result_args*)arg; if (args->finished) { /* 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_free(args); @@ -1228,13 +1227,13 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; 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", chand, calld); } async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } else if (chand->lb_policy != nullptr) { - 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", chand, calld); } @@ -1256,7 +1255,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, // right way to deal with it. else if (chand->resolver != nullptr) { // No LB policy, so try again. - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned but no LB policy, " "trying again", @@ -1264,7 +1263,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, } pick_after_resolver_result_start_locked(exec_ctx, elem); } else { - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver disconnected", chand, calld); } @@ -1277,7 +1276,7 @@ static void pick_after_resolver_result_start_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem) { channel_data* chand = (channel_data*)elem->channel_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: deferring pick pending resolver result", chand, calld); @@ -1362,7 +1361,7 @@ static void cc_start_transport_stream_op_batch( GPR_TIMER_BEGIN("cc_start_transport_stream_op_batch", 0); // If we've previously been cancelled, immediately fail any new batches. 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", chand, calld, grpc_error_string(calld->error)); } @@ -1378,7 +1377,7 @@ static void cc_start_transport_stream_op_batch( // error to the caller when the first batch does get passed down. GRPC_ERROR_UNREF(calld->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, calld, grpc_error_string(calld->error)); } @@ -1407,7 +1406,7 @@ static void cc_start_transport_stream_op_batch( // the channel combiner, which is more efficient (especially for // streaming calls). if (calld->subchannel_call != nullptr) { - if (GRPC_TRACER_ON(grpc_client_channel_trace)) { + if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, calld, calld->subchannel_call); @@ -1421,7 +1420,7 @@ static void cc_start_transport_stream_op_batch( // For batches containing a send_initial_metadata op, enter the channel // combiner to start a pick. 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", chand, calld); } @@ -1432,7 +1431,7 @@ static void cc_start_transport_stream_op_batch( GRPC_ERROR_NONE); } else { // 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, "chand=%p calld=%p: saved batch, yeilding call combiner", chand, calld); diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 9307842b5c..48e4637a82 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -23,7 +23,7 @@ #include "src/core/ext/filters/client_channel/resolver.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. #define GRPC_ARG_SERVER_URI "grpc.server_uri" diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 7b1e642bb8..7a5bb18157 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -78,10 +78,6 @@ void grpc_client_channel_init(void) { GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, (void*)&grpc_client_channel_filter); grpc_http_connect_register_handshaker_factory(); - grpc_register_tracer(&grpc_client_channel_trace); -#ifndef NDEBUG - grpc_register_tracer(&grpc_trace_resolver_refcount); -#endif } void grpc_client_channel_shutdown(void) { diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 387c26ed5c..6276c3e952 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -21,10 +21,8 @@ #define WEAK_REF_BITS 16 -#ifndef NDEBUG -grpc_tracer_flag grpc_trace_lb_policy_refcount = - GRPC_TRACER_INITIALIZER(false, "lb_policy_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount( + false, "lb_policy_refcount"); void grpc_lb_policy_init(grpc_lb_policy* policy, 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_no_barrier_fetch_add(&c->ref_pair, delta); #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, "LB_POLICY: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c, purpose, old_val, old_val + delta, reason); diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index ef42758f4c..72d027995a 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -29,9 +29,7 @@ typedef struct grpc_lb_policy grpc_lb_policy; typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable; typedef struct grpc_lb_policy_args grpc_lb_policy_args; -#ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_lb_policy_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_lb_policy_refcount; struct grpc_lb_policy { const grpc_lb_policy_vtable* vtable; diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 98f85ae52e..2f8e0c93b2 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -126,7 +126,7 @@ #define GRPC_GRPCLB_RECONNECT_JITTER 0.2 #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 * metadata */ @@ -217,7 +217,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, } else { 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, "[grpclb %p] Unreffing RR %p", wc_arg->glb_policy, wc_arg->rr_policy); } @@ -623,7 +623,7 @@ static void update_lb_connectivity_status_locked( 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_INFO, "[grpclb %p] Setting grpclb's state to %s from new RR policy %p state.", @@ -654,7 +654,7 @@ static bool pick_from_internal_rr_locked( } if (server->drop) { // 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, "[grpclb %p] Unreffing RR %p for drop", glb_policy, wc_arg->rr_policy); } @@ -684,7 +684,7 @@ static bool pick_from_internal_rr_locked( (void**)&wc_arg->lb_token, &wc_arg->wrapper_closure); if (pick_done) { /* 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, "[grpclb %p] Unreffing RR %p", glb_policy, wc_arg->rr_policy); } @@ -806,7 +806,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.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, "[grpclb %p] Pending pick about to (async) PICK from RR %p", glb_policy, glb_policy->rr_policy); @@ -821,7 +821,7 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, glb_policy->pending_pings = pping->next; GRPC_LB_POLICY_REF(glb_policy->rr_policy, "rr_handover_pending_ping"); 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, "[grpclb %p] Pending ping about to PING from RR %p", glb_policy, glb_policy->rr_policy); } @@ -837,14 +837,14 @@ static void rr_handover_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); GPR_ASSERT(args != nullptr); if (glb_policy->rr_policy != nullptr) { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Updating RR policy %p", glb_policy, glb_policy->rr_policy); } grpc_lb_policy_update_locked(exec_ctx, glb_policy->rr_policy, args); } else { 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, "[grpclb %p] Created new RR policy %p", glb_policy, glb_policy->rr_policy); } @@ -1186,7 +1186,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, // need to make sure we aren't trying to pick from a RR policy instance // that's in shutdown. if (rr_connectivity_state == GRPC_CHANNEL_SHUTDOWN) { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] NOT picking from from RR %p: RR conn state=%s", glb_policy, glb_policy->rr_policy, @@ -1196,7 +1196,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, on_complete); pick_done = false; } else { // RR not in shutdown - 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", glb_policy, glb_policy->rr_policy); } @@ -1221,7 +1221,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, false /* force_async */, target, wc_arg); } } else { // glb_policy->rr_policy == NULL - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] No RR policy. Adding to grpclb's pending picks", glb_policy); @@ -1272,7 +1272,7 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy->retry_timer_active = false; if (!glb_policy->shutting_down && glb_policy->lb_call == nullptr && error == GRPC_ERROR_NONE) { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", glb_policy); } query_for_backends_locked(exec_ctx, glb_policy); @@ -1293,7 +1293,7 @@ static void maybe_restart_lb_call(grpc_exec_ctx* exec_ctx, grpc_millis next_try = grpc_backoff_step(exec_ctx, &glb_policy->lb_call_backoff_state) .next_attempt_start_time; - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Connection to LB server lost...", glb_policy); grpc_millis timeout = next_try - grpc_exec_ctx_now(exec_ctx); @@ -1499,7 +1499,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, 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, "[grpclb %p] Query for backends (lb_channel: %p, lb_call: %p)", glb_policy, glb_policy->lb_channel, glb_policy->lb_call); @@ -1590,7 +1590,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy->client_stats_report_interval = GPR_MAX( GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( &response->client_stats_report_interval)); - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Received initial LB response message; " "client load reporting interval = %" PRIdPTR " milliseconds", @@ -1602,7 +1602,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy->client_load_report_timer_pending = true; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "client_load_report"); 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, "[grpclb %p] Received initial LB response message; client load " "reporting NOT enabled", @@ -1615,7 +1615,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_grpclb_response_parse_serverlist(response_slice); if (serverlist != nullptr) { GPR_ASSERT(glb_policy->lb_call != nullptr); - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Serverlist with %" PRIuPTR " servers received", glb_policy, serverlist->num_servers); @@ -1633,7 +1633,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, if (serverlist->num_servers > 0) { if (grpc_grpclb_serverlist_equals(glb_policy->serverlist, serverlist)) { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Incoming server list identical to current, " "ignoring.", @@ -1662,7 +1662,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, rr_handover_locked(exec_ctx, glb_policy); } } else { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Received empty server list, ignoring.", glb_policy); @@ -1710,7 +1710,7 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, * actually runs, don't fall back. */ if (glb_policy->serverlist == nullptr) { 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, "[grpclb %p] Falling back to use backends from resolver", glb_policy); @@ -1727,7 +1727,7 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; GPR_ASSERT(glb_policy->lb_call != nullptr); - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { char* status_details = grpc_slice_to_c_string(glb_policy->lb_call_status_details); gpr_log(GPR_INFO, @@ -1909,7 +1909,7 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, GPR_ASSERT(uri->path[0] != '\0'); glb_policy->server_name = 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, "[grpclb %p] Will use '%s' as the server name for LB request.", glb_policy, glb_policy->server_name); @@ -2003,10 +2003,6 @@ static bool maybe_add_client_load_reporting_filter( void grpc_lb_policy_grpclb_init() { grpc_register_lb_policy(grpc_glb_lb_factory_create()); - grpc_register_tracer(&grpc_lb_glb_trace); -#ifndef NDEBUG - grpc_register_tracer(&grpc_trace_lb_policy_refcount); -#endif grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, maybe_add_client_load_reporting_filter, diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 4e249207fa..6cfc37e9d1 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -29,8 +29,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -grpc_tracer_flag grpc_lb_pick_first_trace = - GRPC_TRACER_INITIALIZER(false, "pick_first"); +grpc_core::TraceFlag grpc_lb_pick_first_trace(false, "pick_first"); typedef struct pending_pick { struct pending_pick* next; @@ -66,14 +65,14 @@ static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); gpr_free(p); grpc_subchannel_index_unref(); - 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); } } static void shutdown_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p, grpc_error* error) { - if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { + if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down", p); } p->shutdown = true; @@ -261,7 +260,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, } const grpc_lb_addresses* addresses = (const grpc_lb_addresses*)arg->value.pointer.p; - 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", (void*)p, (unsigned long)addresses->num_addresses); } @@ -298,7 +297,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_lb_subchannel_data* sd = &subchannel_list->subchannels[i]; if (sd->subchannel == p->selected->subchannel) { // 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, "Pick First %p found already selected subchannel %p " "at update index %" PRIuPTR " of %" PRIuPTR "; update done", @@ -336,7 +335,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // for it to report READY before swapping it into the current // subchannel list. if (p->latest_pending_subchannel_list != nullptr) { - if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { + if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down latest pending subchannel list " "%p, about to be replaced by newer latest %p", @@ -363,7 +362,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; pick_first_lb_policy* p = (pick_first_lb_policy*)sd->subchannel_list->policy; - if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { + if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p connectivity changed for subchannel %p (%" PRIuPTR " of %" PRIuPTR @@ -460,7 +459,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_subchannel_get_connected_subchannel(sd->subchannel), "connected"); p->selected = sd; - if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { + if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", (void*)p, (void*)sd->subchannel); } @@ -472,7 +471,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, p->pending_picks = pp->next; *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF( p->selected->connected_subchannel, "picked"); - if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { + if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_INFO, "Servicing pending pick with selected subchannel %p", (void*)p->selected); @@ -571,7 +570,7 @@ static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, grpc_lb_policy_args* args) { GPR_ASSERT(args->client_channel_factory != nullptr); 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); } pf_update_locked(exec_ctx, &p->base, args); @@ -595,7 +594,6 @@ static grpc_lb_policy_factory* pick_first_lb_factory_create() { void grpc_lb_policy_pick_first_init() { grpc_register_lb_policy(pick_first_lb_factory_create()); - grpc_register_tracer(&grpc_lb_pick_first_trace); } void grpc_lb_policy_pick_first_shutdown() {} diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 359aa0e825..23a4cc4a5a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -39,8 +39,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" -grpc_tracer_flag grpc_lb_round_robin_trace = - GRPC_TRACER_INITIALIZER(false, "round_robin"); +grpc_core::TraceFlag grpc_lb_round_robin_trace(false, "round_robin"); /** List of entities waiting for a pick. * @@ -101,7 +100,7 @@ typedef struct round_robin_lb_policy { static size_t get_next_ready_subchannel_index_locked( const round_robin_lb_policy* p) { GPR_ASSERT(p->subchannel_list != nullptr); - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " "last_ready_subchannel_index=%lu", @@ -111,7 +110,7 @@ static size_t get_next_ready_subchannel_index_locked( for (size_t i = 0; i < p->subchannel_list->num_subchannels; ++i) { const size_t index = (i + p->last_ready_subchannel_index + 1) % p->subchannel_list->num_subchannels; - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log( GPR_DEBUG, "[RR %p] checking subchannel %p, subchannel_list %p, index %lu: " @@ -123,7 +122,7 @@ static size_t get_next_ready_subchannel_index_locked( } if (p->subchannel_list->subchannels[index].curr_connectivity_state == GRPC_CHANNEL_READY) { - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] found next ready subchannel (%p) at index %lu of " "subchannel_list %p", @@ -134,7 +133,7 @@ static size_t get_next_ready_subchannel_index_locked( 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); } return p->subchannel_list->num_subchannels; @@ -145,7 +144,7 @@ static void update_last_ready_subchannel_index_locked(round_robin_lb_policy* p, size_t last_ready_index) { GPR_ASSERT(last_ready_index < p->subchannel_list->num_subchannels); 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_DEBUG, "[RR %p] setting last_ready_subchannel_index=%lu (SC %p, CSC %p)", (void*)p, (unsigned long)last_ready_index, @@ -157,7 +156,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) { 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", (void*)pol, (void*)pol); } @@ -170,7 +169,7 @@ static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { static void shutdown_locked(grpc_exec_ctx* exec_ctx, round_robin_lb_policy* p, grpc_error* error) { - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down", p); } p->shutdown = true; @@ -276,7 +275,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { 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_INFO, "[RR %p] Trying to pick (shutdown: %d)", (void*)pol, p->shutdown); } @@ -292,7 +291,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, if (user_data != nullptr) { *user_data = sd->user_data; } - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log( GPR_DEBUG, "[RR %p] Picked target <-- Subchannel %p (connected %p) (sl %p, " @@ -393,7 +392,7 @@ static grpc_connectivity_state update_lb_connectivity_status_locked( "rr_shutdown"); p->shutdown = true; new_state = GRPC_CHANNEL_SHUTDOWN; - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_INFO, "[RR %p] Shutting down: all subchannels have gone into shutdown", (void*)p); @@ -419,7 +418,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_lb_subchannel_data* sd = (grpc_lb_subchannel_data*)arg; round_robin_lb_policy* p = (round_robin_lb_policy*)sd->subchannel_list->policy; - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log( GPR_DEBUG, "[RR %p] connectivity changed for subchannel %p, subchannel_list %p: " @@ -484,7 +483,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // for sds belonging to outdated subchannel lists. GPR_ASSERT(sd->subchannel_list == p->latest_pending_subchannel_list); 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 = p->subchannel_list != nullptr ? (unsigned long)p->subchannel_list->num_subchannels @@ -523,7 +522,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, if (pp->user_data != nullptr) { *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, "[RR %p] Fulfilling pending pick. Target <-- subchannel %p " "(subchannel_list %p, index %lu)", @@ -590,7 +589,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, return; } grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] received update with %" PRIuPTR " addresses", p, addresses->num_addresses); } @@ -611,7 +610,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, } if (p->started_picking) { if (p->latest_pending_subchannel_list != nullptr) { - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down latest pending subchannel list %p, " "about to be replaced by newer latest %p", @@ -669,7 +668,7 @@ static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, "round_robin"); 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, (unsigned long)p->subchannel_list->num_subchannels); } @@ -691,7 +690,6 @@ static grpc_lb_policy_factory* round_robin_lb_factory_create() { void grpc_lb_policy_round_robin_init() { grpc_register_lb_policy(round_robin_lb_factory_create()); - grpc_register_tracer(&grpc_lb_round_robin_trace); } void grpc_lb_policy_round_robin_shutdown() {} diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index 27d9598ac4..b6fce4d207 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -32,11 +32,11 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { if (sd->subchannel != nullptr) { - if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { + if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR " (subchannel %p): unreffing subchannel", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); @@ -58,11 +58,11 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, void grpc_lb_subchannel_data_start_connectivity_watch( grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { - if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { + if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR " (subchannel %p): requesting connectivity change notification", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); @@ -76,11 +76,11 @@ void grpc_lb_subchannel_data_start_connectivity_watch( void grpc_lb_subchannel_data_stop_connectivity_watch( grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd) { - if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { + if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR " (subchannel %p): stopping connectivity watch", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel); @@ -90,15 +90,15 @@ void grpc_lb_subchannel_data_stop_connectivity_watch( } grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_tracer_flag* tracer, + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb) { grpc_lb_subchannel_list* subchannel_list = (grpc_lb_subchannel_list*)gpr_zalloc(sizeof(*subchannel_list)); - if (GRPC_TRACER_ON(*tracer)) { + if (tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Creating subchannel list %p for %" PRIuPTR " subchannels", - tracer->name, p, subchannel_list, addresses->num_addresses); + tracer->name(), p, subchannel_list, addresses->num_addresses); } subchannel_list->policy = p; subchannel_list->tracer = tracer; @@ -128,24 +128,24 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( grpc_channel_args_destroy(exec_ctx, new_args); if (subchannel == nullptr) { // Subchannel could not be created. - if (GRPC_TRACER_ON(*tracer)) { + if (tracer->enabled()) { char* address_uri = grpc_sockaddr_to_uri(&addresses->addresses[i].address); gpr_log(GPR_DEBUG, "[%s %p] could not create subchannel for address uri %s, " "ignoring", - tracer->name, subchannel_list->policy, address_uri); + tracer->name(), subchannel_list->policy, address_uri); gpr_free(address_uri); } continue; } - if (GRPC_TRACER_ON(*tracer)) { + if (tracer->enabled()) { char* address_uri = grpc_sockaddr_to_uri(&addresses->addresses[i].address); gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR ": Created subchannel %p for address uri %s", - tracer->name, p, subchannel_list, subchannel_index, subchannel, + tracer->name(), p, subchannel_list, subchannel_index, subchannel, address_uri); gpr_free(address_uri); } @@ -174,9 +174,9 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list) { - if (GRPC_TRACER_ON(*subchannel_list->tracer)) { + if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Destroying subchannel_list %p", - subchannel_list->tracer->name, subchannel_list->policy, + subchannel_list->tracer->name(), subchannel_list->policy, subchannel_list); } for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { @@ -191,10 +191,10 @@ static void subchannel_list_destroy(grpc_exec_ctx* exec_ctx, void grpc_lb_subchannel_list_ref(grpc_lb_subchannel_list* subchannel_list, const char* reason) { gpr_ref_non_zero(&subchannel_list->refcount); - if (GRPC_TRACER_ON(*subchannel_list->tracer)) { + if (subchannel_list->tracer->enabled()) { const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p REF %lu->%lu (%s)", - subchannel_list->tracer->name, subchannel_list->policy, + subchannel_list->tracer->name(), subchannel_list->policy, subchannel_list, (unsigned long)(count - 1), (unsigned long)count, reason); } @@ -204,10 +204,10 @@ void grpc_lb_subchannel_list_unref(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, const char* reason) { const bool done = gpr_unref(&subchannel_list->refcount); - if (GRPC_TRACER_ON(*subchannel_list->tracer)) { + if (subchannel_list->tracer->enabled()) { const gpr_atm count = gpr_atm_acq_load(&subchannel_list->refcount.count); gpr_log(GPR_DEBUG, "[%s %p] subchannel_list %p UNREF %lu->%lu (%s)", - subchannel_list->tracer->name, subchannel_list->policy, + subchannel_list->tracer->name(), subchannel_list->policy, subchannel_list, (unsigned long)(count + 1), (unsigned long)count, reason); } @@ -231,11 +231,11 @@ void grpc_lb_subchannel_list_unref_for_connectivity_watch( static void subchannel_data_cancel_connectivity_watch( grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { - if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { + if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR " (subchannel %p): canceling connectivity watch (%s)", - sd->subchannel_list->tracer->name, sd->subchannel_list->policy, + sd->subchannel_list->tracer->name(), sd->subchannel_list->policy, sd->subchannel_list, (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); @@ -248,9 +248,9 @@ static void subchannel_data_cancel_connectivity_watch( void grpc_lb_subchannel_list_shutdown_and_unref( grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_list* subchannel_list, const char* reason) { - if (GRPC_TRACER_ON(*subchannel_list->tracer)) { + if (subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] Shutting down subchannel_list %p (%s)", - subchannel_list->tracer->name, subchannel_list->policy, + subchannel_list->tracer->name(), subchannel_list->policy, subchannel_list, reason); } GPR_ASSERT(!subchannel_list->shutting_down); diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index ef3102934c..e3e5eba56a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -84,7 +84,7 @@ struct grpc_lb_subchannel_list { /** backpointer to owning policy */ grpc_lb_policy* policy; - grpc_tracer_flag* tracer; + grpc_core::TraceFlag* tracer; /** all our subchannels */ size_t num_subchannels; @@ -117,7 +117,7 @@ struct grpc_lb_subchannel_list { }; grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( - grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_tracer_flag* tracer, + grpc_exec_ctx* exec_ctx, grpc_lb_policy* p, grpc_core::TraceFlag* tracer, const grpc_lb_addresses* addresses, const grpc_lb_policy_args* args, grpc_iomgr_cb_func connectivity_changed_cb); diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 7e84b98cb9..c16b1515c7 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -19,10 +19,8 @@ #include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/lib/iomgr/combiner.h" -#ifndef NDEBUG -grpc_tracer_flag grpc_trace_resolver_refcount = - GRPC_TRACER_INITIALIZER(false, "resolver_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false, + "resolver_refcount"); void grpc_resolver_init(grpc_resolver* resolver, const grpc_resolver_vtable* vtable, @@ -35,7 +33,7 @@ void grpc_resolver_init(grpc_resolver* resolver, #ifndef NDEBUG void grpc_resolver_ref(grpc_resolver* resolver, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", resolver, @@ -50,7 +48,7 @@ void grpc_resolver_ref(grpc_resolver* resolver) { #ifndef NDEBUG void grpc_resolver_unref(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "RESOLVER:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", resolver, diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index c0901f0225..4e8cfbe417 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -25,9 +25,7 @@ typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver_vtable grpc_resolver_vtable; -#ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_resolver_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount; /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ struct grpc_resolver { diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 2720e68040..58e294d597 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -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_no_barrier_fetch_add(&c->ref_pair, delta); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { + if (grpc_trace_stream_refcount.enabled()) { gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SUBCHANNEL: %p %12s 0x%" PRIxPTR " -> 0x%" PRIxPTR " [%s]", c, purpose, old_val, old_val + delta, reason); diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 61d73edfc0..483eb021e8 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -65,7 +65,6 @@ static bool maybe_add_required_filter(grpc_exec_ctx* exec_ctx, } void grpc_http_filters_init(void) { - grpc_register_tracer(&grpc_compression_trace); grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, maybe_add_optional_filter, &compress_filter); diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index 8d95133d8f..d070b56b6a 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -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, &calld->slices, &tmp); if (did_compress) { - if (GRPC_TRACER_ON(grpc_compression_trace)) { + if (grpc_compression_trace.enabled()) { const char* algo_name; const size_t before_size = calld->slices.length; const size_t after_size = tmp.length; @@ -258,7 +258,7 @@ static void finish_send_message(grpc_exec_ctx* exec_ctx, grpc_slice_buffer_swap(&calld->slices, &tmp); send_flags |= GRPC_WRITE_INTERNAL_COMPRESS; } else { - if (GRPC_TRACER_ON(grpc_compression_trace)) { + if (grpc_compression_trace.enabled()) { const char* algo_name; GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm, &algo_name)); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc index 6d09953830..97c1878f34 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc @@ -20,13 +20,6 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/metadata.h" -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 - grpc_register_tracer(&grpc_trace_chttp2_refcount); -#endif -} +void grpc_chttp2_plugin_init(void) {} void grpc_chttp2_plugin_shutdown(void) {} diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 43788bfc5c..5bd647885f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -90,13 +90,9 @@ static int g_default_max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA; static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; #define MAX_CLIENT_STREAM_ID 0x7fffffffu -grpc_tracer_flag grpc_http_trace = GRPC_TRACER_INITIALIZER(false, "http"); -grpc_tracer_flag grpc_flowctl_trace = GRPC_TRACER_INITIALIZER(false, "flowctl"); - -#ifndef NDEBUG -grpc_tracer_flag grpc_trace_chttp2_refcount = - GRPC_TRACER_INITIALIZER(false, "chttp2_refcount"); -#endif +grpc_core::TraceFlag grpc_http_trace(false, "http"); +grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, + "chttp2_refcount"); /* forward declarations of various callbacks that we'll build closures around */ static void write_action_begin_locked(grpc_exec_ctx* exec_ctx, void* t, @@ -235,7 +231,7 @@ static void destruct_transport(grpc_exec_ctx* exec_ctx, void grpc_chttp2_unref_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, const char* reason, 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_log(GPR_DEBUG, "chttp2:unref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", t, val, val - 1, reason, file, line); @@ -246,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, 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_log(GPR_DEBUG, "chttp2: ref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", t, val, val + 1, reason, file, line); @@ -1237,7 +1233,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, return; } 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); gpr_log( GPR_DEBUG, @@ -1396,7 +1392,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, 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); gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str, op->on_complete); @@ -1686,7 +1682,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); gpr_log(GPR_DEBUG, "perform_stream_op[s=%p]: %s", s, str); gpr_free(str); @@ -2594,7 +2590,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, grpc_error* error) { 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, grpc_error_string(error)); } @@ -2608,7 +2604,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, grpc_error* error) { 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, grpc_error_string(error)); } @@ -3109,7 +3105,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_chttp2_stream_map_size(&t->stream_map) == 0) { /* Channel with no active streams: send a goaway to try and make it * 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", t->peer_string); } @@ -3117,8 +3113,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); - } else if (error == GRPC_ERROR_NONE && - GRPC_TRACER_ON(grpc_resource_quota_trace)) { + } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR " streams", @@ -3140,7 +3135,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx* exec_ctx, void* arg, if (error == GRPC_ERROR_NONE && n > 0) { grpc_chttp2_stream* s = (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, s->id); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index e068987040..369dc34228 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -23,13 +23,9 @@ #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/transport/transport.h" -extern grpc_tracer_flag grpc_http_trace; -extern grpc_tracer_flag grpc_flowctl_trace; -extern grpc_tracer_flag grpc_trace_http2_stream_state; - -#ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_chttp2_refcount; -#endif +extern grpc_core::TraceFlag grpc_http_trace; +extern grpc_core::TraceFlag grpc_trace_http2_stream_state; +extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount; grpc_transport* grpc_create_chttp2_transport( grpc_exec_ctx* exec_ctx, const grpc_channel_args* channel_args, diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index b4e3118043..8a057bd9ff 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.cc +++ b/src/core/ext/transport/chttp2/transport/flow_control.cc @@ -31,6 +31,8 @@ #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/lib/support/string.h" +grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl"); + namespace grpc_core { namespace chttp2 { diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 46d00a1032..bb710fef83 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -30,7 +30,7 @@ struct grpc_chttp2_transport; struct grpc_chttp2_stream; -extern grpc_tracer_flag grpc_flowctl_trace; +extern grpc_core::TraceFlag grpc_flowctl_trace; namespace grpc { namespace testing { @@ -118,7 +118,7 @@ class FlowControlTrace { StreamFlowControl* sfc); void Finish(); - const bool enabled_ = GRPC_TRACER_ON(grpc_flowctl_trace); + const bool enabled_ = grpc_flowctl_trace.enabled(); TransportFlowControl* tfc_; StreamFlowControl* sfc_; diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index d33da721a5..75bb78db4c 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -204,20 +204,19 @@ grpc_error* grpc_chttp2_settings_parser_parse(grpc_exec_ctx* exec_ctx, void* p, parser->incoming_settings[id] != parser->value) { t->initial_window_update += (int64_t)parser->value - parser->incoming_settings[id]; - if (GRPC_TRACER_ON(grpc_http_trace) || - GRPC_TRACER_ON(grpc_flowctl_trace)) { + if (grpc_http_trace.enabled() || grpc_flowctl_trace.enabled()) { gpr_log(GPR_DEBUG, "%p[%s] adding %d for initial_window change", t, t->is_client ? "cli" : "svr", (int)t->initial_window_update); } } 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", t->is_client ? "CLI" : "SVR", t->peer_string, sp->name, 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)", parser->id, parser->value); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index e6e4ff24a3..e76d92e31d 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -57,8 +57,6 @@ static const grpc_slice terminal_slice = { {{nullptr, 0}} /* data.refcounted */ }; -extern "C" grpc_tracer_flag grpc_http_trace; - typedef struct { int is_first_frame; /* number of bytes in 'output' when we started the frame - used to calculate @@ -475,7 +473,7 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, "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* v = nullptr; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { @@ -669,7 +667,7 @@ void grpc_chttp2_hpack_compressor_set_max_table_size( } } 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); } } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 046e0b81cd..08921b19ec 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -34,6 +34,8 @@ /* maximum table size we'll actually use */ #define GRPC_CHTTP2_HPACKC_MAX_TABLE_SIZE (1024 * 1024) +extern grpc_core::TraceFlag grpc_http_trace; + typedef struct { uint32_t filter_elems_sum; uint32_t max_table_size; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 960610eee0..18cb27f199 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -651,7 +651,7 @@ static const uint8_t inverse_base64[256] = { /* emission helpers */ static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, grpc_mdelem md, int add_to_table) { - if (GRPC_TRACER_ON(grpc_http_trace)) { + if (grpc_http_trace.enabled()) { char* k = grpc_slice_to_c_string(GRPC_MDKEY(md)); char* v = nullptr; if (grpc_is_binary_header(GRPC_MDKEY(md))) { @@ -1047,7 +1047,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, grpc_chttp2_hpack_parser* p, 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); } grpc_error* err = diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 7970d2ae27..75b83b80b6 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -28,7 +28,7 @@ #include "src/core/lib/debug/trace.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 { 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) { 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); } 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); 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); } while (tbl->mem_used > bytes) { diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index eec98b78ef..9404213e5c 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -670,13 +670,13 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) -extern grpc_tracer_flag grpc_http_trace; -extern grpc_tracer_flag grpc_flowctl_trace; +// extern grpc_core::TraceFlag grpc_http_trace; +// extern grpc_core::TraceFlag grpc_flowctl_trace; -#define GRPC_CHTTP2_IF_TRACING(stmt) \ - if (!(GRPC_TRACER_ON(grpc_http_trace))) \ - ; \ - else \ +#define GRPC_CHTTP2_IF_TRACING(stmt) \ + if (!(grpc_http_trace.enabled())) \ + ; \ + else \ stmt void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 5f07dec8e8..46ec3fbaa6 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -312,7 +312,7 @@ static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, case GRPC_CHTTP2_FRAME_GOAWAY: return init_goaway_parser(exec_ctx, t); 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); } return init_skip_frame_parser(exec_ctx, t, 0); @@ -417,7 +417,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_ASSERT(s != nullptr); - if (GRPC_TRACER_ON(grpc_http_trace)) { + if (grpc_http_trace.enabled()) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char* value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -501,7 +501,7 @@ static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_ASSERT(s != nullptr); - if (GRPC_TRACER_ON(grpc_http_trace)) { + if (grpc_http_trace.enabled()) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char* value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -758,7 +758,7 @@ static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, if (err == GRPC_ERROR_NONE) { return err; } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { - if (GRPC_TRACER_ON(grpc_http_trace)) { + if (grpc_http_trace.enabled()) { const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); } diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index d92527f05c..c95d02541a 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -39,8 +39,7 @@ static const char* stream_list_id_string(grpc_chttp2_stream_list_id id) { GPR_UNREACHABLE_CODE(return "unknown"); } -grpc_tracer_flag grpc_trace_http2_stream_state = - GRPC_TRACER_INITIALIZER(false, "http2_stream_state"); +grpc_core::TraceFlag grpc_trace_http2_stream_state(false, "http2_stream_state"); /* core list management */ @@ -66,7 +65,7 @@ static bool stream_list_pop(grpc_chttp2_transport* t, s->included[id] = 0; } *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, 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 { 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, 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; 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, t->is_client ? "cli" : "svr", stream_list_id_string(id)); } diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index c36b4bd828..15869b8880 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -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])) { /* ping already in-flight: wait */ - if (GRPC_TRACER_ON(grpc_http_trace) || - GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { + if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: already pinging", 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 && t->ping_policy.max_pings_without_data != 0) { /* need to receive something of substance before sending a ping again */ - if (GRPC_TRACER_ON(grpc_http_trace) || - GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { + if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: too many recent pings: %d/%d", t->is_client ? "CLIENT" : "SERVER", t->peer_string, 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) { /* not enough elapsed time between successive pings */ - if (GRPC_TRACER_ON(grpc_http_trace) || - GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { + if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping delayed [%p]: not enough time elapsed since last ping", 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_STATS_INC_HTTP2_PINGS_SENT(exec_ctx); t->ping_state.last_ping_sent_time = now; - if (GRPC_TRACER_ON(grpc_http_trace) || - GRPC_TRACER_ON(grpc_bdp_estimator_trace)) { + if (grpc_http_trace.enabled() || grpc_bdp_estimator_trace.enabled()) { gpr_log(GPR_DEBUG, "%s: Ping sent [%p]: %d/%d", t->is_client ? "CLIENT" : "SERVER", t->peer_string, t->ping_state.pings_before_data_required, diff --git a/src/core/ext/transport/inproc/inproc_plugin.cc b/src/core/ext/transport/inproc/inproc_plugin.cc index 6a796a0b19..83a7d8d52f 100644 --- a/src/core/ext/transport/inproc/inproc_plugin.cc +++ b/src/core/ext/transport/inproc/inproc_plugin.cc @@ -19,11 +19,8 @@ #include "src/core/ext/transport/inproc/inproc_transport.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"); -void grpc_inproc_plugin_init(void) { - grpc_register_tracer(&grpc_inproc_trace); - grpc_inproc_transport_init(); -} +void grpc_inproc_plugin_init(void) { grpc_inproc_transport_init(); } void grpc_inproc_plugin_shutdown(void) { grpc_inproc_transport_shutdown(); } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 7ea08b05bb..2579060811 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -32,9 +32,9 @@ #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/transport_impl.h" -#define INPROC_LOG(...) \ - do { \ - if (GRPC_TRACER_ON(grpc_inproc_trace)) gpr_log(__VA_ARGS__); \ +#define INPROC_LOG(...) \ + do { \ + if (grpc_inproc_trace.enabled()) gpr_log(__VA_ARGS__); \ } while (0) 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, uint32_t flags, grpc_metadata_batch* out_md, 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 != nullptr); } @@ -873,7 +873,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_lock(mu); - if (GRPC_TRACER_ON(grpc_inproc_trace)) { + if (grpc_inproc_trace.enabled()) { if (op->send_initial_metadata) { log_metadata(op->payload->send_initial_metadata.send_initial_metadata, s->t->is_client, true); diff --git a/src/core/ext/transport/inproc/inproc_transport.h b/src/core/ext/transport/inproc/inproc_transport.h index b532b8a234..7c0453e7ce 100644 --- a/src/core/ext/transport/inproc/inproc_transport.h +++ b/src/core/ext/transport/inproc/inproc_transport.h @@ -25,7 +25,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, grpc_channel_args* args, 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_shutdown(void); |