From 6014e8a945fa81fad7d0311a8a7cded0c2aaa827 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 16 Oct 2017 13:50:29 -0700 Subject: [PATCH 01/27] C++ize tracing --- .../client_channel/channel_connectivity.cc | 2 +- .../filters/client_channel/client_channel.cc | 60 +++++----- .../filters/client_channel/client_channel.h | 2 +- .../client_channel/client_channel_plugin.cc | 4 +- .../ext/filters/client_channel/lb_policy.cc | 6 +- .../ext/filters/client_channel/lb_policy.h | 2 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 48 ++++---- .../lb_policy/pick_first/pick_first.cc | 32 ++--- .../lb_policy/round_robin/round_robin.cc | 48 ++++---- .../ext/filters/client_channel/resolver.cc | 8 +- .../ext/filters/client_channel/resolver.h | 2 +- .../ext/filters/client_channel/subchannel.cc | 2 +- .../ext/filters/http/http_filters_plugin.cc | 2 +- .../message_compress_filter.cc | 4 +- .../chttp2/transport/chttp2_plugin.cc | 8 +- .../chttp2/transport/chttp2_transport.cc | 28 ++--- .../chttp2/transport/chttp2_transport.h | 8 +- .../chttp2/transport/frame_settings.cc | 8 +- .../chttp2/transport/hpack_encoder.cc | 6 +- .../chttp2/transport/hpack_parser.cc | 4 +- .../transport/chttp2/transport/hpack_table.cc | 6 +- .../ext/transport/chttp2/transport/internal.h | 8 +- .../ext/transport/chttp2/transport/parsing.cc | 8 +- .../chttp2/transport/stream_lists.cc | 10 +- .../ext/transport/chttp2/transport/writing.cc | 16 +-- .../ext/transport/inproc/inproc_plugin.cc | 7 +- .../ext/transport/inproc/inproc_transport.cc | 6 +- .../ext/transport/inproc/inproc_transport.h | 2 +- src/core/lib/channel/channel_stack.cc | 2 +- src/core/lib/channel/channel_stack.h | 4 +- src/core/lib/channel/channel_stack_builder.cc | 4 +- src/core/lib/channel/channel_stack_builder.h | 2 +- src/core/lib/debug/trace.cc | 111 ++++++++---------- src/core/lib/debug/trace.h | 58 ++++++--- src/core/lib/http/parser.cc | 4 +- src/core/lib/http/parser.h | 2 +- src/core/lib/iomgr/call_combiner.cc | 32 ++--- src/core/lib/iomgr/call_combiner.h | 2 +- src/core/lib/iomgr/closure.cc | 2 +- src/core/lib/iomgr/closure.h | 2 +- src/core/lib/iomgr/combiner.cc | 8 +- src/core/lib/iomgr/combiner.h | 2 +- src/core/lib/iomgr/error.cc | 14 +-- src/core/lib/iomgr/error.h | 2 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 52 ++++---- src/core/lib/iomgr/ev_epollex_linux.cc | 52 ++++---- src/core/lib/iomgr/ev_epollsig_linux.cc | 10 +- src/core/lib/iomgr/ev_poll_posix.cc | 10 +- src/core/lib/iomgr/ev_posix.cc | 10 +- src/core/lib/iomgr/ev_posix.h | 2 +- src/core/lib/iomgr/ev_windows.cc | 4 +- src/core/lib/iomgr/exec_ctx.cc | 4 +- src/core/lib/iomgr/executor.cc | 18 +-- src/core/lib/iomgr/iomgr_posix.cc | 2 +- src/core/lib/iomgr/iomgr_uv.cc | 2 +- src/core/lib/iomgr/lockfree_event.cc | 8 +- src/core/lib/iomgr/pollset.h | 2 +- src/core/lib/iomgr/pollset_uv.cc | 4 +- src/core/lib/iomgr/pollset_windows.cc | 4 +- src/core/lib/iomgr/resource_quota.cc | 22 ++-- src/core/lib/iomgr/resource_quota.h | 2 +- src/core/lib/iomgr/tcp_client_posix.cc | 8 +- src/core/lib/iomgr/tcp_client_uv.cc | 6 +- src/core/lib/iomgr/tcp_posix.cc | 50 ++++---- src/core/lib/iomgr/tcp_posix.h | 2 +- src/core/lib/iomgr/tcp_server_posix.cc | 2 +- src/core/lib/iomgr/tcp_server_uv.cc | 8 +- src/core/lib/iomgr/tcp_uv.cc | 18 +-- src/core/lib/iomgr/tcp_uv.h | 2 +- src/core/lib/iomgr/tcp_windows.cc | 6 +- src/core/lib/iomgr/timer_generic.cc | 40 +++---- src/core/lib/iomgr/timer_manager.cc | 25 ++-- src/core/lib/iomgr/timer_uv.cc | 6 +- .../lib/security/context/security_context.cc | 8 +- .../lib/security/context/security_context.h | 2 +- .../credentials/jwt/jwt_credentials.cc | 2 +- .../credentials/oauth2/oauth2_credentials.cc | 2 +- .../credentials/plugin/plugin_credentials.cc | 18 +-- .../credentials/plugin/plugin_credentials.h | 2 +- .../lib/security/transport/secure_endpoint.cc | 12 +- .../lib/security/transport/secure_endpoint.h | 2 +- .../security/transport/security_connector.cc | 8 +- .../security/transport/security_connector.h | 2 +- src/core/lib/surface/alarm.cc | 10 +- src/core/lib/surface/alarm_internal.h | 2 +- src/core/lib/surface/api_trace.cc | 2 +- src/core/lib/surface/api_trace.h | 4 +- src/core/lib/surface/call.cc | 16 +-- src/core/lib/surface/call.h | 6 +- src/core/lib/surface/completion_queue.cc | 44 +++---- src/core/lib/surface/completion_queue.h | 10 +- src/core/lib/surface/init.cc | 44 +++---- src/core/lib/surface/init_secure.cc | 10 +- src/core/lib/surface/server.cc | 6 +- src/core/lib/surface/server.h | 2 +- src/core/lib/transport/bdp_estimator.cc | 10 +- src/core/lib/transport/bdp_estimator.h | 6 +- src/core/lib/transport/connectivity_state.cc | 14 +-- src/core/lib/transport/connectivity_state.h | 2 +- src/core/lib/transport/metadata.cc | 18 +-- src/core/lib/transport/metadata.h | 2 +- src/core/lib/transport/transport.cc | 8 +- src/core/lib/transport/transport.h | 2 +- src/core/tsi/fake_transport_security.cc | 8 +- src/core/tsi/ssl_transport_security.cc | 2 +- src/core/tsi/transport_security.cc | 2 +- src/core/tsi/transport_security.h | 2 +- src/core/tsi/transport_security_interface.h | 2 +- test/core/iomgr/timer_list_test.c | 4 +- 109 files changed, 641 insertions(+), 634 deletions(-) diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 31a8fc39ce6..d5c8f121a92 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 22c2bc88804..21ad3d9a260 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -55,8 +55,8 @@ /* Client channel implementation */ -grpc_tracer_flag grpc_client_channel_trace = - GRPC_TRACER_INITIALIZER(false, "client_channel"); +grpc_core::Tracer grpc_client_channel_trace + (false, "client_channel"); /************************************************************************* * METHOD-CONFIG TABLE @@ -250,7 +250,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)); } @@ -264,7 +264,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)); } @@ -301,7 +301,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); @@ -374,7 +374,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 +483,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 = NULL; } - 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 +524,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx *exec_ctx, if (new_lb_policy != NULL || error != GRPC_ERROR_NONE || chand->resolver == 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, chand->lb_policy); } @@ -538,11 +538,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 == NULL) { - 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 != 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); } grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); @@ -565,7 +565,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 != 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); } GRPC_ERROR_UNREF(state_error); @@ -896,7 +896,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 %" PRIdPTR " pending batches: %s", elem->channel_data, calld, calld->waiting_for_pick_batches_count, @@ -939,7 +939,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 %" PRIdPTR " pending batches to subchannel_call=%p", chand, calld, calld->waiting_for_pick_batches_count, @@ -965,7 +965,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); } @@ -1011,7 +1011,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)); } @@ -1037,7 +1037,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)); @@ -1071,7 +1071,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 != 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", chand, calld, calld->lb_policy); } @@ -1089,7 +1089,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); } @@ -1106,7 +1106,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); } @@ -1144,7 +1144,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx *exec_ctx, calld->subchannel_call_context, NULL, &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); } @@ -1190,7 +1190,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); @@ -1212,7 +1212,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx *exec_ctx, (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); @@ -1223,13 +1223,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 (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); } @@ -1248,7 +1248,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); @@ -1333,7 +1333,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)); } @@ -1349,7 +1349,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)); } @@ -1378,7 +1378,7 @@ static void cc_start_transport_stream_op_batch( // the channel combiner, which is more efficient (especially for // streaming calls). if (calld->subchannel_call != NULL) { - 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); @@ -1392,7 +1392,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); } @@ -1403,7 +1403,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 152fe2365af..b5d095fe5f4 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::Tracer 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 4431d115198..d67e11e9769 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -78,9 +78,9 @@ extern "C" 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 } diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 8e6673d737e..6ce49b17e9e 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -22,8 +22,8 @@ #define WEAK_REF_BITS 16 #ifndef NDEBUG -grpc_tracer_flag grpc_trace_lb_policy_refcount = - GRPC_TRACER_INITIALIZER(false, "lb_policy_refcount"); +grpc_core::Tracer grpc_trace_lb_policy_refcount + (false, "lb_policy_refcount"); #endif void grpc_lb_policy_init(grpc_lb_policy *policy, @@ -52,7 +52,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 010299c2f4c..0fcb2ef17be 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -34,7 +34,7 @@ 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; +extern grpc_core::Tracer grpc_trace_lb_policy_refcount; #endif struct grpc_lb_policy { 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 ffd58129c6e..1b9e72bd24c 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::Tracer grpc_lb_glb_trace(false, "glb"); /* add lb_token of selected subchannel (address) to the call's initial * metadata */ @@ -212,7 +212,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, "Unreffing RR %p", (void *)wc_arg->rr_policy); } 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); } - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log( 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); @@ -647,7 +647,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, "Unreffing RR for drop (0x%" PRIxPTR ")", (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); 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, "Unreffing RR (0x%" PRIxPTR ")", (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.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", (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; 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, "Pending ping about to PING from 0x%" PRIxPTR "", (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); GPR_ASSERT(args != 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)", (void *)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, "Created new Round Robin policy (%p)", (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; 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", (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, false /* force_async */, target, wc_arg); } else { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "No RR policy in grpclb instance %p. Adding to grpclb's pending " "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_policy->retry_timer_active = false; 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)", (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 */ grpc_millis next_try = 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)...", (void *)glb_policy); 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); - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "Query for backends (grpclb: %p, lb_channel: %p, lb_call: %p)", (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( 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, "received initial LB response message; " "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; 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, "received initial LB response message; " "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); if (serverlist != 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", (unsigned long)serverlist->num_servers); 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 (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, "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); } } else { - if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { + if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "Received empty server list, ignoring."); } 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. */ if (glb_policy->serverlist == NULL) { 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, "Falling back to use backends from resolver (grpclb %p)", (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) { glb_lb_policy *glb_policy = (glb_lb_policy *)arg; GPR_ASSERT(glb_policy->lb_call != NULL); - 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, @@ -1869,7 +1869,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, "Will use '%s' as the server name for LB request.", glb_policy->server_name); } @@ -1962,9 +1962,9 @@ static bool maybe_add_client_load_reporting_filter( extern "C" 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, 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 b07fc3b720b..8c5065cd9e5 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 @@ -28,8 +28,8 @@ #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::Tracer grpc_lb_pick_first_trace + (false, "pick_first"); typedef struct pending_pick { struct pending_pick *next; @@ -97,7 +97,7 @@ static void pf_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) { gpr_free(p->subchannels); gpr_free(p->new_subchannels); 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); } } @@ -273,7 +273,7 @@ static void stop_connectivity_watchers(grpc_exec_ctx *exec_ctx, pick_first_lb_policy *p) { if (p->num_subchannels > 0) { 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", (void *)p, (void *)p->subchannels[p->checking_subchannel]); } @@ -282,7 +282,7 @@ static void stop_connectivity_watchers(grpc_exec_ctx *exec_ctx, &p->connectivity_changed); p->updating_subchannels = true; } 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, "Pick First %p unsubscribing from selected subchannel %p", (void *)p, (void *)p->selected); @@ -327,7 +327,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, stop_connectivity_watchers(exec_ctx, p); 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", (void *)p, (unsigned long)addresses->num_addresses); } @@ -366,7 +366,7 @@ static void pf_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, grpc_subchannel_key_destroy(exec_ctx, ith_sc_key); if (found_selected) { // 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 amongst " "updates. Update done.", @@ -385,7 +385,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 // interference (ie, no callbacks were scheduled). 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, "Update already in progress for pick first %p. Deferring update.", (void *)p); @@ -409,7 +409,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++) { grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( 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 = grpc_sockaddr_to_uri(&addresses->addresses[i].address); gpr_log(GPR_INFO, @@ -463,7 +463,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_subchannel *selected_subchannel; pending_pick *pp; - 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. Updating selected: %d; Updating " @@ -478,7 +478,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(p->selected != NULL); GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, p->selected, "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", (void *)p, (void *)p->selected); } @@ -495,7 +495,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, for (size_t i = 0; i < p->num_subchannels; i++) { GRPC_SUBCHANNEL_UNREF(exec_ctx, p->subchannels[i], "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, (void *)p->subchannels[i]); } @@ -568,7 +568,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_subchannel_get_connected_subchannel(selected_subchannel), "picked_first"); - 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 (connected %p)", (void *)p, (void *)selected_subchannel, (void *)p->selected); @@ -581,7 +581,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, while ((pp = p->pending_picks)) { p->pending_picks = pp->next; *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, "Servicing pending pick with selected subchannel %p", (void *)p->selected); @@ -682,7 +682,7 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, grpc_lb_policy_args *args) { GPR_ASSERT(args->client_channel_factory != NULL); 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); @@ -708,7 +708,7 @@ static grpc_lb_policy_factory *pick_first_lb_factory_create() { extern "C" void grpc_lb_policy_pick_first_init() { 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() {} 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 6812bb50cd9..f8c68307922 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 @@ -38,8 +38,8 @@ #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::Tracer grpc_lb_round_robin_trace + (false, "round_robin"); /** List of entities waiting for a pick. * @@ -152,7 +152,7 @@ static rr_subchannel_list *rr_subchannel_list_create(round_robin_lb_policy *p, (subchannel_data *)gpr_zalloc(sizeof(subchannel_data) * num_subchannels); subchannel_list->num_subchannels = num_subchannels; 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", (void *)p, (void *)subchannel_list, (unsigned long)num_subchannels); } @@ -162,7 +162,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, rr_subchannel_list *subchannel_list) { 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", (void *)subchannel_list->policy, (void *)subchannel_list); } @@ -186,7 +186,7 @@ static void rr_subchannel_list_destroy(grpc_exec_ctx *exec_ctx, static void rr_subchannel_list_ref(rr_subchannel_list *subchannel_list, const char *reason) { 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); gpr_log(GPR_INFO, "[RR %p] subchannel_list %p REF %lu->%lu (%s)", (void *)subchannel_list->policy, (void *)subchannel_list, @@ -198,7 +198,7 @@ static void rr_subchannel_list_unref(grpc_exec_ctx *exec_ctx, rr_subchannel_list *subchannel_list, const char *reason) { 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); gpr_log(GPR_INFO, "[RR %p] subchannel_list %p UNREF %lu->%lu (%s)", (void *)subchannel_list->policy, (void *)subchannel_list, @@ -215,7 +215,7 @@ static void rr_subchannel_list_shutdown_and_unref( grpc_exec_ctx *exec_ctx, rr_subchannel_list *subchannel_list, const char *reason) { 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)", (void *)subchannel_list->policy, (void *)subchannel_list, reason); } @@ -224,7 +224,7 @@ static void rr_subchannel_list_shutdown_and_unref( for (size_t i = 0; i < subchannel_list->num_subchannels; i++) { subchannel_data *sd = &subchannel_list->subchannels[i]; 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_DEBUG, "[RR %p] Unsubscribing from subchannel %p as part of shutting down " @@ -249,7 +249,7 @@ static void rr_subchannel_list_shutdown_and_unref( static size_t get_next_ready_subchannel_index_locked( const round_robin_lb_policy *p) { 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, "[RR %p] getting next ready subchannel (out of %lu), " "last_ready_subchannel_index=%lu", @@ -259,7 +259,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: " @@ -271,7 +271,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", @@ -282,7 +282,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; @@ -293,7 +293,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)", @@ -306,7 +306,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); } @@ -317,7 +317,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) { 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", (void *)pol, (void *)pol); } @@ -424,7 +424,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, grpc_closure *on_complete) { round_robin_lb_policy *p = (round_robin_lb_policy *)pol; 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); } if (p->subchannel_list != NULL) { @@ -438,7 +438,7 @@ static int rr_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol, if (user_data != NULL) { *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, " @@ -558,7 +558,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { subchannel_data *sd = (subchannel_data *)arg; 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_DEBUG, "[RR %p] connectivity changed for subchannel %p, subchannel_list %p: " @@ -644,7 +644,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 != NULL ? (unsigned long)p->subchannel_list->num_subchannels @@ -684,7 +684,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx *exec_ctx, void *arg, if (pp->user_data != NULL) { *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)", @@ -774,7 +774,7 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, } size_t subchannel_index = 0; 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, "[RR %p] Shutting down latest pending subchannel list %p, about " "to be replaced by newer latest %p", @@ -816,7 +816,7 @@ static void rr_update_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy, GRPC_ERROR_UNREF(error); continue; } - if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { + if (grpc_lb_round_robin_trace.enabled()) { char *address_uri = grpc_sockaddr_to_uri(&addresses->addresses[i].address); gpr_log( @@ -896,7 +896,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); } @@ -918,7 +918,7 @@ static grpc_lb_policy_factory *round_robin_lb_factory_create() { extern "C" void grpc_lb_policy_round_robin_init() { 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() {} diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 8401504fcf6..1863a941626 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -20,8 +20,8 @@ #include "src/core/lib/iomgr/combiner.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_resolver_refcount = - GRPC_TRACER_INITIALIZER(false, "resolver_refcount"); +grpc_core::Tracer grpc_trace_resolver_refcount + (false, "resolver_refcount"); #endif void grpc_resolver_init(grpc_resolver *resolver, @@ -35,7 +35,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 +50,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 73fbbbbc3b1..990e9737e92 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -30,7 +30,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; +extern grpc_core::Tracer grpc_trace_resolver_refcount; #endif /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 5710a221784..3d7b5dd5bf3 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 8f5b8563172..24d46a60aeb 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -65,7 +65,7 @@ static bool maybe_add_required_filter(grpc_exec_ctx *exec_ctx, } 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_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 f785e1355d3..5c4728719e6 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; @@ -257,7 +257,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 ac9ae5c395f..06059cb92ae 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc @@ -21,11 +21,11 @@ #include "src/core/lib/transport/metadata.h" 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 - grpc_register_tracer(&grpc_trace_chttp2_refcount); + #endif } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 0ef06ae6e00..664fb72e573 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -91,12 +91,12 @@ 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"); +grpc_core::Tracer grpc_http_trace(false, "http"); +grpc_core::Tracer grpc_flowctl_trace(false, "flowctl"); #ifndef NDEBUG -grpc_tracer_flag grpc_trace_chttp2_refcount = - GRPC_TRACER_INITIALIZER(false, "chttp2_refcount"); +grpc_core::Tracer grpc_trace_chttp2_refcount + (false, "chttp2_refcount"); #endif /* forward declarations of various callbacks that we'll build closures around */ @@ -229,7 +229,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); @@ -240,7 +240,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); @@ -1216,7 +1216,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, @@ -1375,7 +1375,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); @@ -1667,7 +1667,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); @@ -2563,7 +2563,7 @@ static void read_action_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_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", t->peer_string); } /* Reset the keepalive ping timer */ @@ -2576,7 +2576,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", t->peer_string); } t->flow_control.bdp_estimator->CompletePing(exec_ctx); @@ -3054,7 +3054,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); } @@ -3063,7 +3063,7 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, 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)) { + grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR " streams", @@ -3085,7 +3085,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 321fca4c825..08c22181a75 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -27,12 +27,12 @@ extern "C" { #endif -extern grpc_tracer_flag grpc_http_trace; -extern grpc_tracer_flag grpc_flowctl_trace; -extern grpc_tracer_flag grpc_trace_http2_stream_state; +extern grpc_core::Tracer grpc_http_trace; +extern grpc_core::Tracer grpc_flowctl_trace; +extern grpc_core::Tracer grpc_trace_http2_stream_state; #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_chttp2_refcount; +extern grpc_core::Tracer grpc_trace_chttp2_refcount; #endif grpc_transport *grpc_create_chttp2_transport( diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index 2995bf73102..b3fc08041f8 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -204,20 +204,20 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p, parser->incoming_settings[id] != parser->value) { t->flow_control.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->flow_control.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 17b8c4ab85e..098d61cc6fb 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -57,7 +57,7 @@ static const grpc_slice terminal_slice = { {{0, 0}} /* data.refcounted */ }; -extern "C" grpc_tracer_flag grpc_http_trace; +extern grpc_core::Tracer grpc_http_trace; typedef struct { int is_first_frame; @@ -430,7 +430,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) && !GRPC_MDELEM_IS_INTERNED(elem)) { + if (grpc_http_trace.enabled() && !GRPC_MDELEM_IS_INTERNED(elem)) { char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); char *v = grpc_slice_to_c_string(GRPC_MDVALUE(elem)); gpr_log( @@ -622,7 +622,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_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 3d1df19bc38..d974e3872c8 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -650,7 +650,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) && !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 *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); 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, 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 82c284b36e3..66bd87c94e3 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::Tracer 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 f7a57a6543e..07dc381e0a7 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -793,12 +793,12 @@ 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::Tracer grpc_http_trace; +extern grpc_core::Tracer grpc_flowctl_trace; #ifndef NDEBUG #define GRPC_FLOW_CONTROL_IF_TRACING(stmt) \ - if (!(GRPC_TRACER_ON(grpc_flowctl_trace))) \ + if (!(grpc_flowctl_trace.enabled())) \ ; \ else \ stmt @@ -807,7 +807,7 @@ extern grpc_tracer_flag grpc_flowctl_trace; #endif #define GRPC_CHTTP2_IF_TRACING(stmt) \ - if (!(GRPC_TRACER_ON(grpc_http_trace))) \ + if (!(grpc_http_trace.enabled())) \ ; \ else \ stmt diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 78886b497a7..a766ac4c3fd 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -310,7 +310,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); @@ -414,7 +414,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, 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 *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -496,7 +496,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, 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 *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -749,7 +749,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, NULL)) { - 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 9f731a397f3..3595d09a8f2 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -39,8 +39,8 @@ 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::Tracer grpc_trace_http2_stream_state + (false, "http2_stream_state"); /* core list management */ @@ -66,7 +66,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 +88,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 +120,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 25c1a5ef056..e3ee506e873 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -51,8 +51,8 @@ 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 +61,8 @@ 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 +81,8 @@ 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 +103,8 @@ 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 5d8a1c74abd..8e0203b5ed4 100644 --- a/src/core/ext/transport/inproc/inproc_plugin.cc +++ b/src/core/ext/transport/inproc/inproc_plugin.cc @@ -19,12 +19,9 @@ #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::Tracer grpc_inproc_trace(false, "inproc"); -extern "C" void grpc_inproc_plugin_init(void) { - grpc_register_tracer(&grpc_inproc_trace); - grpc_inproc_transport_init(); -} +extern "C" void grpc_inproc_plugin_init(void) { grpc_inproc_transport_init(); } extern "C" 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 67a8358927c..047a24c145e 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -34,7 +34,7 @@ #define INPROC_LOG(...) \ do { \ - if (GRPC_TRACER_ON(grpc_inproc_trace)) gpr_log(__VA_ARGS__); \ + 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 != 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_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 37e6d99e99f..8fd8caf4029 100644 --- a/src/core/ext/transport/inproc/inproc_transport.h +++ b/src/core/ext/transport/inproc/inproc_transport.h @@ -29,7 +29,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::Tracer grpc_inproc_trace; void grpc_inproc_transport_init(void); void grpc_inproc_transport_shutdown(void); diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 775c8bc667c..5201d6bf3d7 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -23,7 +23,7 @@ #include #include -grpc_tracer_flag grpc_trace_channel = GRPC_TRACER_INITIALIZER(false, "channel"); +grpc_core::Tracer grpc_trace_channel(false, "channel"); /* Memory layouts. diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 5c00c098894..01d6310428f 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -285,10 +285,10 @@ void grpc_call_log_op(const char *file, int line, gpr_log_severity severity, grpc_call_element *elem, grpc_transport_stream_op_batch *op); -extern grpc_tracer_flag grpc_trace_channel; +extern grpc_core::Tracer grpc_trace_channel; #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 } diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index b663ebfb522..83f8113a353 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -23,8 +23,8 @@ #include #include -grpc_tracer_flag grpc_trace_channel_stack_builder = - GRPC_TRACER_INITIALIZER(false, "channel_stack_builder"); +grpc_core::Tracer grpc_trace_channel_stack_builder + (false, "channel_stack_builder"); typedef struct filter_node { struct filter_node *next; diff --git a/src/core/lib/channel/channel_stack_builder.h b/src/core/lib/channel/channel_stack_builder.h index fdff2a2b6db..d790cf9a637 100644 --- a/src/core/lib/channel/channel_stack_builder.h +++ b/src/core/lib/channel/channel_stack_builder.h @@ -160,7 +160,7 @@ grpc_error *grpc_channel_stack_builder_finish( void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder); -extern grpc_tracer_flag grpc_trace_channel_stack_builder; +extern grpc_core::Tracer grpc_trace_channel_stack_builder; #ifdef __cplusplus } diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 21b0d8c3a67..5953be641ad 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -27,26 +27,53 @@ int grpc_tracer_set_enabled(const char *name, int enabled); -typedef struct tracer { - grpc_tracer_flag *flag; - struct tracer *next; -} tracer; -static tracer *tracers; - -#ifdef GRPC_THREADSAFE_TRACER -#define TRACER_SET(flag, on) gpr_atm_no_barrier_store(&(flag).value, (on)) -#else -#define TRACER_SET(flag, on) (flag).value = (on) -#endif - -void grpc_register_tracer(grpc_tracer_flag *flag) { - tracer *t = (tracer *)gpr_malloc(sizeof(*t)); - t->flag = flag; - t->next = tracers; - TRACER_SET(*flag, false); - tracers = t; +namespace grpc_core { + +Tracer::Tracer(bool default_enabled, const char *name) + : next_tracer_(root_tracer_), name_(name), value_(default_enabled) { + root_tracer_ = this; +} + +void Tracer::List() { + gpr_log(GPR_DEBUG, "available tracers:"); + Tracer *t; + for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { + gpr_log(GPR_DEBUG, "\t%s", t->name_); + } +} + +bool Tracer::Set(const char *name, bool enabled) { + Tracer *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) { size_t n = *ns; size_t np = n + 1; @@ -80,9 +107,9 @@ static void parse(const char *s) { for (i = 0; i < nstrings; i++) { if (strings[i][0] == '-') { - grpc_tracer_set_enabled(strings[i] + 1, 0); + grpc_core::Tracer::Set(strings[i] + 1, false); } else { - grpc_tracer_set_enabled(strings[i], 1); + grpc_core::Tracer::Set(strings[i], true); } } @@ -92,14 +119,6 @@ static void parse(const char *s) { 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) { char *e = gpr_getenv(env_var); if (e != NULL) { @@ -108,40 +127,8 @@ void grpc_tracer_init(const char *env_var) { } } -void grpc_tracer_shutdown(void) { - while (tracers) { - tracer *t = tracers; - tracers = t->next; - gpr_free(t); - } -} +void grpc_tracer_shutdown(void) {} int grpc_tracer_set_enabled(const char *name, int enabled) { - tracer *t; - 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; + return grpc_core::Tracer::Set(name, enabled != 0); } diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 558ba942bbb..c9ce850d3ff 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -27,37 +27,61 @@ extern "C" { #endif +void grpc_tracer_init(const char *env_var_name); +void grpc_tracer_shutdown(void); + +#ifdef __cplusplus +} +#endif + #if defined(__has_feature) #if __has_feature(thread_sanitizer) #define GRPC_THREADSAFE_TRACER #endif #endif -typedef struct { +#ifdef __cplusplus + +namespace grpc_core { + +class Tracer { + public: + Tracer(bool default_enabled, const char *name); + ~Tracer(); + + static bool Set(const char *tracer, bool enabled); + + bool enabled() { +#ifdef GRPC_THREADSAFE_TRACER + gpr_atm_no_barrier_load(&value_) != 0 +#else + return value_; +#endif + } + + private: + static void List(); + + void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER - gpr_atm value; + gpr_atm_no_barrier_store(&value, enabled); #else - bool value; + value_ = enabled; #endif - const char *name; -} grpc_tracer_flag; + } + static Tracer *root_tracer_; + Tracer *next_tracer_; + const char *const name_; #ifdef GRPC_THREADSAFE_TRACER -#define GRPC_TRACER_ON(flag) (gpr_atm_no_barrier_load(&(flag).value) != 0) -#define GRPC_TRACER_INITIALIZER(on, name) \ - { (gpr_atm)(on), (name) } + gpr_atm value_; #else -#define GRPC_TRACER_ON(flag) ((flag).value) -#define GRPC_TRACER_INITIALIZER(on, name) \ - { (on), (name) } + bool value_; #endif +}; -void grpc_register_tracer(grpc_tracer_flag *flag); -void grpc_tracer_init(const char *env_var_name); -void grpc_tracer_shutdown(void); +} // namespace grpc_core -#ifdef __cplusplus -} -#endif +#endif // __cplusplus #endif /* GRPC_CORE_LIB_DEBUG_TRACE_H */ diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index 0950bd655ef..f272df11ddc 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -25,7 +25,7 @@ #include #include -grpc_tracer_flag grpc_http1_trace = GRPC_TRACER_INITIALIZER(false, "http1"); +grpc_core::Tracer grpc_http1_trace(false, "http1"); static char *buf2str(void *buffer, size_t length) { 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_HEADERS: 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", GRPC_HTTP_PARSER_MAX_HEADER_LENGTH); return GRPC_ERROR_CREATE_FROM_STATIC_STRING( diff --git a/src/core/lib/http/parser.h b/src/core/lib/http/parser.h index d2bda6ae0e4..b6efeda28a6 100644 --- a/src/core/lib/http/parser.h +++ b/src/core/lib/http/parser.h @@ -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_response_destroy(grpc_http_response *response); -extern grpc_tracer_flag grpc_http1_trace; +extern grpc_core::Tracer grpc_http1_trace; #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index d45719608b4..d36e2c5befa 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -24,8 +24,8 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/profiling/timers.h" -grpc_tracer_flag grpc_call_combiner_trace = - GRPC_TRACER_INITIALIZER(false, "call_combiner"); +grpc_core::Tracer grpc_call_combiner_trace + (false, "call_combiner"); static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) { if (cancel_state & 1) { @@ -63,7 +63,7 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, grpc_error* error DEBUG_ARGS, const char* reason) { 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, "==> grpc_call_combiner_start() [%p] closure=%p [" DEBUG_FMT_STR "%s] error=%s", @@ -72,7 +72,7 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, } size_t prev_size = (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, prev_size + 1); } @@ -80,13 +80,13 @@ void grpc_call_combiner_start(grpc_exec_ctx* exec_ctx, if (prev_size == 0) { GRPC_STATS_INC_CALL_COMBINER_LOCKS_INITIATED(exec_ctx); 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"); } // Queue was empty, so execute this closure immediately. GRPC_CLOSURE_SCHED(exec_ctx, closure, error); } else { - if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { + if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_INFO, " QUEUING"); } // Queue was not empty, so add closure to queue. @@ -100,21 +100,21 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, grpc_call_combiner* call_combiner DEBUG_ARGS, const char* reason) { 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, "==> grpc_call_combiner_stop() [%p] [" DEBUG_FMT_STR "%s]", call_combiner DEBUG_FMT_ARGS, reason); } size_t prev_size = (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, prev_size - 1); } GPR_ASSERT(prev_size >= 1); if (prev_size > 1) { while (true) { - if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { + if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " checking queue"); } bool empty; @@ -123,19 +123,19 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, if (closure == NULL) { // This can happen either due to a race condition within the mpscq // 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"); } 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", closure, grpc_error_string(closure->error_data.error)); } GRPC_CLOSURE_SCHED(exec_ctx, closure, closure->error_data.error); break; } - } else if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { + } else if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, " queue empty"); } GPR_TIMER_END("call_combiner_stop", 0); @@ -152,7 +152,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, // If error is set, invoke the cancellation closure immediately. // Otherwise, store the new closure. if (original_error != GRPC_ERROR_NONE) { - if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { + if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, "call_combiner=%p: scheduling notify_on_cancel callback=%p " "for pre-existing cancellation", @@ -163,7 +163,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, } else { if (gpr_atm_full_cas(&call_combiner->cancel_state, original_state, (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", call_combiner, closure); } @@ -172,7 +172,7 @@ void grpc_call_combiner_set_notify_on_cancel(grpc_exec_ctx* exec_ctx, // up any resources they may be holding for the callback. if (original_state != 0) { closure = (grpc_closure*)original_state; - if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { + if (grpc_call_combiner_trace.enabled()) { gpr_log(GPR_DEBUG, "call_combiner=%p: scheduling old cancel callback=%p", call_combiner, closure); @@ -201,7 +201,7 @@ void grpc_call_combiner_cancel(grpc_exec_ctx* exec_ctx, encode_cancel_state_error(error))) { if (original_state != 0) { 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, "call_combiner=%p: scheduling notify_on_cancel callback=%p", call_combiner, notify_on_cancel); diff --git a/src/core/lib/iomgr/call_combiner.h b/src/core/lib/iomgr/call_combiner.h index 527f84fce04..463501a6603 100644 --- a/src/core/lib/iomgr/call_combiner.h +++ b/src/core/lib/iomgr/call_combiner.h @@ -40,7 +40,7 @@ extern "C" { // when it is done with the action that was kicked off by the original // callback. -extern grpc_tracer_flag grpc_call_combiner_trace; +extern grpc_core::Tracer grpc_call_combiner_trace; typedef struct { gpr_atm size; // size_t, num closures in queue or currently executing diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc index 00edefc6ae4..b2dfdbc207b 100644 --- a/src/core/lib/iomgr/closure.cc +++ b/src/core/lib/iomgr/closure.cc @@ -25,7 +25,7 @@ #include "src/core/lib/profiling/timers.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_closure = GRPC_TRACER_INITIALIZER(false, "closure"); +grpc_core::Tracer grpc_trace_closure(false, "closure"); #endif #ifndef NDEBUG diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index cd32a4ba381..ae946072ce4 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -34,7 +34,7 @@ struct grpc_closure; typedef struct grpc_closure grpc_closure; #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_closure; +extern grpc_core::Tracer grpc_trace_closure; #endif typedef struct grpc_closure_list { diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 53f4b7eaa7e..2d1c652041a 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -29,12 +29,12 @@ #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/profiling/timers.h" -grpc_tracer_flag grpc_combiner_trace = - GRPC_TRACER_INITIALIZER(false, "combiner"); +grpc_core::Tracer grpc_combiner_trace + (false, "combiner"); #define GRPC_COMBINER_TRACE(fn) \ do { \ - if (GRPC_TRACER_ON(grpc_combiner_trace)) { \ + if (grpc_combiner_trace.enabled()) { \ fn; \ } \ } while (0) @@ -106,7 +106,7 @@ static void start_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock) { #ifndef NDEBUG #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, \ "C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \ gpr_atm_no_barrier_load(&lock->refs.count), \ diff --git a/src/core/lib/iomgr/combiner.h b/src/core/lib/iomgr/combiner.h index 10e5fb480db..5f80e1de271 100644 --- a/src/core/lib/iomgr/combiner.h +++ b/src/core/lib/iomgr/combiner.h @@ -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); -extern grpc_tracer_flag grpc_combiner_trace; +extern grpc_core::Tracer grpc_combiner_trace; #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 2ea6cf1301e..cbb27f442ed 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -38,8 +38,8 @@ #include "src/core/lib/slice/slice_internal.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_error_refcount = - GRPC_TRACER_INITIALIZER(false, "error_refcount"); +grpc_core::Tracer grpc_trace_error_refcount + (false, "error_refcount"); #endif static const char *error_int_name(grpc_error_ints key) { @@ -130,7 +130,7 @@ bool grpc_error_is_special(grpc_error *err) { #ifndef NDEBUG grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line) { 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_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line); @@ -183,7 +183,7 @@ static void error_destroy(grpc_error *err) { #ifndef NDEBUG void grpc_error_unref(grpc_error *err, const char *file, int line) { 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_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line); @@ -216,7 +216,7 @@ static uint8_t get_placement(grpc_error **err, size_t size) { *err = (grpc_error *)gpr_realloc( *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { + if (grpc_trace_error_refcount.enabled()) { if (*err != orig) { gpr_log(GPR_DEBUG, "realloc %p -> %p", orig, *err); } @@ -329,7 +329,7 @@ grpc_error *grpc_error_create(const char *file, int line, grpc_slice desc, return GRPC_ERROR_OOM; } #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); } #endif @@ -411,7 +411,7 @@ static grpc_error *copy_error_and_unref(grpc_error *in) { out = (grpc_error *)gpr_malloc(sizeof(*in) + new_arena_capacity * sizeof(intptr_t)); #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); } #endif diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index b36330a7ab6..0d91006a90d 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -39,7 +39,7 @@ extern "C" { typedef struct grpc_error grpc_error; #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_error_refcount; +extern grpc_core::Tracer grpc_trace_error_refcount; #endif typedef enum { diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 6126e2771cd..4bda75ebb73 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -274,7 +274,7 @@ static grpc_fd *fd_create(int fd, const char *name) { gpr_asprintf(&fd_name, "%s fd=%d", name, fd); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); #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); } #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); - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { 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; 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); } @@ -691,7 +691,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, retry_lock_neighborhood: gpr_mu_lock(&neighborhood->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", pollset, worker, kick_state_string(worker->state), is_reassigning); @@ -743,7 +743,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, worker->initialized_cv = true; gpr_cv_init(&worker->cv); 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", pollset, worker, kick_state_string(worker->state), 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); } - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, "PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " "kicked_without_poller: %d", @@ -805,7 +805,7 @@ static bool check_neighborhood_for_available_poller( case UNKICKED: if (gpr_atm_no_barrier_cas(&g_active_poller, 0, (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", inspect_worker); } @@ -816,7 +816,7 @@ static bool check_neighborhood_for_available_poller( gpr_cv_signal(&inspect_worker->cv); } } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { 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); } if (!found_worker) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, " .. mark pollset %p inactive", inspect); } 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_hdl) { 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); } 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); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { 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_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) { gpr_cv_destroy(&worker->cv); } - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, " .. remove 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); GRPC_STATS_INC_POLLSET_KICK(exec_ctx); grpc_error *ret_err = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_strvec log; gpr_strvec_init(&log); char *tmp; @@ -1025,7 +1025,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, if (root_worker == NULL) { GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); pollset->kicked_without_poller = true; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked_without_poller"); } 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; if (root_worker->state == KICKED) { 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); } SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { 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); } 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( &g_active_poller)) { 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); } 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; } else if (next_worker->state == UNKICKED) { 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_ASSERT(next_worker->initialized_cv); @@ -1068,7 +1068,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, goto done; } else if (next_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_ERROR, " .. 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; } else { 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, root_worker); } @@ -1098,7 +1098,7 @@ static grpc_error *pollset_kick(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, } } else { 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"); } 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 (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. specific worker already kicked"); } goto done; } else if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { 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); } 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 == (grpc_pollset_worker *)gpr_atm_no_barrier_load(&g_active_poller)) { 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"); } 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; } else if (specific_worker->initialized_cv) { 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"); } 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; } else { 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"); } SET_KICK_STATE(specific_worker, KICKED); diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 59dd8fd2fe9..58e5392c478 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -264,7 +264,7 @@ static gpr_mu fd_freelist_mu; unref_by(ec, fd, n, reason, __FILE__, __LINE__) static void ref_by(grpc_fd *fd, int n, 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, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -297,7 +297,7 @@ static void fd_destroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { #ifndef NDEBUG static void unref_by(grpc_exec_ctx *exec_ctx, grpc_fd *fd, int n, 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, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -360,7 +360,7 @@ static grpc_fd *fd_create(int fd, const char *name) { gpr_asprintf(&fd_name, "%s fd=%d", name, fd); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); #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); } #endif @@ -499,7 +499,7 @@ static grpc_error *pollable_add_fd(pollable *p, grpc_fd *fd) { const int epfd = p->epfd; GPR_ASSERT(epfd != -1); - 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); } @@ -567,7 +567,7 @@ static void do_kick_all(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_lock(&worker->pollable_obj->po.mu); } if (worker->initialized_cv && worker != pollset->root_worker) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kickall_via_cv %p (pollable %p vs %p)", pollset, worker, &pollset->pollable_obj, worker->pollable_obj); @@ -575,7 +575,7 @@ static void do_kick_all(grpc_exec_ctx *exec_ctx, void *arg, worker->kicked = true; gpr_cv_signal(&worker->cv); } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kickall_via_wakeup %p (pollable %p vs %p)", pollset, worker, &pollset->pollable_obj, worker->pollable_obj); @@ -606,7 +606,7 @@ static void pollset_kick_all(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset) { static grpc_error *pollset_kick_inner(grpc_pollset *pollset, pollable *p, grpc_pollset_worker *specific_worker) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kick %p tls_pollset=%p tls_worker=%p " "root_worker=(pollset:%p pollable:%p)", @@ -617,13 +617,13 @@ static grpc_error *pollset_kick_inner(grpc_pollset *pollset, pollable *p, if (specific_worker == NULL) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { 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", p); } pollset->kicked_without_poller = true; return GRPC_ERROR_NONE; } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_via_wakeup_fd", p); } grpc_error *err = pollable_materialize(p); @@ -631,25 +631,25 @@ static grpc_error *pollset_kick_inner(grpc_pollset *pollset, pollable *p, return grpc_wakeup_fd_wakeup(&p->wakeup); } } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", p); } return GRPC_ERROR_NONE; } } else 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); } return GRPC_ERROR_NONE; } else 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); } specific_worker->kicked = true; return GRPC_ERROR_NONE; } else if (specific_worker == p->root_worker) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_wakeup_fd", p); } grpc_error *err = pollable_materialize(p); @@ -657,7 +657,7 @@ static grpc_error *pollset_kick_inner(grpc_pollset *pollset, pollable *p, specific_worker->kicked = true; return grpc_wakeup_fd_wakeup(&p->wakeup); } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_via_cv", p); } specific_worker->kicked = true; @@ -752,7 +752,7 @@ static grpc_error *pollset_process_events(grpc_exec_ctx *exec_ctx, struct epoll_event *ev = &pollset->events[n]; void *data_ptr = ev->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); } append_error(&error, @@ -764,7 +764,7 @@ static grpc_error *pollset_process_events(grpc_exec_ctx *exec_ctx, bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p got fd %p: cancel=%d read=%d " "write=%d", @@ -797,7 +797,7 @@ static grpc_error *pollset_epoll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, pollable *p, grpc_millis 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); gpr_log(GPR_DEBUG, "PS:%p poll %p[%s] for %dms", pollset, p, desc, timeout); gpr_free(desc); @@ -817,7 +817,7 @@ static grpc_error *pollset_epoll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, 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, "PS:%p poll %p got %d events", pollset, p, r); } @@ -890,7 +890,7 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, if (worker->pollable_obj != &pollset->pollable_obj) { gpr_mu_unlock(&pollset->pollable_obj.po.mu); } - if (GRPC_TRACER_ON(grpc_polling_trace) && + if (grpc_polling_trace.enabled() && worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset, worker->pollable_obj, worker, @@ -899,18 +899,18 @@ static bool begin_worker(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, while (do_poll && worker->pollable_obj->root_worker != worker) { if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->po.mu, 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, worker->pollable_obj, worker); } do_poll = false; } 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, worker->pollable_obj, worker); } do_poll = false; - } else if (GRPC_TRACER_ON(grpc_polling_trace) && + } else if (grpc_polling_trace.enabled() && worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset, worker->pollable_obj, worker); @@ -954,7 +954,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, grpc_pollset_worker **worker_hdl, grpc_millis deadline) { grpc_pollset_worker worker; - if (0 && GRPC_TRACER_ON(grpc_polling_trace)) { + if (0 && grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRIdPTR " deadline=%" PRIdPTR " kwp=%d root_worker=%p", pollset, worker_hdl, &worker, grpc_exec_ctx_now(exec_ctx), deadline, @@ -1018,7 +1018,7 @@ static grpc_error *pollset_add_fd_locked(grpc_exec_ctx *exec_ctx, static const char *err_desc = "pollset_add_fd"; grpc_error *error = GRPC_ERROR_NONE; if (pollset->current_pollable_obj == &g_empty_pollable) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p add fd %p; transition pollable from empty to fd", pollset, fd); @@ -1031,14 +1031,14 @@ static grpc_error *pollset_add_fd_locked(grpc_exec_ctx *exec_ctx, if (!fd_locked) gpr_mu_unlock(&fd->pollable_obj.po.mu); REF_BY(fd, 2, "pollset_pollable"); } else if (pollset->current_pollable_obj == &pollset->pollable_obj) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p add fd %p; already multipolling", pollset, fd); } append_error(&error, pollable_add_fd(pollset->current_pollable_obj, fd), err_desc); } else if (pollset->current_pollable_obj != &fd->pollable_obj) { grpc_fd *had_fd = (grpc_fd *)pollset->current_pollable_obj; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p add fd %p; transition pollable from fd %p to multipoller", pollset, fd, had_fd); diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 035bdc4cb55..648de4f7e15 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -54,7 +54,7 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #define GRPC_POLLING_TRACE(...) \ - if (GRPC_TRACER_ON(grpc_polling_trace)) { \ + if (grpc_polling_trace.enabled()) { \ gpr_log(GPR_INFO, __VA_ARGS__); \ } @@ -288,7 +288,7 @@ static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi); #ifndef NDEBUG static void pi_add_ref_dbg(polling_island *pi, 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_log(GPR_DEBUG, "Add ref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR " (%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, 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_log(GPR_DEBUG, "Unref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR " (%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__) static void ref_by(grpc_fd *fd, int n, 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, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", 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 static void unref_by(grpc_fd *fd, int n, 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, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 036a35690c5..ad4d0164bdc 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -288,7 +288,7 @@ cv_fd_table g_cvfds; #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, int line) { - if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { + if (grpc_trace_fd_refcount.enabled()) { gpr_log(GPR_DEBUG, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", 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 static void unref_by(grpc_fd *fd, int n, 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, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", 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); 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); } @@ -1016,7 +1016,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, } } else { 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); } 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) { fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); } 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, pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 3a1dd8d30b3..166801e229a 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -36,12 +36,12 @@ #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/support/env.h" -grpc_tracer_flag grpc_polling_trace = - GRPC_TRACER_INITIALIZER(false, "polling"); /* Disabled by default */ +grpc_core::Tracer grpc_polling_trace + (false, "polling"); /* Disabled by default */ #ifndef NDEBUG -grpc_tracer_flag grpc_trace_fd_refcount = - GRPC_TRACER_INITIALIZER(false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount + (false, "fd_refcount"); #endif /** Default poll() function - a pointer so that it can be overridden by some @@ -156,7 +156,7 @@ const grpc_event_engine_vtable *grpc_get_event_engine_test_only() { const char *grpc_get_poll_strategy_name() { return g_poll_strategy_name; } void grpc_event_engine_init(void) { - grpc_register_tracer(&grpc_polling_trace); + char *s = gpr_getenv("GRPC_POLL_STRATEGY"); if (s == NULL) { diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index bc4456c2a29..1f585259c11 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -31,7 +31,7 @@ extern "C" { #endif -extern grpc_tracer_flag grpc_polling_trace; /* Disabled by default */ +extern grpc_core::Tracer grpc_polling_trace; /* Disabled by default */ typedef struct grpc_fd grpc_fd; diff --git a/src/core/lib/iomgr/ev_windows.cc b/src/core/lib/iomgr/ev_windows.cc index c24dfaeaf7c..c9d83c09492 100644 --- a/src/core/lib/iomgr/ev_windows.cc +++ b/src/core/lib/iomgr/ev_windows.cc @@ -22,7 +22,7 @@ #include "src/core/lib/debug/trace.h" -grpc_tracer_flag grpc_polling_trace = - GRPC_TRACER_INITIALIZER(false, "polling"); /* Disabled by default */ +grpc_core::Tracer grpc_polling_trace + (false, "polling"); /* Disabled by default */ #endif // GRPC_WINSOCK_SOCKET diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 3d17afcb8fb..6707f40f105 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -60,7 +60,7 @@ static void exec_ctx_run(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error) { #ifndef NDEBUG 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]", closure, closure->file_created, closure->line_created, 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 closure->cb(exec_ctx, closure->cb_arg, error); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_closure)) { + if (grpc_trace_closure.enabled()) { gpr_log(GPR_DEBUG, "closure %p finished", closure); } #endif diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 92c3e70301c..bf233087d51 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -51,8 +51,8 @@ static gpr_spinlock g_adding_thread_lock = GPR_SPINLOCK_STATIC_INITIALIZER; GPR_TLS_DECL(g_this_thread_state); -static grpc_tracer_flag executor_trace = - GRPC_TRACER_INITIALIZER(false, "executor"); +static grpc_core::Tracer executor_trace + (false, "executor"); static void executor_thread(void *arg); @@ -63,7 +63,7 @@ static size_t run_closures(grpc_exec_ctx *exec_ctx, grpc_closure_list list) { while (c != NULL) { grpc_closure *next = c->next_data.next; grpc_error *error = c->error_data.error; - if (GRPC_TRACER_ON(executor_trace)) { + if (executor_trace.enabled()) { #ifndef NDEBUG gpr_log(GPR_DEBUG, "EXECUTOR: run %p [created by %s:%d]", c, c->file_created, c->line_created); @@ -134,7 +134,7 @@ void grpc_executor_set_threading(grpc_exec_ctx *exec_ctx, bool threading) { } void grpc_executor_init(grpc_exec_ctx *exec_ctx) { - grpc_register_tracer(&executor_trace); + gpr_atm_no_barrier_store(&g_cur_threads, 0); grpc_executor_set_threading(exec_ctx, true); } @@ -152,7 +152,7 @@ static void executor_thread(void *arg) { size_t subtract_depth = 0; for (;;) { - if (GRPC_TRACER_ON(executor_trace)) { + if (executor_trace.enabled()) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: step (sub_depth=%" PRIdPTR ")", (int)(ts - g_thread_state), subtract_depth); } @@ -163,7 +163,7 @@ static void executor_thread(void *arg) { gpr_cv_wait(&ts->cv, &ts->mu, gpr_inf_future(GPR_CLOCK_REALTIME)); } if (ts->shutdown) { - if (GRPC_TRACER_ON(executor_trace)) { + if (executor_trace.enabled()) { gpr_log(GPR_DEBUG, "EXECUTOR[%d]: shutdown", (int)(ts - g_thread_state)); } @@ -174,7 +174,7 @@ static void executor_thread(void *arg) { grpc_closure_list exec = ts->elems; ts->elems = GRPC_CLOSURE_LIST_INIT; 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)); } @@ -196,7 +196,7 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure, retry_push = false; size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads); if (cur_thread_count == 0) { - if (GRPC_TRACER_ON(executor_trace)) { + if (executor_trace.enabled()) { #ifndef NDEBUG gpr_log(GPR_DEBUG, "EXECUTOR: schedule %p (created %s:%d) inline", closure, closure->file_created, closure->line_created); @@ -217,7 +217,7 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure, bool try_new_thread; for (;;) { - if (GRPC_TRACER_ON(executor_trace)) { + if (executor_trace.enabled()) { #ifndef NDEBUG gpr_log( GPR_DEBUG, diff --git a/src/core/lib/iomgr/iomgr_posix.cc b/src/core/lib/iomgr/iomgr_posix.cc index f5875a247ee..3135b1d5632 100644 --- a/src/core/lib/iomgr/iomgr_posix.cc +++ b/src/core/lib/iomgr/iomgr_posix.cc @@ -28,7 +28,7 @@ void grpc_iomgr_platform_init(void) { grpc_wakeup_fd_global_init(); grpc_event_engine_init(); - grpc_register_tracer(&grpc_tcp_trace); + } void grpc_iomgr_platform_flush(void) {} diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index df5d23af3bb..d63829b8b12 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -31,7 +31,7 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_global_init(); - grpc_register_tracer(&grpc_tcp_trace); + grpc_executor_set_threading(&exec_ctx, false); g_init_thread = gpr_thd_currentid(); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index f967b22ba99..27e720d2191 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -22,7 +22,7 @@ #include "src/core/lib/debug/trace.h" -extern grpc_tracer_flag grpc_polling_trace; +extern grpc_core::Tracer grpc_polling_trace; /* 'state' holds the to call when the fd is readable or writable respectively. 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) { while (true) { 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, state, (void *)curr, closure); } @@ -148,7 +148,7 @@ bool grpc_lfev_set_shutdown(grpc_exec_ctx *exec_ctx, gpr_atm *state, while (true) { 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, (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) { 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, (void *)curr); } diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index 799fae154cf..33bfcf824c2 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -30,7 +30,7 @@ extern "C" { #endif #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_fd_refcount; +extern grpc_core::Tracer grpc_trace_fd_refcount; #endif /* A grpc_pollset is a set of file descriptors that a higher level item is diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index b9901bf8efd..336379b457c 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -35,8 +35,8 @@ #include "src/core/lib/debug/trace.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_fd_refcount = - GRPC_TRACER_INITIALIZER(false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount + (false, "fd_refcount"); #endif struct grpc_pollset { diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index bb4df83fc13..a7df9f27bf5 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -31,8 +31,8 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #ifndef NDEBUG -grpc_tracer_flag grpc_trace_fd_refcount = - GRPC_TRACER_INITIALIZER(false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount + (false, "fd_refcount"); #endif gpr_mu grpc_polling_mu; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index ecb5747da86..966b05fd5bc 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -31,8 +31,8 @@ #include "src/core/lib/iomgr/combiner.h" -grpc_tracer_flag grpc_resource_quota_trace = - GRPC_TRACER_INITIALIZER(false, "resource_quota"); +grpc_core::Tracer grpc_resource_quota_trace + (false, "resource_quota"); #define MEMORY_USAGE_ESTIMATION_MAX 65536 @@ -294,7 +294,7 @@ static bool rq_alloc(grpc_exec_ctx *exec_ctx, while ((resource_user = rulist_pop_head(resource_quota, GRPC_RULIST_AWAITING_ALLOCATION))) { 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 " free_pool=%" PRId64, resource_user, gpr_atm_no_barrier_load(&resource_user->shutdown), @@ -319,13 +319,13 @@ static bool rq_alloc(grpc_exec_ctx *exec_ctx, resource_user->free_pool = 0; resource_quota->free_pool -= amt; 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 " bytes; rq_free_pool -> %" PRId64, resource_quota->name, resource_user->name, amt, 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) { gpr_log(GPR_DEBUG, "RQ %s %s: discard already satisfied alloc request", resource_quota->name, resource_user->name); @@ -356,7 +356,7 @@ static bool rq_reclaim_from_per_user_free_pool( resource_user->free_pool = 0; resource_quota->free_pool += amt; 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 " bytes; rq_free_pool -> %" PRId64, resource_quota->name, resource_user->name, amt, @@ -379,7 +379,7 @@ static bool rq_reclaim(grpc_exec_ctx *exec_ctx, : GRPC_RULIST_RECLAIMER_BENIGN; grpc_resource_user *resource_user = rulist_pop_head(resource_quota, list); 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", resource_quota->name, resource_user->name, destructive ? "destructive" : "benign"); @@ -513,7 +513,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) { - if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { + if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RU shutdown %p", ru); } grpc_resource_user *resource_user = (grpc_resource_user *)ru; @@ -811,7 +811,7 @@ void grpc_resource_user_alloc(grpc_exec_ctx *exec_ctx, ru_ref_by(resource_user, (gpr_atm)size); resource_user->free_pool -= (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, resource_user->resource_quota->name, resource_user->name, size, resource_user->free_pool); @@ -836,7 +836,7 @@ void grpc_resource_user_free(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&resource_user->mu); bool was_zero_or_negative = resource_user->free_pool <= 0; 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, resource_user->resource_quota->name, resource_user->name, size, resource_user->free_pool); @@ -865,7 +865,7 @@ void grpc_resource_user_post_reclaimer(grpc_exec_ctx *exec_ctx, void grpc_resource_user_finish_reclamation(grpc_exec_ctx *exec_ctx, 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", resource_user->resource_quota->name, resource_user->name); } diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 1d4249b7e29..04c80c692cb 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -65,7 +65,7 @@ extern "C" { maintain lists of users (which users arrange to leave before they are destroyed) */ -extern grpc_tracer_flag grpc_resource_quota_trace; +extern grpc_core::Tracer grpc_resource_quota_trace; grpc_resource_quota *grpc_resource_quota_ref_internal( grpc_resource_quota *resource_quota); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 5611dd90624..4ef13dd1f5e 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -43,7 +43,7 @@ #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/support/string.h" -extern grpc_tracer_flag grpc_tcp_trace; +extern grpc_core::Tracer grpc_tcp_trace; typedef struct { gpr_mu mu; @@ -99,7 +99,7 @@ done: static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { int done; 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); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, str); @@ -137,7 +137,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { GRPC_ERROR_REF(error); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s", ac->addr_str, str); @@ -317,7 +317,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx, grpc_schedule_on_exec_ctx); 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", ac->addr_str, fdobj); } diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index f3e9366299d..bebb7634b63 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -32,7 +32,7 @@ #include "src/core/lib/iomgr/tcp_uv.h" #include "src/core/lib/iomgr/timer.h" -extern grpc_tracer_flag grpc_tcp_trace; +extern grpc_core::Tracer grpc_tcp_trace; typedef struct grpc_uv_tcp_connect { 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) { int done; 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); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", 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->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", connect->addr_name); } diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 7fcaef76792..ae8d7b47240 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -61,7 +61,7 @@ typedef GRPC_MSG_IOVLEN_TYPE msg_iovlen_type; typedef size_t msg_iovlen_type; #endif -grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); +grpc_core::Tracer grpc_tcp_trace(false, "tcp"); typedef struct { 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, grpc_error *error_ignored) { 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); } 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, grpc_error *error_ignored) { 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_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_mu_lock(p->pollset_mu); 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_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); } grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p), GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, grpc_schedule_on_exec_ctx)); } else { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); } 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); gpr_atm old_count = 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, (int)old_count - 1); } @@ -180,14 +180,14 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { backup_poller *p; gpr_atm old_count = 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, 2 + (int)old_count); } if (old_count == 0) { GRPC_STATS_INC_TCP_BACKUP_POLLERS_CREATED(exec_ctx); p = (backup_poller *)gpr_malloc(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); } 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 } } - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); } 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) { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_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) { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", 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, 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)); } 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__) static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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_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); size_t i; 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, grpc_error *error) { 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, 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); if (tcp->incoming_buffer->length < target_read_size && 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); } grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, target_read_size, 1, tcp->incoming_buffer); } else { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "TCP:%p do_read", 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_tcp *tcp = (grpc_tcp *)arg; 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)); } @@ -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 (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } notify_on_write(exec_ctx, tcp); } else { cb = tcp->write_cb; tcp->write_cb = NULL; - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { const char *str = grpc_error_string(error); 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_error *error = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { size_t 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)) { TCP_REF(tcp, "write"); tcp->write_cb = cb; - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { gpr_log(GPR_DEBUG, "write: delayed"); } notify_on_write(exec_ctx, tcp); } else { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); } diff --git a/src/core/lib/iomgr/tcp_posix.h b/src/core/lib/iomgr/tcp_posix.h index 47e78fa67e6..3a515298748 100644 --- a/src/core/lib/iomgr/tcp_posix.h +++ b/src/core/lib/iomgr/tcp_posix.h @@ -37,7 +37,7 @@ extern "C" { #endif -extern grpc_tracer_flag grpc_tcp_trace; +extern grpc_core::Tracer grpc_tcp_trace; /* Create a tcp endpoint given a file desciptor and a read slice size. Takes ownership of fd. */ diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 06612d639cc..777b96eaac3 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -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); 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); } diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 348838c495c..2880fe2250e 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -213,7 +213,7 @@ static void finish_accept(grpc_exec_ctx *exec_ctx, grpc_tcp_listener *sp) { } else { 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) { gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", 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); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { 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); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { char *port_string; grpc_sockaddr_to_string(&port_string, addr, 0); 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)pollset_count; 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_ASSERT(on_accept_cb); diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index e311964dbcf..ece494065a2 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -38,7 +38,7 @@ #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" -grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); +grpc_core::Tracer grpc_tcp_trace(false, "tcp"); typedef struct { 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__) static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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); tcp->read_slice = alloc_read_slice(&exec_ctx, tcp->resource_user); error = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { size_t i; const char *str = grpc_error_string(error); 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_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); 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 { 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); 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; GRPC_UV_ASSERT_SAME_THREAD(); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { size_t 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_tcp *tcp = (grpc_tcp *)ep; if (!tcp->shutting_down) { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { const char *str = grpc_error_string(why); 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_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); } diff --git a/src/core/lib/iomgr/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h index 3399535b421..63f028173ea 100644 --- a/src/core/lib/iomgr/tcp_uv.h +++ b/src/core/lib/iomgr/tcp_uv.h @@ -34,7 +34,7 @@ #include -extern grpc_tracer_flag grpc_tcp_trace; +extern grpc_core::Tracer grpc_tcp_trace; #define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index dc84e564a9b..9024f2b743d 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -49,7 +49,7 @@ #define GRPC_FIONBIO FIONBIO #endif -grpc_tracer_flag grpc_tcp_trace = GRPC_TRACER_INITIALIZER(false, "tcp"); +grpc_core::Tracer grpc_tcp_trace(false, "tcp"); static grpc_error *set_non_block(SOCKET sock) { 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__) static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index b8e895de6f0..05984c4f90f 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -44,9 +44,9 @@ #define MAX_QUEUE_WINDOW_DURATION 1 extern "C" { -grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); -grpc_tracer_flag grpc_timer_check_trace = - GRPC_TRACER_INITIALIZER(false, "timer_check"); +grpc_core::Tracer grpc_timer_trace(false, "timer"); +grpc_core::Tracer grpc_timer_check_trace + (false, "timer_check"); } /* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with @@ -247,8 +247,8 @@ void grpc_timer_list_init(grpc_exec_ctx *exec_ctx) { g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); gpr_tls_init(&g_last_seen_min_timer); 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++) { timer_shard *shard = &g_shards[i]; @@ -331,7 +331,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer, timer->hash_table_next = NULL; #endif - if (GRPC_TRACER_ON(grpc_timer_trace)) { + if (grpc_timer_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); @@ -367,7 +367,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer, timer->heap_index = INVALID_HEAP_INDEX; 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 " => is_first_timer=%s", (int)(shard - g_shards), shard->queue_deadline_cap, @@ -388,7 +388,7 @@ void grpc_timer_init(grpc_exec_ctx *exec_ctx, grpc_timer *timer, grpc_timer_check. */ if (is_first_timer) { 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, shard->min_deadline); } @@ -418,7 +418,7 @@ void grpc_timer_cancel(grpc_exec_ctx *exec_ctx, grpc_timer *timer) { timer_shard *shard = &g_shards[GPR_HASH_POINTER(timer, NUM_SHARDS)]; 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, timer->pending ? "true" : "false"); } @@ -459,7 +459,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) { saturating_add(GPR_MAX(now, shard->queue_deadline_cap), (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, (int)(shard - g_shards), shard->queue_deadline_cap); } @@ -467,7 +467,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) { next = timer->next; 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", timer->deadline); } @@ -484,7 +484,7 @@ static int refill_heap(timer_shard *shard, gpr_atm now) { static grpc_timer *pop_one(timer_shard *shard, gpr_atm now) { grpc_timer *timer; for (;;) { - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s", (int)(shard - g_shards), grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); @@ -494,13 +494,13 @@ static grpc_timer *pop_one(timer_shard *shard, gpr_atm now) { if (!refill_heap(shard, now)) return NULL; } 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, " .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR, timer->deadline, now); } 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", timer, now - timer->deadline, timer->closure->scheduler->vtable->name); @@ -525,7 +525,7 @@ static size_t pop_timers(grpc_exec_ctx *exec_ctx, timer_shard *shard, } *new_min_deadline = compute_min_deadline(shard); 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, (int)(shard - g_shards), n); } @@ -549,7 +549,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&g_shared_mutables.mu); 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, (int)(g_shard_queue[0] - g_shards), g_shard_queue[0]->min_deadline); @@ -567,7 +567,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx *exec_ctx, result = GRPC_TIMERS_FIRED; } - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. result --> %d" ", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR @@ -612,7 +612,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx, if (next != NULL) { *next = GPR_MIN(*next, min_timer); } - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER CHECK SKIP: now=%" PRIdPTR " min_timer=%" PRIdPTR, now, min_timer); @@ -626,7 +626,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx, : GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system"); // tracing - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { char *next_str; if (next == NULL) { next_str = gpr_strdup("NULL"); @@ -643,7 +643,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx *exec_ctx, grpc_timer_check_result r = run_some_expired_timers(exec_ctx, now, next, shutdown_error); // tracing - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { char *next_str; if (next == NULL) { next_str = gpr_strdup("NULL"); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 1248f82189a..951059d43ea 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -33,7 +33,7 @@ typedef struct completed_thread { struct completed_thread *next; } completed_thread; -extern "C" grpc_tracer_flag grpc_timer_check_trace; +extern grpc_core::Tracer grpc_timer_check_trace; // global mutex static gpr_mu g_mu; @@ -81,7 +81,7 @@ static void start_timer_thread_and_unlock(void) { ++g_waiter_count; ++g_thread_count; 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_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 // waiter so that the next deadline is not missed 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_cv_signal(&g_cv_wait); @@ -123,7 +123,7 @@ static void run_some_timers(grpc_exec_ctx *exec_ctx) { gpr_mu_unlock(&g_mu); } // 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"); } 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_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); gpr_log(GPR_DEBUG, "sleep for a %" PRIdPTR " milliseconds", 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) && - next == GRPC_MILLIS_INF_FUTURE) { + if (grpc_timer_check_trace.enabled() && next == GRPC_MILLIS_INF_FUTURE) { gpr_log(GPR_DEBUG, "sleep until kicked"); } gpr_cv_wait(&g_cv_wait, &g_mu, 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", my_timed_waiter_generation == g_timed_waiter_generation, 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 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"); } next = GRPC_MILLIS_INF_FUTURE; @@ -266,7 +265,7 @@ static void timer_thread_cleanup(completed_thread *ct) { ct->next = g_completed_threads; g_completed_threads = ct; 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"); } } @@ -309,18 +308,18 @@ void grpc_timer_manager_init(void) { static void stop_threads(void) { 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); } if (g_threaded) { g_threaded = false; 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); } while (g_thread_count > 0) { 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); } gc_completed_threads(); diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index ccbbe357ae9..7ddfafd0029 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -30,9 +30,9 @@ #include extern "C" { -grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); -grpc_tracer_flag grpc_timer_check_trace = - GRPC_TRACER_INITIALIZER(false, "timer_check"); +grpc_core::Tracer grpc_timer_trace(false, "timer"); +grpc_core::Tracer grpc_timer_check_trace + (false, "timer_check"); } static void timer_close_callback(uv_handle_t *handle) { gpr_free(handle); } diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 31d800b9b46..96bec5a4c77 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -30,8 +30,8 @@ #include #ifndef NDEBUG -grpc_tracer_flag grpc_trace_auth_context_refcount = - GRPC_TRACER_INITIALIZER(false, "auth_context_refcount"); +grpc_core::Tracer grpc_trace_auth_context_refcount + (false, "auth_context_refcount"); #endif /* --- grpc_call --- */ @@ -135,7 +135,7 @@ grpc_auth_context *grpc_auth_context_ref(grpc_auth_context *ctx, const char *file, int line, const char *reason) { 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, const char *reason) { 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "AUTH_CONTEXT:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val, diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h index 0df39257a7a..f8ea0bad12a 100644 --- a/src/core/lib/security/context/security_context.h +++ b/src/core/lib/security/context/security_context.h @@ -23,7 +23,7 @@ #include "src/core/lib/security/credentials/credentials.h" #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_auth_context_refcount; +extern grpc_core::Tracer grpc_trace_auth_context_refcount; #endif #ifdef __cplusplus diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index 835dd677ed8..82d7ad5d62b 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -172,7 +172,7 @@ static char *redact_private_key(const char *json_key) { grpc_call_credentials *grpc_service_account_jwt_access_credentials_create( 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); gpr_log(GPR_INFO, "grpc_service_account_jwt_access_credentials_create(" diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index f52a424e363..8258bd7cd1e 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -467,7 +467,7 @@ grpc_call_credentials *grpc_google_refresh_token_credentials_create( const char *json_refresh_token, void *reserved) { grpc_auth_refresh_token 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); gpr_log(GPR_INFO, "grpc_refresh_token_credentials_create(json_refresh_token=%s, " diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index 8106a730fea..acff5ae7d28 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -31,8 +31,8 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/validate_metadata.h" -grpc_tracer_flag grpc_plugin_credentials_trace = - GRPC_TRACER_INITIALIZER(false, "plugin_credentials"); +grpc_core::Tracer grpc_plugin_credentials_trace + (false, "plugin_credentials"); static void plugin_destruct(grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds) { @@ -123,7 +123,7 @@ static void plugin_md_request_metadata_ready(void *request, NULL, NULL); grpc_plugin_credentials_pending_request *r = (grpc_plugin_credentials_pending_request *)request; - if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { + if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin returned " "asynchronously", @@ -136,7 +136,7 @@ static void plugin_md_request_metadata_ready(void *request, grpc_error *error = process_plugin_result(&exec_ctx, r, md, num_md, status, error_details); 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, "plugin_credentials[%p]: request %p: plugin was previously " "cancelled", @@ -172,7 +172,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx, c->pending_requests = pending_request; gpr_mu_unlock(&c->mu); // 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", c, pending_request); } @@ -185,7 +185,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx, plugin_md_request_metadata_ready, pending_request, creds_md, &num_creds_md, &status, &error_details)) { - if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { + if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin will return " "asynchronously", @@ -200,7 +200,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx, // asynchronously by plugin_cancel_get_request_metadata(), so return // false. Otherwise, process the result. if (pending_request->cancelled) { - if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { + if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p was cancelled, error " "will be returned asynchronously", @@ -208,7 +208,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx *exec_ctx, } retval = false; } else { - if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { + if (grpc_plugin_credentials_trace.enabled()) { gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: plugin returned " "synchronously", @@ -237,7 +237,7 @@ static void plugin_cancel_get_request_metadata( c->pending_requests; pending_request != NULL; pending_request = pending_request->next) { 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, pending_request); } diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.h b/src/core/lib/security/credentials/plugin/plugin_credentials.h index f56df9eac5a..9c8bc18e279 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.h +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.h @@ -21,7 +21,7 @@ #include "src/core/lib/security/credentials/credentials.h" -extern grpc_tracer_flag grpc_plugin_credentials_trace; +extern grpc_core::Tracer grpc_plugin_credentials_trace; struct grpc_plugin_credentials; diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index ae5633b82c4..901675f7a0e 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -61,8 +61,8 @@ typedef struct { gpr_refcount ref; } secure_endpoint; -grpc_tracer_flag grpc_trace_secure_endpoint = - GRPC_TRACER_INITIALIZER(false, "secure_endpoint"); +grpc_core::Tracer grpc_trace_secure_endpoint + (false, "secure_endpoint"); static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) { secure_endpoint *ep = secure_ep; @@ -86,7 +86,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, const char *reason, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val, @@ -99,7 +99,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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val, @@ -131,7 +131,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, grpc_error *error) { - if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { + if (grpc_trace_secure_endpoint.enabled()) { size_t i; for (i = 0; i < ep->read_buffer->count; i++) { char *data = grpc_dump_slice(ep->read_buffer->slices[i], @@ -270,7 +270,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); - if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { + if (grpc_trace_secure_endpoint.enabled()) { for (i = 0; i < slices->count; i++) { char *data = grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); diff --git a/src/core/lib/security/transport/secure_endpoint.h b/src/core/lib/security/transport/secure_endpoint.h index 980449c03ee..cfa1d49d8f5 100644 --- a/src/core/lib/security/transport/secure_endpoint.h +++ b/src/core/lib/security/transport/secure_endpoint.h @@ -29,7 +29,7 @@ extern "C" { struct tsi_frame_protector; struct tsi_zero_copy_grpc_protector; -extern grpc_tracer_flag grpc_trace_secure_endpoint; +extern grpc_core::Tracer grpc_trace_secure_endpoint; /* 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 diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 51844fb91f1..3d205ddefee 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -44,8 +44,8 @@ #include "src/core/tsi/transport_security_adapter.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_security_connector_refcount = - GRPC_TRACER_INITIALIZER(false, "security_connector_refcount"); +grpc_core::Tracer grpc_trace_security_connector_refcount + (false, "security_connector_refcount"); #endif /* -- Constants. -- */ @@ -164,7 +164,7 @@ grpc_security_connector *grpc_security_connector_ref( grpc_security_connector *sc, const char *file, int line, const char *reason) { 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECURITY_CONNECTOR:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", sc, @@ -185,7 +185,7 @@ void grpc_security_connector_unref(grpc_exec_ctx *exec_ctx, const char *file, int line, const char *reason) { 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECURITY_CONNECTOR:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", sc, diff --git a/src/core/lib/security/transport/security_connector.h b/src/core/lib/security/transport/security_connector.h index 4d87cd0c806..e4ee2110ebc 100644 --- a/src/core/lib/security/transport/security_connector.h +++ b/src/core/lib/security/transport/security_connector.h @@ -34,7 +34,7 @@ extern "C" { #endif #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_security_connector_refcount; +extern grpc_core::Tracer grpc_trace_security_connector_refcount; #endif /* --- status enum. --- */ diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 16a16bfd93b..721c2fcd1e9 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -28,8 +28,8 @@ #include "src/core/lib/surface/completion_queue.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_alarm_refcount = - GRPC_TRACER_INITIALIZER(false, "alarm_refcount"); +grpc_core::Tracer grpc_trace_alarm_refcount + (false, "alarm_refcount"); #endif struct grpc_alarm { @@ -59,7 +59,7 @@ static void alarm_unref(grpc_alarm *alarm) { #ifndef NDEBUG static void alarm_ref_dbg(grpc_alarm *alarm, const char *reason, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "Alarm:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, @@ -71,7 +71,7 @@ static void alarm_ref_dbg(grpc_alarm *alarm, const char *reason, static void alarm_unref_dbg(grpc_alarm *alarm, const char *reason, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "Alarm:%p Unref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, @@ -103,7 +103,7 @@ grpc_alarm *grpc_alarm_create(void *reserved) { grpc_alarm *alarm = (grpc_alarm *)gpr_malloc(sizeof(grpc_alarm)); #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); } #endif diff --git a/src/core/lib/surface/alarm_internal.h b/src/core/lib/surface/alarm_internal.h index 136b60547fa..85d5b85988f 100644 --- a/src/core/lib/surface/alarm_internal.h +++ b/src/core/lib/surface/alarm_internal.h @@ -28,7 +28,7 @@ extern "C" { #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_alarm_refcount; +extern grpc_core::Tracer grpc_trace_alarm_refcount; #define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__) #define GRPC_ALARM_UNREF(a, reason) \ diff --git a/src/core/lib/surface/api_trace.cc b/src/core/lib/surface/api_trace.cc index 56973303dab..dfddbba178a 100644 --- a/src/core/lib/surface/api_trace.cc +++ b/src/core/lib/surface/api_trace.cc @@ -19,4 +19,4 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/debug/trace.h" -grpc_tracer_flag grpc_api_trace = GRPC_TRACER_INITIALIZER(false, "api"); +grpc_core::Tracer grpc_api_trace(false, "api"); diff --git a/src/core/lib/surface/api_trace.h b/src/core/lib/surface/api_trace.h index 105abdf629d..8433175f9bc 100644 --- a/src/core/lib/surface/api_trace.h +++ b/src/core/lib/surface/api_trace.h @@ -26,7 +26,7 @@ extern "C" { #endif -extern grpc_tracer_flag grpc_api_trace; +extern grpc_core::Tracer grpc_api_trace; /* Provide unwrapping macros because we're in C89 and variadic macros weren't 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 'nargs' must be specified. */ #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); \ } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 8216aa0ec81..e2cf832c7f2 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -259,10 +259,10 @@ struct grpc_call { gpr_atm recv_state; }; -grpc_tracer_flag grpc_call_error_trace = - GRPC_TRACER_INITIALIZER(false, "call_error"); -grpc_tracer_flag grpc_compression_trace = - GRPC_TRACER_INITIALIZER(false, "compression"); +grpc_core::Tracer grpc_call_error_trace + (false, "call_error"); +grpc_core::Tracer grpc_compression_trace + (false, "compression"); #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1)) #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1) @@ -764,7 +764,7 @@ static void get_final_status(grpc_exec_ctx *exec_ctx, grpc_call *call, for (i = 0; i < STATUS_SOURCE_COUNT; 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"); for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (status[i].is_set) { @@ -1426,7 +1426,7 @@ static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, } 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_byte_stream_destroy(exec_ctx, call->receiving_stream); @@ -1530,7 +1530,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, GPR_ASSERT(call->stream_encodings_accepted_by_peer != 0); if (!GPR_BITGET(call->stream_encodings_accepted_by_peer, call->incoming_stream_compression_algorithm)) { - if (GRPC_TRACER_ON(grpc_compression_trace)) { + if (grpc_compression_trace.enabled()) { const char *algo_name = NULL; grpc_stream_compression_algorithm_name( call->incoming_stream_compression_algorithm, &algo_name); @@ -1573,7 +1573,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, GPR_ASSERT(call->encodings_accepted_by_peer != 0); if (!GPR_BITGET(call->encodings_accepted_by_peer, call->incoming_compression_algorithm)) { - if (GRPC_TRACER_ON(grpc_compression_trace)) { + if (grpc_compression_trace.enabled()) { const char *algo_name = NULL; grpc_compression_algorithm_name(call->incoming_compression_algorithm, &algo_name); diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 27c2f5243ca..ee7dc5cc165 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -102,7 +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); #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) uint8_t grpc_call_is_client(grpc_call *call); @@ -112,8 +112,8 @@ uint8_t grpc_call_is_client(grpc_call *call); grpc_compression_algorithm grpc_call_compression_for_level( grpc_call *call, grpc_compression_level level); -extern grpc_tracer_flag grpc_call_error_trace; -extern grpc_tracer_flag grpc_compression_trace; +extern grpc_core::Tracer grpc_call_error_trace; +extern grpc_core::Tracer grpc_compression_trace; #ifdef __cplusplus } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 21664f03c8b..33378516ff5 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -39,13 +39,13 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/event_string.h" -grpc_tracer_flag grpc_trace_operation_failures = - GRPC_TRACER_INITIALIZER(false, "op_failure"); +grpc_core::Tracer grpc_trace_operation_failures + (false, "op_failure"); #ifndef NDEBUG -grpc_tracer_flag grpc_trace_pending_tags = - GRPC_TRACER_INITIALIZER(false, "pending_tags"); -grpc_tracer_flag grpc_trace_cq_refcount = - GRPC_TRACER_INITIALIZER(false, "cq_refcount"); +grpc_core::Tracer grpc_trace_pending_tags + (false, "pending_tags"); +grpc_core::Tracer grpc_trace_cq_refcount + (false, "cq_refcount"); #endif typedef struct { @@ -328,14 +328,14 @@ static const cq_vtable g_cq_vtable[] = { #define POLLSET_FROM_CQ(cq) \ ((grpc_pollset *)(cq->vtable->data_size + (char *)DATA_FROM_CQ(cq))) -grpc_tracer_flag grpc_cq_pluck_trace = - GRPC_TRACER_INITIALIZER(true, "queue_pluck"); -grpc_tracer_flag grpc_cq_event_timeout_trace = - GRPC_TRACER_INITIALIZER(true, "queue_timeout"); +grpc_core::Tracer grpc_cq_pluck_trace + (true, "queue_pluck"); +grpc_core::Tracer grpc_cq_event_timeout_trace + (true, "queue_timeout"); #define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ - if (GRPC_TRACER_ON(grpc_api_trace) && \ - (GRPC_TRACER_ON(grpc_cq_pluck_trace) || \ + if (grpc_api_trace.enabled() && \ + (grpc_cq_pluck_trace.enabled() || \ (event)->type != GRPC_QUEUE_TIMEOUT)) { \ char *_ev = grpc_event_string(event); \ gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ @@ -481,7 +481,7 @@ int grpc_get_cq_poll_num(grpc_completion_queue *cq) { #ifndef NDEBUG void grpc_cq_internal_ref(grpc_completion_queue *cq, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val + 1, @@ -502,7 +502,7 @@ static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *arg, #ifndef NDEBUG void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cq, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val - 1, @@ -604,15 +604,15 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, void *done_arg, grpc_cq_completion *storage) { GPR_TIMER_BEGIN("cq_end_op_for_next", 0); - if (GRPC_TRACER_ON(grpc_api_trace) || - (GRPC_TRACER_ON(grpc_trace_operation_failures) && + if (grpc_api_trace.enabled() || + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 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) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -688,15 +688,15 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0); - if (GRPC_TRACER_ON(grpc_api_trace) || - (GRPC_TRACER_ON(grpc_trace_operation_failures) && + if (grpc_api_trace.enabled() || + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 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) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } @@ -791,7 +791,7 @@ static bool cq_is_next_finished(grpc_exec_ctx *exec_ctx, void *arg) { #ifndef NDEBUG 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_init(&v); @@ -1054,7 +1054,7 @@ static grpc_event cq_pluck(grpc_completion_queue *cq, void *tag, 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_completion_queue_pluck(" "cq=%p, tag=%p, " diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 69d144bd95c..3020091f210 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -27,13 +27,13 @@ /* These trace flags default to 1. The corresponding lines are only traced if grpc_api_trace is also truthy */ -extern grpc_tracer_flag grpc_cq_pluck_trace; -extern grpc_tracer_flag grpc_cq_event_timeout_trace; -extern grpc_tracer_flag grpc_trace_operation_failures; +extern grpc_core::Tracer grpc_cq_pluck_trace; +extern grpc_core::Tracer grpc_cq_event_timeout_trace; +extern grpc_core::Tracer grpc_trace_operation_failures; #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_pending_tags; -extern grpc_tracer_flag grpc_trace_cq_refcount; +extern grpc_core::Tracer grpc_trace_pending_tags; +extern grpc_core::Tracer grpc_trace_cq_refcount; #endif #ifdef __cplusplus diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index b089da2c54f..9ad8214a180 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -125,29 +125,29 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_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 - 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 grpc_security_pre_init(); grpc_iomgr_init(&exec_ctx); diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 8fbde3d1b4a..97adc9fdda1 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -38,11 +38,11 @@ #endif void grpc_security_pre_init(void) { - grpc_register_tracer(&grpc_trace_secure_endpoint); - grpc_register_tracer(&tsi_tracing_enabled); + + #ifndef NDEBUG - grpc_register_tracer(&grpc_trace_auth_context_refcount); - grpc_register_tracer(&grpc_trace_security_connector_refcount); + + #endif } @@ -87,5 +87,5 @@ void grpc_register_security_filters(void) { void grpc_security_init() { grpc_security_register_handshaker_factories(); - grpc_register_tracer(&grpc_plugin_credentials_trace); + } diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index dd09cb91de4..b2a35f98480 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -59,8 +59,8 @@ typedef struct registered_method registered_method; typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; -grpc_tracer_flag grpc_server_channel_trace = - GRPC_TRACER_INITIALIZER(false, "server_channel"); +grpc_core::Tracer grpc_server_channel_trace + (false, "server_channel"); typedef struct requested_call { requested_call_type type; @@ -445,7 +445,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, 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); gpr_log(GPR_INFO, "Disconnected client: %s", msg); } diff --git a/src/core/lib/surface/server.h b/src/core/lib/surface/server.h index 375eab4a048..20e6ec4eec6 100644 --- a/src/core/lib/surface/server.h +++ b/src/core/lib/surface/server.h @@ -31,7 +31,7 @@ extern "C" { extern const grpc_channel_filter grpc_server_top_filter; /** Lightweight tracing of server channel state */ -extern grpc_tracer_flag grpc_server_channel_trace; +extern grpc_core::Tracer grpc_server_channel_trace; /* Add a listener to the server: when the server starts, it will call start, and when it shuts down, it will call destroy */ diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 2a1c97c84e3..82fcb9e5624 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -23,8 +23,8 @@ #include -grpc_tracer_flag grpc_bdp_estimator_trace = - GRPC_TRACER_INITIALIZER(false, "bdp_estimator"); +grpc_core::Tracer grpc_bdp_estimator_trace + (false, "bdp_estimator"); namespace grpc_core { @@ -45,7 +45,7 @@ void BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) { double dt = (double)dt_ts.tv_sec + 1e-9 * (double)dt_ts.tv_nsec; double bw = dt > 0 ? ((double)accumulator_ / dt) : 0; 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 " dt=%lf bw=%lfMbs bw_est=%lfMbs", name_, accumulator_, estimate_, dt, bw / 125000.0, @@ -55,7 +55,7 @@ void BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) { if (accumulator_ > 2 * estimate_ / 3 && bw > bw_est_) { estimate_ = GPR_MAX(accumulator_, estimate_ * 2); 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_, estimate_); } @@ -72,7 +72,7 @@ void BdpEstimator::CompletePing(grpc_exec_ctx *exec_ctx) { } if (start_inter_ping_delay != inter_ping_delay_) { 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_, inter_ping_delay_); } diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index 6447f2d62ce..681595c34b0 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -31,7 +31,7 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/exec_ctx.h" -extern grpc_tracer_flag grpc_bdp_estimator_trace; +extern grpc_core::Tracer grpc_bdp_estimator_trace; namespace grpc_core { @@ -68,7 +68,7 @@ class BdpEstimator { // grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a // transport (but not necessarily started) 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_, accumulator_, estimate_); } @@ -81,7 +81,7 @@ class BdpEstimator { // once // the ping is on the wire 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_, accumulator_, estimate_); } diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index f328a6cdbb7..cf95a3c4694 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -24,8 +24,8 @@ #include #include -grpc_tracer_flag grpc_connectivity_state_trace = - GRPC_TRACER_INITIALIZER(false, "connectivity_state"); +grpc_core::Tracer grpc_connectivity_state_trace + (false, "connectivity_state"); const char *grpc_connectivity_state_name(grpc_connectivity_state state) { switch (state) { @@ -80,7 +80,7 @@ grpc_connectivity_state grpc_connectivity_state_check( grpc_connectivity_state cur = (grpc_connectivity_state)gpr_atm_no_barrier_load( &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, grpc_connectivity_state_name(cur)); } @@ -92,7 +92,7 @@ grpc_connectivity_state grpc_connectivity_state_get( grpc_connectivity_state cur = (grpc_connectivity_state)gpr_atm_no_barrier_load( &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, grpc_connectivity_state_name(cur)); } @@ -113,7 +113,7 @@ bool grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state cur = (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); - if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { + if (grpc_connectivity_state_trace.enabled()) { if (current == NULL) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, tracker->name, notify); @@ -167,7 +167,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx, (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); 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); gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker, tracker->name, grpc_connectivity_state_name(cur), @@ -195,7 +195,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx, while ((w = tracker->watchers) != NULL) { *w->current = state; 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, w->notify); } diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index c0ba1881484..d70c9a8480a 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -47,7 +47,7 @@ typedef struct { char *name; } grpc_connectivity_state_tracker; -extern grpc_tracer_flag grpc_connectivity_state_trace; +extern grpc_core::Tracer grpc_connectivity_state_trace; /** enum --> string conversion */ const char *grpc_connectivity_state_name(grpc_connectivity_state state); diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 5455b2481bd..a138d59f9d7 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -49,8 +49,8 @@ */ #ifndef NDEBUG -grpc_tracer_flag grpc_trace_metadata = - GRPC_TRACER_INITIALIZER(false, "metadata"); +grpc_core::Tracer grpc_trace_metadata + (false, "metadata"); #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s), __FILE__, __LINE__) @@ -149,7 +149,7 @@ static int is_mdelem_static(grpc_mdelem e) { static void ref_md_locked(mdtab_shard *shard, interned_metadata *md DEBUG_ARGS) { #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -252,7 +252,7 @@ grpc_mdelem grpc_mdelem_create( allocated->value = grpc_slice_ref_internal(value); gpr_atm_rel_store(&allocated->refcnt, 1); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(allocated->key); char *value_str = grpc_slice_to_c_string(allocated->value); gpr_log(GPR_DEBUG, "ELM ALLOC:%p:%" PRIdPTR ": '%s' = '%s'", @@ -306,7 +306,7 @@ grpc_mdelem grpc_mdelem_create( shard->elems[idx] = md; gpr_mu_init(&md->mu_user_data); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(GPR_DEBUG, "ELM NEW:%p:%" PRIdPTR ": '%s' = '%s'", (void *)md, @@ -370,7 +370,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -392,7 +392,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -422,7 +422,7 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -448,7 +448,7 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char *key_str = grpc_slice_to_c_string(md->key); char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 9f82225dc39..a70ebc49211 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -26,7 +26,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_metadata; +extern grpc_core::Tracer grpc_trace_metadata; #endif #ifdef __cplusplus diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index ab4f938e7b4..e75524d07d3 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -32,13 +32,13 @@ #include "src/core/lib/transport/transport_impl.h" #ifndef NDEBUG -grpc_tracer_flag grpc_trace_stream_refcount = - GRPC_TRACER_INITIALIZER(false, "stream_refcount"); +grpc_core::Tracer grpc_trace_stream_refcount + (false, "stream_refcount"); #endif #ifndef NDEBUG void grpc_stream_ref(grpc_stream_refcount *refcount, const char *reason) { - if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { + if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p REF %" PRIdPTR "->%" PRIdPTR " %s", refcount->object_type, refcount, refcount->destroy.cb_arg, val, @@ -53,7 +53,7 @@ void grpc_stream_ref(grpc_stream_refcount *refcount) { #ifndef NDEBUG void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount, const char *reason) { - if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { + if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p UNREF %" PRIdPTR "->%" PRIdPTR " %s", refcount->object_type, refcount, refcount->destroy.cb_arg, val, diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index fbf5dcb8b59..80464027245 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -44,7 +44,7 @@ typedef struct grpc_transport grpc_transport; typedef struct grpc_stream grpc_stream; #ifndef NDEBUG -extern grpc_tracer_flag grpc_trace_stream_refcount; +extern grpc_core::Tracer grpc_trace_stream_refcount; #endif typedef struct grpc_stream_refcount { diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 349dcf5cb8f..08628e44389 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -571,7 +571,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( if (next_message_to_send > TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { next_message_to_send = TSI_FAKE_HANDSHAKE_MESSAGE_MAX; } - if (GRPC_TRACER_ON(tsi_tracing_enabled)) { + if (tsi_tracing_enabled.enabled()) { gpr_log(GPR_INFO, "%s prepared %s.", impl->is_client ? "Client" : "Server", tsi_fake_handshake_message_to_string(impl->next_message_to_send)); @@ -583,7 +583,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( if (!impl->is_client && impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { /* We're done. */ - if (GRPC_TRACER_ON(tsi_tracing_enabled)) { + if (tsi_tracing_enabled.enabled()) { gpr_log(GPR_INFO, "Server is done."); } impl->result = TSI_OK; @@ -621,7 +621,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer( tsi_fake_handshake_message_to_string(received_msg), tsi_fake_handshake_message_to_string(expected_msg)); } - if (GRPC_TRACER_ON(tsi_tracing_enabled)) { + if (tsi_tracing_enabled.enabled()) { gpr_log(GPR_INFO, "%s received %s.", impl->is_client ? "Client" : "Server", tsi_fake_handshake_message_to_string(received_msg)); } @@ -629,7 +629,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer( impl->needs_incoming_message = 0; if (impl->next_message_to_send == TSI_FAKE_HANDSHAKE_MESSAGE_MAX) { /* We're done. */ - if (GRPC_TRACER_ON(tsi_tracing_enabled)) { + if (tsi_tracing_enabled.enabled()) { gpr_log(GPR_INFO, "%s is done.", impl->is_client ? "Client" : "Server"); } impl->result = TSI_OK; diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index b1c69e9c7b2..09d6c70ad17 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -175,7 +175,7 @@ static const char *ssl_error_string(int error) { /* TODO(jboeuf): Remove when we are past the debugging phase with this code. */ static void ssl_log_where_info(const SSL *ssl, int where, int flag, const char *msg) { - if ((where & flag) && GRPC_TRACER_ON(tsi_tracing_enabled)) { + if ((where & flag) && tsi_tracing_enabled.enabled()) { gpr_log(GPR_INFO, "%20.20s - %30.30s - %5.10s", msg, SSL_state_string_long(ssl), SSL_state_string(ssl)); } diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 21bd8eba78e..c452a0f1bfe 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -26,7 +26,7 @@ /* --- Tracing. --- */ -grpc_tracer_flag tsi_tracing_enabled = GRPC_TRACER_INITIALIZER(false, "tsi"); +grpc_core::Tracer tsi_tracing_enabled(false, "tsi"); /* --- tsi_result common implementation. --- */ diff --git a/src/core/tsi/transport_security.h b/src/core/tsi/transport_security.h index 3bba38149c8..0a3c45c4746 100644 --- a/src/core/tsi/transport_security.h +++ b/src/core/tsi/transport_security.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern grpc_tracer_flag tsi_tracing_enabled; +extern grpc_core::Tracer tsi_tracing_enabled; /* Base for tsi_frame_protector implementations. See transport_security_interface.h for documentation. */ diff --git a/src/core/tsi/transport_security_interface.h b/src/core/tsi/transport_security_interface.h index 80c426bbdbe..ebf75f36fcc 100644 --- a/src/core/tsi/transport_security_interface.h +++ b/src/core/tsi/transport_security_interface.h @@ -60,7 +60,7 @@ const char *tsi_result_to_string(tsi_result result); /* --- tsi tracing --- */ -extern grpc_tracer_flag tsi_tracing_enabled; +extern grpc_core::Tracer tsi_tracing_enabled; /* -- tsi_zero_copy_grpc_protector object -- diff --git a/test/core/iomgr/timer_list_test.c b/test/core/iomgr/timer_list_test.c index c3d9f9d88d4..f63a38850e6 100644 --- a/test/core/iomgr/timer_list_test.c +++ b/test/core/iomgr/timer_list_test.c @@ -31,8 +31,8 @@ #define MAX_CB 30 -extern grpc_tracer_flag grpc_timer_trace; -extern grpc_tracer_flag grpc_timer_check_trace; +extern grpc_core::Tracer grpc_timer_trace; +extern grpc_core::Tracer grpc_timer_check_trace; static int cb_called[MAX_CB][2]; From cdaf6d8e0660f83b708e4e73e90a4deaeab7ea2b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 16 Oct 2017 13:51:45 -0700 Subject: [PATCH 02/27] clang-format --- .../filters/client_channel/client_channel.cc | 3 +- .../client_channel/client_channel_plugin.cc | 4 +- .../ext/filters/client_channel/lb_policy.cc | 3 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 4 +- .../lb_policy/pick_first/pick_first.cc | 4 +- .../lb_policy/round_robin/round_robin.cc | 4 +- .../ext/filters/client_channel/resolver.cc | 3 +- .../ext/filters/http/http_filters_plugin.cc | 1 - .../chttp2/transport/chttp2_plugin.cc | 5 +-- .../chttp2/transport/chttp2_transport.cc | 6 +-- .../chttp2/transport/frame_settings.cc | 3 +- .../ext/transport/chttp2/transport/internal.h | 16 +++---- .../chttp2/transport/stream_lists.cc | 3 +- .../ext/transport/chttp2/transport/writing.cc | 12 ++---- .../ext/transport/inproc/inproc_transport.cc | 4 +- src/core/lib/channel/channel_stack_builder.cc | 4 +- src/core/lib/iomgr/call_combiner.cc | 3 +- src/core/lib/iomgr/combiner.cc | 13 +++--- src/core/lib/iomgr/error.cc | 3 +- src/core/lib/iomgr/ev_epollsig_linux.cc | 4 +- src/core/lib/iomgr/ev_posix.cc | 9 ++-- src/core/lib/iomgr/ev_windows.cc | 4 +- src/core/lib/iomgr/executor.cc | 4 +- src/core/lib/iomgr/iomgr_posix.cc | 1 - src/core/lib/iomgr/iomgr_uv.cc | 2 +- src/core/lib/iomgr/pollset_uv.cc | 3 +- src/core/lib/iomgr/pollset_windows.cc | 3 +- src/core/lib/iomgr/resource_quota.cc | 3 +- src/core/lib/iomgr/timer_generic.cc | 5 +-- src/core/lib/iomgr/timer_uv.cc | 3 +- .../lib/security/context/security_context.cc | 4 +- .../credentials/plugin/plugin_credentials.cc | 3 +- .../lib/security/transport/secure_endpoint.cc | 3 +- .../security/transport/security_connector.cc | 4 +- src/core/lib/surface/alarm.cc | 3 +- src/core/lib/surface/api_trace.h | 2 +- src/core/lib/surface/call.cc | 6 +-- src/core/lib/surface/call.h | 3 +- src/core/lib/surface/completion_queue.cc | 42 +++++++------------ src/core/lib/surface/init.cc | 24 +---------- src/core/lib/surface/init_secure.cc | 10 +---- src/core/lib/surface/server.cc | 3 +- src/core/lib/transport/bdp_estimator.cc | 3 +- src/core/lib/transport/connectivity_state.cc | 3 +- src/core/lib/transport/metadata.cc | 3 +- src/core/lib/transport/transport.cc | 3 +- 46 files changed, 88 insertions(+), 170 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 21ad3d9a260..8a8e76ff12a 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -55,8 +55,7 @@ /* Client channel implementation */ -grpc_core::Tracer grpc_client_channel_trace - (false, "client_channel"); +grpc_core::Tracer grpc_client_channel_trace(false, "client_channel"); /************************************************************************* * METHOD-CONFIG TABLE 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 d67e11e9769..407b8349d80 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -78,9 +78,9 @@ extern "C" 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(); - + #ifndef NDEBUG - + #endif } diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 6ce49b17e9e..738486adbbc 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -22,8 +22,7 @@ #define WEAK_REF_BITS 16 #ifndef NDEBUG -grpc_core::Tracer grpc_trace_lb_policy_refcount - (false, "lb_policy_refcount"); +grpc_core::Tracer grpc_trace_lb_policy_refcount(false, "lb_policy_refcount"); #endif void grpc_lb_policy_init(grpc_lb_policy *policy, 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 1b9e72bd24c..9ad54fabf54 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 @@ -1962,9 +1962,9 @@ static bool maybe_add_client_load_reporting_filter( extern "C" void grpc_lb_policy_grpclb_init() { grpc_register_lb_policy(grpc_glb_lb_factory_create()); - + #ifndef NDEBUG - + #endif grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, 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 8c5065cd9e5..3454ff0cbd8 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 @@ -28,8 +28,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -grpc_core::Tracer grpc_lb_pick_first_trace - (false, "pick_first"); +grpc_core::Tracer grpc_lb_pick_first_trace(false, "pick_first"); typedef struct pending_pick { struct pending_pick *next; @@ -708,7 +707,6 @@ static grpc_lb_policy_factory *pick_first_lb_factory_create() { extern "C" void grpc_lb_policy_pick_first_init() { grpc_register_lb_policy(pick_first_lb_factory_create()); - } extern "C" 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 f8c68307922..e7cf8ce6f74 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 @@ -38,8 +38,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" -grpc_core::Tracer grpc_lb_round_robin_trace - (false, "round_robin"); +grpc_core::Tracer grpc_lb_round_robin_trace(false, "round_robin"); /** List of entities waiting for a pick. * @@ -918,7 +917,6 @@ static grpc_lb_policy_factory *round_robin_lb_factory_create() { extern "C" void grpc_lb_policy_round_robin_init() { grpc_register_lb_policy(round_robin_lb_factory_create()); - } extern "C" void grpc_lb_policy_round_robin_shutdown() {} diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 1863a941626..9ce4f80e636 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -20,8 +20,7 @@ #include "src/core/lib/iomgr/combiner.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_resolver_refcount - (false, "resolver_refcount"); +grpc_core::Tracer grpc_trace_resolver_refcount(false, "resolver_refcount"); #endif void grpc_resolver_init(grpc_resolver *resolver, diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 24d46a60aeb..cbcbca1efcf 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, } extern "C" void grpc_http_filters_init(void) { - 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/transport/chttp2/transport/chttp2_plugin.cc b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc index 06059cb92ae..13c39667627 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc @@ -21,11 +21,8 @@ #include "src/core/lib/transport/metadata.h" extern "C" void grpc_chttp2_plugin_init(void) { - - - #ifndef NDEBUG - + #endif } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 664fb72e573..a1030388938 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -95,8 +95,7 @@ grpc_core::Tracer grpc_http_trace(false, "http"); grpc_core::Tracer grpc_flowctl_trace(false, "flowctl"); #ifndef NDEBUG -grpc_core::Tracer grpc_trace_chttp2_refcount - (false, "chttp2_refcount"); +grpc_core::Tracer grpc_trace_chttp2_refcount(false, "chttp2_refcount"); #endif /* forward declarations of various callbacks that we'll build closures around */ @@ -3062,8 +3061,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_resource_quota_trace.enabled()) { + } 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", diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.cc b/src/core/ext/transport/chttp2/transport/frame_settings.cc index b3fc08041f8..8ee12aeceb9 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.cc +++ b/src/core/ext/transport/chttp2/transport/frame_settings.cc @@ -204,8 +204,7 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p, parser->incoming_settings[id] != parser->value) { t->flow_control.initial_window_update += (int64_t)parser->value - parser->incoming_settings[id]; - if (grpc_http_trace.enabled() || - grpc_flowctl_trace.enabled()) { + 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->flow_control.initial_window_update); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 07dc381e0a7..55cb55de568 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -797,19 +797,19 @@ extern grpc_core::Tracer grpc_http_trace; extern grpc_core::Tracer grpc_flowctl_trace; #ifndef NDEBUG -#define GRPC_FLOW_CONTROL_IF_TRACING(stmt) \ - if (!(grpc_flowctl_trace.enabled())) \ - ; \ - else \ +#define GRPC_FLOW_CONTROL_IF_TRACING(stmt) \ + if (!(grpc_flowctl_trace.enabled())) \ + ; \ + else \ stmt #else #define GRPC_FLOW_CONTROL_IF_TRACING(stmt) #endif -#define GRPC_CHTTP2_IF_TRACING(stmt) \ - if (!(grpc_http_trace.enabled())) \ - ; \ - 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/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 3595d09a8f2..76538976b66 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_core::Tracer grpc_trace_http2_stream_state - (false, "http2_stream_state"); +grpc_core::Tracer grpc_trace_http2_stream_state(false, "http2_stream_state"); /* core list management */ diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index e3ee506e873..34c9bc334a2 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_http_trace.enabled() || - grpc_bdp_estimator_trace.enabled()) { + 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_http_trace.enabled() || - grpc_bdp_estimator_trace.enabled()) { + 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_http_trace.enabled() || - grpc_bdp_estimator_trace.enabled()) { + 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_http_trace.enabled() || - grpc_bdp_estimator_trace.enabled()) { + 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_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index 047a24c145e..c2af5fb9cda 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -32,8 +32,8 @@ #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/transport_impl.h" -#define INPROC_LOG(...) \ - do { \ +#define INPROC_LOG(...) \ + do { \ if (grpc_inproc_trace.enabled()) gpr_log(__VA_ARGS__); \ } while (0) diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 83f8113a353..3ee70a85bee 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -23,8 +23,8 @@ #include #include -grpc_core::Tracer grpc_trace_channel_stack_builder - (false, "channel_stack_builder"); +grpc_core::Tracer grpc_trace_channel_stack_builder(false, + "channel_stack_builder"); typedef struct filter_node { struct filter_node *next; diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index d36e2c5befa..48122d6b55d 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -24,8 +24,7 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/profiling/timers.h" -grpc_core::Tracer grpc_call_combiner_trace - (false, "call_combiner"); +grpc_core::Tracer grpc_call_combiner_trace(false, "call_combiner"); static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) { if (cancel_state & 1) { diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index 2d1c652041a..b77ddbffa11 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -29,14 +29,13 @@ #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/profiling/timers.h" -grpc_core::Tracer grpc_combiner_trace - (false, "combiner"); +grpc_core::Tracer grpc_combiner_trace(false, "combiner"); -#define GRPC_COMBINER_TRACE(fn) \ - do { \ +#define GRPC_COMBINER_TRACE(fn) \ + do { \ if (grpc_combiner_trace.enabled()) { \ - fn; \ - } \ + fn; \ + } \ } while (0) #define STATE_UNORPHANED 1 @@ -106,7 +105,7 @@ static void start_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock) { #ifndef NDEBUG #define GRPC_COMBINER_DEBUG_SPAM(op, delta) \ - if (grpc_combiner_trace.enabled()) { \ + if (grpc_combiner_trace.enabled()) { \ gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, \ "C:%p %s %" PRIdPTR " --> %" PRIdPTR " %s", lock, (op), \ gpr_atm_no_barrier_load(&lock->refs.count), \ diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index cbb27f442ed..578d35764fc 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -38,8 +38,7 @@ #include "src/core/lib/slice/slice_internal.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_error_refcount - (false, "error_refcount"); +grpc_core::Tracer grpc_trace_error_refcount(false, "error_refcount"); #endif static const char *error_int_name(grpc_error_ints key) { diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 648de4f7e15..ad7b27b279e 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -53,9 +53,9 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) -#define GRPC_POLLING_TRACE(...) \ +#define GRPC_POLLING_TRACE(...) \ if (grpc_polling_trace.enabled()) { \ - gpr_log(GPR_INFO, __VA_ARGS__); \ + gpr_log(GPR_INFO, __VA_ARGS__); \ } static int grpc_wakeup_signal = -1; diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 166801e229a..45403c30371 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -36,12 +36,11 @@ #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/support/env.h" -grpc_core::Tracer grpc_polling_trace - (false, "polling"); /* Disabled by default */ +grpc_core::Tracer grpc_polling_trace(false, + "polling"); /* Disabled by default */ #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount - (false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); #endif /** Default poll() function - a pointer so that it can be overridden by some @@ -156,8 +155,6 @@ const grpc_event_engine_vtable *grpc_get_event_engine_test_only() { const char *grpc_get_poll_strategy_name() { return g_poll_strategy_name; } void grpc_event_engine_init(void) { - - char *s = gpr_getenv("GRPC_POLL_STRATEGY"); if (s == NULL) { s = gpr_strdup("all"); diff --git a/src/core/lib/iomgr/ev_windows.cc b/src/core/lib/iomgr/ev_windows.cc index c9d83c09492..c2e5d55df89 100644 --- a/src/core/lib/iomgr/ev_windows.cc +++ b/src/core/lib/iomgr/ev_windows.cc @@ -22,7 +22,7 @@ #include "src/core/lib/debug/trace.h" -grpc_core::Tracer grpc_polling_trace - (false, "polling"); /* Disabled by default */ +grpc_core::Tracer grpc_polling_trace(false, + "polling"); /* Disabled by default */ #endif // GRPC_WINSOCK_SOCKET diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index bf233087d51..085c2127a13 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -51,8 +51,7 @@ static gpr_spinlock g_adding_thread_lock = GPR_SPINLOCK_STATIC_INITIALIZER; GPR_TLS_DECL(g_this_thread_state); -static grpc_core::Tracer executor_trace - (false, "executor"); +static grpc_core::Tracer executor_trace(false, "executor"); static void executor_thread(void *arg); @@ -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) { - gpr_atm_no_barrier_store(&g_cur_threads, 0); grpc_executor_set_threading(exec_ctx, true); } diff --git a/src/core/lib/iomgr/iomgr_posix.cc b/src/core/lib/iomgr/iomgr_posix.cc index 3135b1d5632..f8f6fe23536 100644 --- a/src/core/lib/iomgr/iomgr_posix.cc +++ b/src/core/lib/iomgr/iomgr_posix.cc @@ -28,7 +28,6 @@ void grpc_iomgr_platform_init(void) { grpc_wakeup_fd_global_init(); grpc_event_engine_init(); - } void grpc_iomgr_platform_flush(void) {} diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index d63829b8b12..b8a10f2ae88 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -31,7 +31,7 @@ gpr_thd_id g_init_thread; void grpc_iomgr_platform_init(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_pollset_global_init(); - + grpc_executor_set_threading(&exec_ctx, false); g_init_thread = gpr_thd_currentid(); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index 336379b457c..cf3566d08fe 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -35,8 +35,7 @@ #include "src/core/lib/debug/trace.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount - (false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); #endif struct grpc_pollset { diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index a7df9f27bf5..d0d299b6b7f 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -31,8 +31,7 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount - (false, "fd_refcount"); +grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); #endif gpr_mu grpc_polling_mu; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 966b05fd5bc..d3ed87a1c03 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -31,8 +31,7 @@ #include "src/core/lib/iomgr/combiner.h" -grpc_core::Tracer grpc_resource_quota_trace - (false, "resource_quota"); +grpc_core::Tracer grpc_resource_quota_trace(false, "resource_quota"); #define MEMORY_USAGE_ESTIMATION_MAX 65536 diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 05984c4f90f..98b4ca22ab4 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -45,8 +45,7 @@ extern "C" { grpc_core::Tracer grpc_timer_trace(false, "timer"); -grpc_core::Tracer grpc_timer_check_trace - (false, "timer_check"); +grpc_core::Tracer grpc_timer_check_trace(false, "timer_check"); } /* 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); gpr_tls_init(&g_last_seen_min_timer); gpr_tls_set(&g_last_seen_min_timer, 0); - - for (i = 0; i < NUM_SHARDS; i++) { timer_shard *shard = &g_shards[i]; diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 7ddfafd0029..a64269585cf 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -31,8 +31,7 @@ extern "C" { grpc_core::Tracer grpc_timer_trace(false, "timer"); -grpc_core::Tracer grpc_timer_check_trace - (false, "timer_check"); +grpc_core::Tracer grpc_timer_check_trace(false, "timer_check"); } static void timer_close_callback(uv_handle_t *handle) { gpr_free(handle); } diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 96bec5a4c77..39f92fe595f 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -30,8 +30,8 @@ #include #ifndef NDEBUG -grpc_core::Tracer grpc_trace_auth_context_refcount - (false, "auth_context_refcount"); +grpc_core::Tracer grpc_trace_auth_context_refcount(false, + "auth_context_refcount"); #endif /* --- grpc_call --- */ diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index acff5ae7d28..cf032410168 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -31,8 +31,7 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/validate_metadata.h" -grpc_core::Tracer grpc_plugin_credentials_trace - (false, "plugin_credentials"); +grpc_core::Tracer grpc_plugin_credentials_trace(false, "plugin_credentials"); static void plugin_destruct(grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds) { diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index 901675f7a0e..e2772980cd0 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -61,8 +61,7 @@ typedef struct { gpr_refcount ref; } secure_endpoint; -grpc_core::Tracer grpc_trace_secure_endpoint - (false, "secure_endpoint"); +grpc_core::Tracer grpc_trace_secure_endpoint(false, "secure_endpoint"); static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) { secure_endpoint *ep = secure_ep; diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 3d205ddefee..3c19d5e60a5 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -44,8 +44,8 @@ #include "src/core/tsi/transport_security_adapter.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_security_connector_refcount - (false, "security_connector_refcount"); +grpc_core::Tracer grpc_trace_security_connector_refcount( + false, "security_connector_refcount"); #endif /* -- Constants. -- */ diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 721c2fcd1e9..6bab0be8499 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -28,8 +28,7 @@ #include "src/core/lib/surface/completion_queue.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_alarm_refcount - (false, "alarm_refcount"); +grpc_core::Tracer grpc_trace_alarm_refcount(false, "alarm_refcount"); #endif struct grpc_alarm { diff --git a/src/core/lib/surface/api_trace.h b/src/core/lib/surface/api_trace.h index 8433175f9bc..044ed9b6ecb 100644 --- a/src/core/lib/surface/api_trace.h +++ b/src/core/lib/surface/api_trace.h @@ -47,7 +47,7 @@ extern grpc_core::Tracer grpc_api_trace; /* Due to the limitations of C89's preprocessor, the arity of the var-arg list 'nargs' must be specified. */ #define GRPC_API_TRACE(fmt, nargs, args) \ - if (grpc_api_trace.enabled()) { \ + if (grpc_api_trace.enabled()) { \ gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \ } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index e2cf832c7f2..21a0285e1ca 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -259,10 +259,8 @@ struct grpc_call { gpr_atm recv_state; }; -grpc_core::Tracer grpc_call_error_trace - (false, "call_error"); -grpc_core::Tracer grpc_compression_trace - (false, "compression"); +grpc_core::Tracer grpc_call_error_trace(false, "call_error"); +grpc_core::Tracer grpc_compression_trace(false, "compression"); #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1)) #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1) diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index ee7dc5cc165..f00cf0503b2 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -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); #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \ - if (grpc_api_trace.enabled()) \ - grpc_call_log_batch(sev, call, ops, nops, tag) + if (grpc_api_trace.enabled()) grpc_call_log_batch(sev, call, ops, nops, tag) uint8_t grpc_call_is_client(grpc_call *call); diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 33378516ff5..c0ef8a8a1ca 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -39,13 +39,10 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/event_string.h" -grpc_core::Tracer grpc_trace_operation_failures - (false, "op_failure"); +grpc_core::Tracer grpc_trace_operation_failures(false, "op_failure"); #ifndef NDEBUG -grpc_core::Tracer grpc_trace_pending_tags - (false, "pending_tags"); -grpc_core::Tracer grpc_trace_cq_refcount - (false, "cq_refcount"); +grpc_core::Tracer grpc_trace_pending_tags(false, "pending_tags"); +grpc_core::Tracer grpc_trace_cq_refcount(false, "cq_refcount"); #endif typedef struct { @@ -328,18 +325,15 @@ static const cq_vtable g_cq_vtable[] = { #define POLLSET_FROM_CQ(cq) \ ((grpc_pollset *)(cq->vtable->data_size + (char *)DATA_FROM_CQ(cq))) -grpc_core::Tracer grpc_cq_pluck_trace - (true, "queue_pluck"); -grpc_core::Tracer grpc_cq_event_timeout_trace - (true, "queue_timeout"); - -#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ - if (grpc_api_trace.enabled() && \ - (grpc_cq_pluck_trace.enabled() || \ - (event)->type != GRPC_QUEUE_TIMEOUT)) { \ - char *_ev = grpc_event_string(event); \ - gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ - gpr_free(_ev); \ +grpc_core::Tracer grpc_cq_pluck_trace(true, "queue_pluck"); +grpc_core::Tracer grpc_cq_event_timeout_trace(true, "queue_timeout"); + +#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ + if (grpc_api_trace.enabled() && (grpc_cq_pluck_trace.enabled() || \ + (event)->type != GRPC_QUEUE_TIMEOUT)) { \ + char *_ev = grpc_event_string(event); \ + gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ + gpr_free(_ev); \ } static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *cq, @@ -605,15 +599,13 @@ static void cq_end_op_for_next(grpc_exec_ctx *exec_ctx, GPR_TIMER_BEGIN("cq_end_op_for_next", 0); if (grpc_api_trace.enabled() || - (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE)) { + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); - if (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE) { + if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } @@ -689,15 +681,13 @@ static void cq_end_op_for_pluck(grpc_exec_ctx *exec_ctx, GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0); if (grpc_api_trace.enabled() || - (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE)) { + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char *errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); - if (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE) { + if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 9ad8214a180..2db761b4dcf 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -125,29 +125,9 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); - - - - - - - - - - - - - - + #ifndef NDEBUG - - - - - - - - + #endif grpc_security_pre_init(); grpc_iomgr_init(&exec_ctx); diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 97adc9fdda1..80b1fe022f5 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -38,11 +38,8 @@ #endif void grpc_security_pre_init(void) { - - #ifndef NDEBUG - - + #endif } @@ -85,7 +82,4 @@ void grpc_register_security_filters(void) { maybe_prepend_server_auth_filter, NULL); } -void grpc_security_init() { - grpc_security_register_handshaker_factories(); - -} +void grpc_security_init() { grpc_security_register_handshaker_factories(); } diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index b2a35f98480..081fa54f168 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -59,8 +59,7 @@ typedef struct registered_method registered_method; typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; -grpc_core::Tracer grpc_server_channel_trace - (false, "server_channel"); +grpc_core::Tracer grpc_server_channel_trace(false, "server_channel"); typedef struct requested_call { requested_call_type type; diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 82fcb9e5624..6eb2f54864c 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -23,8 +23,7 @@ #include -grpc_core::Tracer grpc_bdp_estimator_trace - (false, "bdp_estimator"); +grpc_core::Tracer grpc_bdp_estimator_trace(false, "bdp_estimator"); namespace grpc_core { diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index cf95a3c4694..f9e81855553 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -24,8 +24,7 @@ #include #include -grpc_core::Tracer grpc_connectivity_state_trace - (false, "connectivity_state"); +grpc_core::Tracer grpc_connectivity_state_trace(false, "connectivity_state"); const char *grpc_connectivity_state_name(grpc_connectivity_state state) { switch (state) { diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index a138d59f9d7..99eccba34e9 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -49,8 +49,7 @@ */ #ifndef NDEBUG -grpc_core::Tracer grpc_trace_metadata - (false, "metadata"); +grpc_core::Tracer grpc_trace_metadata(false, "metadata"); #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s), __FILE__, __LINE__) diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index e75524d07d3..4055e9c881a 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -32,8 +32,7 @@ #include "src/core/lib/transport/transport_impl.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_stream_refcount - (false, "stream_refcount"); +grpc_core::Tracer grpc_trace_stream_refcount(false, "stream_refcount"); #endif #ifndef NDEBUG From 694580faee3a3bb91f9922a1d04125aa48f50bd5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 18 Oct 2017 14:48:14 -0700 Subject: [PATCH 03/27] Better name --- include/grpc/grpc.h | 2 +- .../ext/filters/client_channel/client_channel.cc | 2 +- .../ext/filters/client_channel/client_channel.h | 2 +- src/core/ext/filters/client_channel/lb_policy.cc | 2 +- src/core/ext/filters/client_channel/lb_policy.h | 2 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 2 +- .../lb_policy/pick_first/pick_first.cc | 2 +- .../lb_policy/round_robin/round_robin.cc | 2 +- src/core/ext/filters/client_channel/resolver.cc | 2 +- src/core/ext/filters/client_channel/resolver.h | 2 +- .../chttp2/transport/chttp2_transport.cc | 6 +++--- .../chttp2/transport/chttp2_transport.h | 8 ++++---- .../transport/chttp2/transport/hpack_encoder.cc | 2 +- .../transport/chttp2/transport/hpack_table.cc | 2 +- .../ext/transport/chttp2/transport/internal.h | 4 ++-- .../transport/chttp2/transport/stream_lists.cc | 2 +- src/core/ext/transport/inproc/inproc_plugin.cc | 2 +- src/core/ext/transport/inproc/inproc_transport.h | 2 +- src/core/lib/channel/channel_stack.cc | 2 +- src/core/lib/channel/channel_stack.h | 2 +- src/core/lib/channel/channel_stack_builder.cc | 2 +- src/core/lib/channel/channel_stack_builder.h | 2 +- src/core/lib/debug/trace.cc | 16 ++++++++-------- src/core/lib/debug/trace.h | 10 +++++----- src/core/lib/http/parser.cc | 2 +- src/core/lib/http/parser.h | 2 +- src/core/lib/iomgr/call_combiner.cc | 2 +- src/core/lib/iomgr/call_combiner.h | 2 +- src/core/lib/iomgr/closure.cc | 2 +- src/core/lib/iomgr/closure.h | 2 +- src/core/lib/iomgr/combiner.cc | 2 +- src/core/lib/iomgr/combiner.h | 2 +- src/core/lib/iomgr/error.cc | 2 +- src/core/lib/iomgr/error.h | 2 +- src/core/lib/iomgr/ev_epollex_linux.cc | 2 +- src/core/lib/iomgr/ev_posix.cc | 4 ++-- src/core/lib/iomgr/ev_posix.h | 2 +- src/core/lib/iomgr/ev_windows.cc | 2 +- src/core/lib/iomgr/executor.cc | 2 +- src/core/lib/iomgr/lockfree_event.cc | 2 +- src/core/lib/iomgr/pollset.h | 2 +- src/core/lib/iomgr/pollset_uv.cc | 2 +- src/core/lib/iomgr/pollset_windows.cc | 2 +- src/core/lib/iomgr/resource_quota.cc | 2 +- src/core/lib/iomgr/resource_quota.h | 2 +- src/core/lib/iomgr/tcp_client_posix.cc | 2 +- src/core/lib/iomgr/tcp_client_uv.cc | 2 +- src/core/lib/iomgr/tcp_posix.cc | 2 +- src/core/lib/iomgr/tcp_posix.h | 2 +- src/core/lib/iomgr/tcp_uv.cc | 2 +- src/core/lib/iomgr/tcp_uv.h | 2 +- src/core/lib/iomgr/tcp_windows.cc | 2 +- src/core/lib/iomgr/timer_generic.cc | 4 ++-- src/core/lib/iomgr/timer_manager.cc | 2 +- src/core/lib/iomgr/timer_uv.cc | 4 ++-- .../lib/security/context/security_context.cc | 2 +- src/core/lib/security/context/security_context.h | 2 +- .../credentials/plugin/plugin_credentials.cc | 2 +- .../credentials/plugin/plugin_credentials.h | 2 +- .../lib/security/transport/secure_endpoint.cc | 2 +- .../lib/security/transport/secure_endpoint.h | 2 +- .../lib/security/transport/security_connector.cc | 2 +- .../lib/security/transport/security_connector.h | 2 +- src/core/lib/surface/alarm.cc | 2 +- src/core/lib/surface/alarm_internal.h | 2 +- src/core/lib/surface/api_trace.cc | 2 +- src/core/lib/surface/api_trace.h | 2 +- src/core/lib/surface/call.cc | 4 ++-- src/core/lib/surface/call.h | 4 ++-- src/core/lib/surface/completion_queue.cc | 10 +++++----- src/core/lib/surface/completion_queue.h | 10 +++++----- src/core/lib/surface/server.cc | 2 +- src/core/lib/surface/server.h | 2 +- src/core/lib/transport/bdp_estimator.cc | 2 +- src/core/lib/transport/bdp_estimator.h | 2 +- src/core/lib/transport/connectivity_state.cc | 2 +- src/core/lib/transport/connectivity_state.h | 2 +- src/core/lib/transport/metadata.cc | 2 +- src/core/lib/transport/metadata.h | 2 +- src/core/lib/transport/transport.cc | 2 +- src/core/lib/transport/transport.h | 2 +- src/core/tsi/transport_security.cc | 2 +- src/core/tsi/transport_security.h | 2 +- src/core/tsi/transport_security_interface.h | 2 +- 84 files changed, 114 insertions(+), 114 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 1de289fba45..bc8d95fa4ce 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -411,7 +411,7 @@ GRPCAPI void grpc_server_destroy(grpc_server *server); /** 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 tracking down problems in the field. diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 8a8e76ff12a..70209a50209 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -55,7 +55,7 @@ /* Client channel implementation */ -grpc_core::Tracer grpc_client_channel_trace(false, "client_channel"); +grpc_core::TraceFlag grpc_client_channel_trace(false, "client_channel"); /************************************************************************* * METHOD-CONFIG TABLE diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index b5d095fe5f4..d78e7a798ca 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_core::Tracer 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/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 738486adbbc..316377b8453 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -22,7 +22,7 @@ #define WEAK_REF_BITS 16 #ifndef NDEBUG -grpc_core::Tracer grpc_trace_lb_policy_refcount(false, "lb_policy_refcount"); +grpc_core::TraceFlag grpc_trace_lb_policy_refcount(false, "lb_policy_refcount"); #endif void grpc_lb_policy_init(grpc_lb_policy *policy, diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 0fcb2ef17be..710c9d9f389 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -34,7 +34,7 @@ typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable; typedef struct grpc_lb_policy_args grpc_lb_policy_args; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_lb_policy_refcount; +extern grpc_core::TraceFlag grpc_trace_lb_policy_refcount; #endif struct grpc_lb_policy { 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 9ad54fabf54..eb699af6da4 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_core::Tracer grpc_lb_glb_trace(false, "glb"); +grpc_core::TraceFlag grpc_lb_glb_trace(false, "glb"); /* add lb_token of selected subchannel (address) to the call's initial * metadata */ 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 3454ff0cbd8..831b78f345d 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 @@ -28,7 +28,7 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" -grpc_core::Tracer grpc_lb_pick_first_trace(false, "pick_first"); +grpc_core::TraceFlag grpc_lb_pick_first_trace(false, "pick_first"); typedef struct pending_pick { struct pending_pick *next; 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 e7cf8ce6f74..911df134cbd 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 @@ -38,7 +38,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" -grpc_core::Tracer grpc_lb_round_robin_trace(false, "round_robin"); +grpc_core::TraceFlag grpc_lb_round_robin_trace(false, "round_robin"); /** List of entities waiting for a pick. * diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 9ce4f80e636..93dd834fb2e 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -20,7 +20,7 @@ #include "src/core/lib/iomgr/combiner.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_resolver_refcount(false, "resolver_refcount"); +grpc_core::TraceFlag grpc_trace_resolver_refcount(false, "resolver_refcount"); #endif void grpc_resolver_init(grpc_resolver *resolver, diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 990e9737e92..3ff787acca4 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -30,7 +30,7 @@ typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver_vtable grpc_resolver_vtable; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_resolver_refcount; +extern grpc_core::TraceFlag grpc_trace_resolver_refcount; #endif /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index ae352d5d7a0..19fdcc91508 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -90,11 +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; #define MAX_CLIENT_STREAM_ID 0x7fffffffu -grpc_core::Tracer grpc_http_trace(false, "http"); -grpc_core::Tracer grpc_flowctl_trace(false, "flowctl"); +grpc_core::TraceFlag grpc_http_trace(false, "http"); +grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl"); #ifndef NDEBUG -grpc_core::Tracer grpc_trace_chttp2_refcount(false, "chttp2_refcount"); +grpc_core::TraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); #endif /* forward declarations of various callbacks that we'll build closures around */ diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index 08c22181a75..408759a2925 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -27,12 +27,12 @@ extern "C" { #endif -extern grpc_core::Tracer grpc_http_trace; -extern grpc_core::Tracer grpc_flowctl_trace; -extern grpc_core::Tracer grpc_trace_http2_stream_state; +extern grpc_core::TraceFlag grpc_http_trace; +extern grpc_core::TraceFlag grpc_flowctl_trace; +extern grpc_core::TraceFlag grpc_trace_http2_stream_state; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_chttp2_refcount; +extern grpc_core::TraceFlag grpc_trace_chttp2_refcount; #endif grpc_transport *grpc_create_chttp2_transport( diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index ddb75fc9e73..c380869fc64 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -57,7 +57,7 @@ static const grpc_slice terminal_slice = { {{0, 0}} /* data.refcounted */ }; -extern grpc_core::Tracer grpc_http_trace; +extern grpc_core::TraceFlag grpc_http_trace; typedef struct { int is_first_frame; diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 66bd87c94e3..1cb8c0a85ba 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 grpc_core::Tracer grpc_http_trace; +extern grpc_core::TraceFlag grpc_http_trace; static struct { const char *key; diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index f1d1334e84d..6ef32958e02 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -678,8 +678,8 @@ 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_core::Tracer grpc_http_trace; -extern grpc_core::Tracer 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))) \ diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 76538976b66..f2acdd4165f 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -39,7 +39,7 @@ static const char *stream_list_id_string(grpc_chttp2_stream_list_id id) { GPR_UNREACHABLE_CODE(return "unknown"); } -grpc_core::Tracer grpc_trace_http2_stream_state(false, "http2_stream_state"); +grpc_core::TraceFlag grpc_trace_http2_stream_state(false, "http2_stream_state"); /* core list management */ diff --git a/src/core/ext/transport/inproc/inproc_plugin.cc b/src/core/ext/transport/inproc/inproc_plugin.cc index 8e0203b5ed4..2526dbfa063 100644 --- a/src/core/ext/transport/inproc/inproc_plugin.cc +++ b/src/core/ext/transport/inproc/inproc_plugin.cc @@ -19,7 +19,7 @@ #include "src/core/ext/transport/inproc/inproc_transport.h" #include "src/core/lib/debug/trace.h" -grpc_core::Tracer grpc_inproc_trace(false, "inproc"); +grpc_core::TraceFlag grpc_inproc_trace(false, "inproc"); extern "C" void grpc_inproc_plugin_init(void) { grpc_inproc_transport_init(); } diff --git a/src/core/ext/transport/inproc/inproc_transport.h b/src/core/ext/transport/inproc/inproc_transport.h index 8fd8caf4029..248a9dd54eb 100644 --- a/src/core/ext/transport/inproc/inproc_transport.h +++ b/src/core/ext/transport/inproc/inproc_transport.h @@ -29,7 +29,7 @@ grpc_channel *grpc_inproc_channel_create(grpc_server *server, grpc_channel_args *args, void *reserved); -extern grpc_core::Tracer grpc_inproc_trace; +extern grpc_core::TraceFlag grpc_inproc_trace; void grpc_inproc_transport_init(void); void grpc_inproc_transport_shutdown(void); diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 5201d6bf3d7..1e48d1c5e98 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -23,7 +23,7 @@ #include #include -grpc_core::Tracer grpc_trace_channel(false, "channel"); +grpc_core::TraceFlag grpc_trace_channel(false, "channel"); /* Memory layouts. diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 01d6310428f..0796d6f17c4 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -285,7 +285,7 @@ void grpc_call_log_op(const char *file, int line, gpr_log_severity severity, grpc_call_element *elem, grpc_transport_stream_op_batch *op); -extern grpc_core::Tracer grpc_trace_channel; +extern grpc_core::TraceFlag grpc_trace_channel; #define GRPC_CALL_LOG_OP(sev, elem, op) \ if (grpc_trace_channel.enabled()) grpc_call_log_op(sev, elem, op) diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 3ee70a85bee..f01650bd1bc 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -23,7 +23,7 @@ #include #include -grpc_core::Tracer grpc_trace_channel_stack_builder(false, +grpc_core::TraceFlag grpc_trace_channel_stack_builder(false, "channel_stack_builder"); typedef struct filter_node { diff --git a/src/core/lib/channel/channel_stack_builder.h b/src/core/lib/channel/channel_stack_builder.h index d790cf9a637..981be90f685 100644 --- a/src/core/lib/channel/channel_stack_builder.h +++ b/src/core/lib/channel/channel_stack_builder.h @@ -160,7 +160,7 @@ grpc_error *grpc_channel_stack_builder_finish( void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder); -extern grpc_core::Tracer grpc_trace_channel_stack_builder; +extern grpc_core::TraceFlag grpc_trace_channel_stack_builder; #ifdef __cplusplus } diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 5953be641ad..52cfbe52ea3 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -29,21 +29,21 @@ int grpc_tracer_set_enabled(const char *name, int enabled); namespace grpc_core { -Tracer::Tracer(bool default_enabled, const char *name) +TraceFlag::TraceFlag(bool default_enabled, const char *name) : next_tracer_(root_tracer_), name_(name), value_(default_enabled) { root_tracer_ = this; } -void Tracer::List() { +void TraceFlag::List() { gpr_log(GPR_DEBUG, "available tracers:"); - Tracer *t; + TraceFlag *t; for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { gpr_log(GPR_DEBUG, "\t%s", t->name_); } } -bool Tracer::Set(const char *name, bool enabled) { - Tracer *t; +bool TraceFlag::Set(const char *name, bool enabled) { + TraceFlag *t; if (0 == strcmp(name, "all")) { for (t = root_tracer_; t; t = t->next_tracer_) { t->set_enabled(enabled); @@ -107,9 +107,9 @@ static void parse(const char *s) { for (i = 0; i < nstrings; i++) { if (strings[i][0] == '-') { - grpc_core::Tracer::Set(strings[i] + 1, false); + grpc_core::TraceFlag::Set(strings[i] + 1, false); } else { - grpc_core::Tracer::Set(strings[i], true); + grpc_core::TraceFlag::Set(strings[i], true); } } @@ -130,5 +130,5 @@ void grpc_tracer_init(const char *env_var) { void grpc_tracer_shutdown(void) {} int grpc_tracer_set_enabled(const char *name, int enabled) { - return grpc_core::Tracer::Set(name, enabled != 0); + return grpc_core::TraceFlag::Set(name, enabled != 0); } diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index c9ce850d3ff..c09aa017035 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -44,10 +44,10 @@ void grpc_tracer_shutdown(void); namespace grpc_core { -class Tracer { +class TraceFlag { public: - Tracer(bool default_enabled, const char *name); - ~Tracer(); + TraceFlag(bool default_enabled, const char *name); + ~TraceFlag(); static bool Set(const char *tracer, bool enabled); @@ -70,8 +70,8 @@ class Tracer { #endif } - static Tracer *root_tracer_; - Tracer *next_tracer_; + static TraceFlag *root_tracer_; + TraceFlag *next_tracer_; const char *const name_; #ifdef GRPC_THREADSAFE_TRACER gpr_atm value_; diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index f272df11ddc..720e8e85ee3 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -25,7 +25,7 @@ #include #include -grpc_core::Tracer grpc_http1_trace(false, "http1"); +grpc_core::TraceFlag grpc_http1_trace(false, "http1"); static char *buf2str(void *buffer, size_t length) { char *out = (char *)gpr_malloc(length + 1); diff --git a/src/core/lib/http/parser.h b/src/core/lib/http/parser.h index b6efeda28a6..044f159f736 100644 --- a/src/core/lib/http/parser.h +++ b/src/core/lib/http/parser.h @@ -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_response_destroy(grpc_http_response *response); -extern grpc_core::Tracer grpc_http1_trace; +extern grpc_core::TraceFlag grpc_http1_trace; #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index 48122d6b55d..752303e260e 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -24,7 +24,7 @@ #include "src/core/lib/debug/stats.h" #include "src/core/lib/profiling/timers.h" -grpc_core::Tracer grpc_call_combiner_trace(false, "call_combiner"); +grpc_core::TraceFlag grpc_call_combiner_trace(false, "call_combiner"); static grpc_error* decode_cancel_state_error(gpr_atm cancel_state) { if (cancel_state & 1) { diff --git a/src/core/lib/iomgr/call_combiner.h b/src/core/lib/iomgr/call_combiner.h index 463501a6603..77420fa3e0a 100644 --- a/src/core/lib/iomgr/call_combiner.h +++ b/src/core/lib/iomgr/call_combiner.h @@ -40,7 +40,7 @@ extern "C" { // when it is done with the action that was kicked off by the original // callback. -extern grpc_core::Tracer grpc_call_combiner_trace; +extern grpc_core::TraceFlag grpc_call_combiner_trace; typedef struct { gpr_atm size; // size_t, num closures in queue or currently executing diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc index b2dfdbc207b..8639c2b7d20 100644 --- a/src/core/lib/iomgr/closure.cc +++ b/src/core/lib/iomgr/closure.cc @@ -25,7 +25,7 @@ #include "src/core/lib/profiling/timers.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_closure(false, "closure"); +grpc_core::TraceFlag grpc_trace_closure(false, "closure"); #endif #ifndef NDEBUG diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index ae946072ce4..66484a210f6 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -34,7 +34,7 @@ struct grpc_closure; typedef struct grpc_closure grpc_closure; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_closure; +extern grpc_core::TraceFlag grpc_trace_closure; #endif typedef struct grpc_closure_list { diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index b77ddbffa11..30e3b9111f9 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -29,7 +29,7 @@ #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/profiling/timers.h" -grpc_core::Tracer grpc_combiner_trace(false, "combiner"); +grpc_core::TraceFlag grpc_combiner_trace(false, "combiner"); #define GRPC_COMBINER_TRACE(fn) \ do { \ diff --git a/src/core/lib/iomgr/combiner.h b/src/core/lib/iomgr/combiner.h index 5f80e1de271..8eeb0df06ab 100644 --- a/src/core/lib/iomgr/combiner.h +++ b/src/core/lib/iomgr/combiner.h @@ -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); -extern grpc_core::Tracer grpc_combiner_trace; +extern grpc_core::TraceFlag grpc_combiner_trace; #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 578d35764fc..898a18cb9e7 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -38,7 +38,7 @@ #include "src/core/lib/slice/slice_internal.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_error_refcount(false, "error_refcount"); +grpc_core::TraceFlag grpc_trace_error_refcount(false, "error_refcount"); #endif static const char *error_int_name(grpc_error_ints key) { diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 0d91006a90d..d4050c11382 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -39,7 +39,7 @@ extern "C" { typedef struct grpc_error grpc_error; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_error_refcount; +extern grpc_core::TraceFlag grpc_trace_error_refcount; #endif typedef enum { diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index d30ca3fd5ee..bdcaf926b4e 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -58,7 +58,7 @@ #define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5 #ifndef NDEBUG -grpc_core::Tracer grpc_trace_pollable_refcount(false, "pollable_refcount"); +grpc_core::TraceFlag grpc_trace_pollable_refcount(false, "pollable_refcount"); #endif /******************************************************************************* diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 28e4efa011d..87fcfd2e04b 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -36,11 +36,11 @@ #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/support/env.h" -grpc_core::Tracer grpc_polling_trace(false, +grpc_core::TraceFlag grpc_polling_trace(false, "polling"); /* Disabled by default */ #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); +grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); #endif /** Default poll() function - a pointer so that it can be overridden by some diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index 1f585259c11..d4d6d98cae0 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -31,7 +31,7 @@ extern "C" { #endif -extern grpc_core::Tracer grpc_polling_trace; /* Disabled by default */ +extern grpc_core::TraceFlag grpc_polling_trace; /* Disabled by default */ typedef struct grpc_fd grpc_fd; diff --git a/src/core/lib/iomgr/ev_windows.cc b/src/core/lib/iomgr/ev_windows.cc index c2e5d55df89..cb66de0a06b 100644 --- a/src/core/lib/iomgr/ev_windows.cc +++ b/src/core/lib/iomgr/ev_windows.cc @@ -22,7 +22,7 @@ #include "src/core/lib/debug/trace.h" -grpc_core::Tracer grpc_polling_trace(false, +grpc_core::TraceFlag grpc_polling_trace(false, "polling"); /* Disabled by default */ #endif // GRPC_WINSOCK_SOCKET diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 085c2127a13..59c78183478 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -51,7 +51,7 @@ static gpr_spinlock g_adding_thread_lock = GPR_SPINLOCK_STATIC_INITIALIZER; GPR_TLS_DECL(g_this_thread_state); -static grpc_core::Tracer executor_trace(false, "executor"); +static grpc_core::TraceFlag executor_trace(false, "executor"); static void executor_thread(void *arg); diff --git a/src/core/lib/iomgr/lockfree_event.cc b/src/core/lib/iomgr/lockfree_event.cc index 27e720d2191..a4aeacccf9b 100644 --- a/src/core/lib/iomgr/lockfree_event.cc +++ b/src/core/lib/iomgr/lockfree_event.cc @@ -22,7 +22,7 @@ #include "src/core/lib/debug/trace.h" -extern grpc_core::Tracer grpc_polling_trace; +extern grpc_core::TraceFlag grpc_polling_trace; /* 'state' holds the to call when the fd is readable or writable respectively. It can contain one of the following values: diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index 33bfcf824c2..d48f7f8574b 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -30,7 +30,7 @@ extern "C" { #endif #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_fd_refcount; +extern grpc_core::TraceFlag grpc_trace_fd_refcount; #endif /* A grpc_pollset is a set of file descriptors that a higher level item is diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index cf3566d08fe..2016d5d808c 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -35,7 +35,7 @@ #include "src/core/lib/debug/trace.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); +grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); #endif struct grpc_pollset { diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index d0d299b6b7f..88354991d5d 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -31,7 +31,7 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #ifndef NDEBUG -grpc_core::Tracer grpc_trace_fd_refcount(false, "fd_refcount"); +grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); #endif gpr_mu grpc_polling_mu; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index d3ed87a1c03..28098ecd086 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -31,7 +31,7 @@ #include "src/core/lib/iomgr/combiner.h" -grpc_core::Tracer grpc_resource_quota_trace(false, "resource_quota"); +grpc_core::TraceFlag grpc_resource_quota_trace(false, "resource_quota"); #define MEMORY_USAGE_ESTIMATION_MAX 65536 diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 04c80c692cb..fdebe89b860 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -65,7 +65,7 @@ extern "C" { maintain lists of users (which users arrange to leave before they are destroyed) */ -extern grpc_core::Tracer grpc_resource_quota_trace; +extern grpc_core::TraceFlag grpc_resource_quota_trace; grpc_resource_quota *grpc_resource_quota_ref_internal( grpc_resource_quota *resource_quota); diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 4ef13dd1f5e..05c2adae20b 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -43,7 +43,7 @@ #include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/support/string.h" -extern grpc_core::Tracer grpc_tcp_trace; +extern grpc_core::TraceFlag grpc_tcp_trace; typedef struct { gpr_mu mu; diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index bebb7634b63..b2aefc282ea 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -32,7 +32,7 @@ #include "src/core/lib/iomgr/tcp_uv.h" #include "src/core/lib/iomgr/timer.h" -extern grpc_core::Tracer grpc_tcp_trace; +extern grpc_core::TraceFlag grpc_tcp_trace; typedef struct grpc_uv_tcp_connect { uv_connect_t connect_req; diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index cfdacaf9888..3fa175df95d 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -61,7 +61,7 @@ typedef GRPC_MSG_IOVLEN_TYPE msg_iovlen_type; typedef size_t msg_iovlen_type; #endif -grpc_core::Tracer grpc_tcp_trace(false, "tcp"); +grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); typedef struct { grpc_endpoint base; diff --git a/src/core/lib/iomgr/tcp_posix.h b/src/core/lib/iomgr/tcp_posix.h index 3a515298748..d9963c2f2f3 100644 --- a/src/core/lib/iomgr/tcp_posix.h +++ b/src/core/lib/iomgr/tcp_posix.h @@ -37,7 +37,7 @@ extern "C" { #endif -extern grpc_core::Tracer grpc_tcp_trace; +extern grpc_core::TraceFlag grpc_tcp_trace; /* Create a tcp endpoint given a file desciptor and a read slice size. Takes ownership of fd. */ diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index ece494065a2..b245ce4ecf1 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -38,7 +38,7 @@ #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" -grpc_core::Tracer grpc_tcp_trace(false, "tcp"); +grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); typedef struct { grpc_endpoint base; diff --git a/src/core/lib/iomgr/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h index 63f028173ea..3d4afe0fb8d 100644 --- a/src/core/lib/iomgr/tcp_uv.h +++ b/src/core/lib/iomgr/tcp_uv.h @@ -34,7 +34,7 @@ #include -extern grpc_core::Tracer grpc_tcp_trace; +extern grpc_core::TraceFlag grpc_tcp_trace; #define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index 9024f2b743d..99304bb764a 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -49,7 +49,7 @@ #define GRPC_FIONBIO FIONBIO #endif -grpc_core::Tracer grpc_tcp_trace(false, "tcp"); +grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); static grpc_error *set_non_block(SOCKET sock) { int status; diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 98b4ca22ab4..1735aeb19f3 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -44,8 +44,8 @@ #define MAX_QUEUE_WINDOW_DURATION 1 extern "C" { -grpc_core::Tracer grpc_timer_trace(false, "timer"); -grpc_core::Tracer grpc_timer_check_trace(false, "timer_check"); +grpc_core::TraceFlag grpc_timer_trace(false, "timer"); +grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); } /* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 951059d43ea..9f2dcb52d35 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -33,7 +33,7 @@ typedef struct completed_thread { struct completed_thread *next; } completed_thread; -extern grpc_core::Tracer grpc_timer_check_trace; +extern grpc_core::TraceFlag grpc_timer_check_trace; // global mutex static gpr_mu g_mu; diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index a64269585cf..c4d46ff48fd 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -30,8 +30,8 @@ #include extern "C" { -grpc_core::Tracer grpc_timer_trace(false, "timer"); -grpc_core::Tracer grpc_timer_check_trace(false, "timer_check"); +grpc_core::TraceFlag grpc_timer_trace(false, "timer"); +grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); } static void timer_close_callback(uv_handle_t *handle) { gpr_free(handle); } diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 39f92fe595f..b0868950e15 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -30,7 +30,7 @@ #include #ifndef NDEBUG -grpc_core::Tracer grpc_trace_auth_context_refcount(false, +grpc_core::TraceFlag grpc_trace_auth_context_refcount(false, "auth_context_refcount"); #endif diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h index f8ea0bad12a..cc03bd6084c 100644 --- a/src/core/lib/security/context/security_context.h +++ b/src/core/lib/security/context/security_context.h @@ -23,7 +23,7 @@ #include "src/core/lib/security/credentials/credentials.h" #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_auth_context_refcount; +extern grpc_core::TraceFlag grpc_trace_auth_context_refcount; #endif #ifdef __cplusplus diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index cf032410168..47007988d28 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -31,7 +31,7 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/validate_metadata.h" -grpc_core::Tracer grpc_plugin_credentials_trace(false, "plugin_credentials"); +grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials"); static void plugin_destruct(grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds) { diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.h b/src/core/lib/security/credentials/plugin/plugin_credentials.h index 9c8bc18e279..f0d757e04d2 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.h +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.h @@ -21,7 +21,7 @@ #include "src/core/lib/security/credentials/credentials.h" -extern grpc_core::Tracer grpc_plugin_credentials_trace; +extern grpc_core::TraceFlag grpc_plugin_credentials_trace; struct grpc_plugin_credentials; diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index e2772980cd0..5964f3ba708 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -61,7 +61,7 @@ typedef struct { gpr_refcount ref; } secure_endpoint; -grpc_core::Tracer grpc_trace_secure_endpoint(false, "secure_endpoint"); +grpc_core::TraceFlag grpc_trace_secure_endpoint(false, "secure_endpoint"); static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) { secure_endpoint *ep = secure_ep; diff --git a/src/core/lib/security/transport/secure_endpoint.h b/src/core/lib/security/transport/secure_endpoint.h index cfa1d49d8f5..4748c8809c6 100644 --- a/src/core/lib/security/transport/secure_endpoint.h +++ b/src/core/lib/security/transport/secure_endpoint.h @@ -29,7 +29,7 @@ extern "C" { struct tsi_frame_protector; struct tsi_zero_copy_grpc_protector; -extern grpc_core::Tracer grpc_trace_secure_endpoint; +extern grpc_core::TraceFlag grpc_trace_secure_endpoint; /* 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 diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 31e2fd0107a..9c5c53e67e5 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -44,7 +44,7 @@ #include "src/core/tsi/transport_security_adapter.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_security_connector_refcount( +grpc_core::TraceFlag grpc_trace_security_connector_refcount( false, "security_connector_refcount"); #endif diff --git a/src/core/lib/security/transport/security_connector.h b/src/core/lib/security/transport/security_connector.h index 38b53a2b8e3..f401349fde8 100644 --- a/src/core/lib/security/transport/security_connector.h +++ b/src/core/lib/security/transport/security_connector.h @@ -34,7 +34,7 @@ extern "C" { #endif #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_security_connector_refcount; +extern grpc_core::TraceFlag grpc_trace_security_connector_refcount; #endif /* --- status enum. --- */ diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 6bab0be8499..4ebdba71d9e 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -28,7 +28,7 @@ #include "src/core/lib/surface/completion_queue.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_alarm_refcount(false, "alarm_refcount"); +grpc_core::TraceFlag grpc_trace_alarm_refcount(false, "alarm_refcount"); #endif struct grpc_alarm { diff --git a/src/core/lib/surface/alarm_internal.h b/src/core/lib/surface/alarm_internal.h index 85d5b85988f..fa86815ed0c 100644 --- a/src/core/lib/surface/alarm_internal.h +++ b/src/core/lib/surface/alarm_internal.h @@ -28,7 +28,7 @@ extern "C" { #ifndef NDEBUG -extern grpc_core::Tracer 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_UNREF(a, reason) \ diff --git a/src/core/lib/surface/api_trace.cc b/src/core/lib/surface/api_trace.cc index dfddbba178a..7ab836a9bac 100644 --- a/src/core/lib/surface/api_trace.cc +++ b/src/core/lib/surface/api_trace.cc @@ -19,4 +19,4 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/debug/trace.h" -grpc_core::Tracer grpc_api_trace(false, "api"); +grpc_core::TraceFlag grpc_api_trace(false, "api"); diff --git a/src/core/lib/surface/api_trace.h b/src/core/lib/surface/api_trace.h index 044ed9b6ecb..9838bccacf0 100644 --- a/src/core/lib/surface/api_trace.h +++ b/src/core/lib/surface/api_trace.h @@ -26,7 +26,7 @@ extern "C" { #endif -extern grpc_core::Tracer grpc_api_trace; +extern grpc_core::TraceFlag grpc_api_trace; /* Provide unwrapping macros because we're in C89 and variadic macros weren't introduced until C99... */ diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 21a0285e1ca..a003439da49 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -259,8 +259,8 @@ struct grpc_call { gpr_atm recv_state; }; -grpc_core::Tracer grpc_call_error_trace(false, "call_error"); -grpc_core::Tracer grpc_compression_trace(false, "compression"); +grpc_core::TraceFlag grpc_call_error_trace(false, "call_error"); +grpc_core::TraceFlag grpc_compression_trace(false, "compression"); #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1)) #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1) diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index f00cf0503b2..0fbdf9812b0 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -111,8 +111,8 @@ uint8_t grpc_call_is_client(grpc_call *call); grpc_compression_algorithm grpc_call_compression_for_level( grpc_call *call, grpc_compression_level level); -extern grpc_core::Tracer grpc_call_error_trace; -extern grpc_core::Tracer grpc_compression_trace; +extern grpc_core::TraceFlag grpc_call_error_trace; +extern grpc_core::TraceFlag grpc_compression_trace; #ifdef __cplusplus } diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index c0ef8a8a1ca..5c35e44bcca 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -39,10 +39,10 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/event_string.h" -grpc_core::Tracer grpc_trace_operation_failures(false, "op_failure"); +grpc_core::TraceFlag grpc_trace_operation_failures(false, "op_failure"); #ifndef NDEBUG -grpc_core::Tracer grpc_trace_pending_tags(false, "pending_tags"); -grpc_core::Tracer grpc_trace_cq_refcount(false, "cq_refcount"); +grpc_core::TraceFlag grpc_trace_pending_tags(false, "pending_tags"); +grpc_core::TraceFlag grpc_trace_cq_refcount(false, "cq_refcount"); #endif typedef struct { @@ -325,8 +325,8 @@ static const cq_vtable g_cq_vtable[] = { #define POLLSET_FROM_CQ(cq) \ ((grpc_pollset *)(cq->vtable->data_size + (char *)DATA_FROM_CQ(cq))) -grpc_core::Tracer grpc_cq_pluck_trace(true, "queue_pluck"); -grpc_core::Tracer grpc_cq_event_timeout_trace(true, "queue_timeout"); +grpc_core::TraceFlag grpc_cq_pluck_trace(true, "queue_pluck"); +grpc_core::TraceFlag grpc_cq_event_timeout_trace(true, "queue_timeout"); #define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ if (grpc_api_trace.enabled() && (grpc_cq_pluck_trace.enabled() || \ diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 3020091f210..cb390fe753e 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -27,13 +27,13 @@ /* These trace flags default to 1. The corresponding lines are only traced if grpc_api_trace is also truthy */ -extern grpc_core::Tracer grpc_cq_pluck_trace; -extern grpc_core::Tracer grpc_cq_event_timeout_trace; -extern grpc_core::Tracer grpc_trace_operation_failures; +extern grpc_core::TraceFlag grpc_cq_pluck_trace; +extern grpc_core::TraceFlag grpc_cq_event_timeout_trace; +extern grpc_core::TraceFlag grpc_trace_operation_failures; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_pending_tags; -extern grpc_core::Tracer grpc_trace_cq_refcount; +extern grpc_core::TraceFlag grpc_trace_pending_tags; +extern grpc_core::TraceFlag grpc_trace_cq_refcount; #endif #ifdef __cplusplus diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 081fa54f168..97e00eed55e 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -59,7 +59,7 @@ typedef struct registered_method registered_method; typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; -grpc_core::Tracer grpc_server_channel_trace(false, "server_channel"); +grpc_core::TraceFlag grpc_server_channel_trace(false, "server_channel"); typedef struct requested_call { requested_call_type type; diff --git a/src/core/lib/surface/server.h b/src/core/lib/surface/server.h index 20e6ec4eec6..a7c3405288d 100644 --- a/src/core/lib/surface/server.h +++ b/src/core/lib/surface/server.h @@ -31,7 +31,7 @@ extern "C" { extern const grpc_channel_filter grpc_server_top_filter; /** Lightweight tracing of server channel state */ -extern grpc_core::Tracer 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, and when it shuts down, it will call destroy */ diff --git a/src/core/lib/transport/bdp_estimator.cc b/src/core/lib/transport/bdp_estimator.cc index 36826f45ca2..a9db572c5ba 100644 --- a/src/core/lib/transport/bdp_estimator.cc +++ b/src/core/lib/transport/bdp_estimator.cc @@ -23,7 +23,7 @@ #include -grpc_core::Tracer grpc_bdp_estimator_trace(false, "bdp_estimator"); +grpc_core::TraceFlag grpc_bdp_estimator_trace(false, "bdp_estimator"); namespace grpc_core { diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index 3558eb49e71..872cfaad8c9 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -31,7 +31,7 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/exec_ctx.h" -extern grpc_core::Tracer grpc_bdp_estimator_trace; +extern grpc_core::TraceFlag grpc_bdp_estimator_trace; namespace grpc_core { diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index f9e81855553..eb3bbeb5888 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -24,7 +24,7 @@ #include #include -grpc_core::Tracer grpc_connectivity_state_trace(false, "connectivity_state"); +grpc_core::TraceFlag grpc_connectivity_state_trace(false, "connectivity_state"); const char *grpc_connectivity_state_name(grpc_connectivity_state state) { switch (state) { diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index d70c9a8480a..3127f56ec72 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -47,7 +47,7 @@ typedef struct { char *name; } grpc_connectivity_state_tracker; -extern grpc_core::Tracer grpc_connectivity_state_trace; +extern grpc_core::TraceFlag grpc_connectivity_state_trace; /** enum --> string conversion */ const char *grpc_connectivity_state_name(grpc_connectivity_state state); diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 1eddb6f0d6f..9adf43d0196 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -49,7 +49,7 @@ */ #ifndef NDEBUG -grpc_core::Tracer grpc_trace_metadata(false, "metadata"); +grpc_core::TraceFlag grpc_trace_metadata(false, "metadata"); #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s), __FILE__, __LINE__) diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 66780d925b5..678c213be16 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -26,7 +26,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_metadata; +extern grpc_core::TraceFlag grpc_trace_metadata; #endif #ifdef __cplusplus diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 4055e9c881a..d0c4e04f856 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -32,7 +32,7 @@ #include "src/core/lib/transport/transport_impl.h" #ifndef NDEBUG -grpc_core::Tracer grpc_trace_stream_refcount(false, "stream_refcount"); +grpc_core::TraceFlag grpc_trace_stream_refcount(false, "stream_refcount"); #endif #ifndef NDEBUG diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 80464027245..ae0dea362c7 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -44,7 +44,7 @@ typedef struct grpc_transport grpc_transport; typedef struct grpc_stream grpc_stream; #ifndef NDEBUG -extern grpc_core::Tracer grpc_trace_stream_refcount; +extern grpc_core::TraceFlag grpc_trace_stream_refcount; #endif typedef struct grpc_stream_refcount { diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index c452a0f1bfe..a2f45f5e0ba 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -26,7 +26,7 @@ /* --- Tracing. --- */ -grpc_core::Tracer tsi_tracing_enabled(false, "tsi"); +grpc_core::TraceFlag tsi_tracing_enabled(false, "tsi"); /* --- tsi_result common implementation. --- */ diff --git a/src/core/tsi/transport_security.h b/src/core/tsi/transport_security.h index 0a3c45c4746..c5fbba15222 100644 --- a/src/core/tsi/transport_security.h +++ b/src/core/tsi/transport_security.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern grpc_core::Tracer tsi_tracing_enabled; +extern grpc_core::TraceFlag tsi_tracing_enabled; /* Base for tsi_frame_protector implementations. See transport_security_interface.h for documentation. */ diff --git a/src/core/tsi/transport_security_interface.h b/src/core/tsi/transport_security_interface.h index ebf75f36fcc..40a5a596d63 100644 --- a/src/core/tsi/transport_security_interface.h +++ b/src/core/tsi/transport_security_interface.h @@ -60,7 +60,7 @@ const char *tsi_result_to_string(tsi_result result); /* --- tsi tracing --- */ -extern grpc_core::Tracer tsi_tracing_enabled; +extern grpc_core::TraceFlag tsi_tracing_enabled; /* -- tsi_zero_copy_grpc_protector object -- From 3c991309962418c447ee5b4f99fec396a4a3c3e1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 18 Oct 2017 15:00:40 -0700 Subject: [PATCH 04/27] Add debug-only trace flags --- src/core/ext/filters/client_channel/lb_policy.cc | 5 ++--- src/core/ext/filters/client_channel/resolver.cc | 5 ++--- .../ext/transport/chttp2/transport/chttp2_transport.cc | 5 ++--- src/core/ext/transport/chttp2/transport/internal.h | 8 ++++---- src/core/lib/debug/trace.h | 10 ++++++++++ src/core/lib/iomgr/closure.cc | 4 +--- src/core/lib/iomgr/error.cc | 5 ++--- src/core/lib/iomgr/ev_epollex_linux.cc | 5 ++--- src/core/lib/iomgr/pollset_uv.cc | 4 +--- src/core/lib/iomgr/pollset_windows.cc | 4 +--- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 316377b8453..8bffd480596 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -21,9 +21,8 @@ #define WEAK_REF_BITS 16 -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_lb_policy_refcount(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, diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 93dd834fb2e..d29a5e76469 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -19,9 +19,8 @@ #include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/lib/iomgr/combiner.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_resolver_refcount(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, diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 19fdcc91508..8f837b6a14d 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -93,9 +93,8 @@ static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; grpc_core::TraceFlag grpc_http_trace(false, "http"); grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl"); -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); -#endif +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, diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 6ef32958e02..f658b663914 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -681,10 +681,10 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, 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/lib/debug/trace.h b/src/core/lib/debug/trace.h index c09aa017035..ad12e451270 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -80,6 +80,16 @@ class TraceFlag { #endif }; +#ifndef NDEBUG +typedef TraceFlag DebugOnlyTraceFlag; +#else +class DebugOnlyTraceFlag { + public: + DebugOnlyTraceFlag(bool default_enabled, const char *name) {} + bool enabled() { return false; } +}; +#endif + } // namespace grpc_core #endif // __cplusplus diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc index 8639c2b7d20..47429b45875 100644 --- a/src/core/lib/iomgr/closure.cc +++ b/src/core/lib/iomgr/closure.cc @@ -24,9 +24,7 @@ #include "src/core/lib/profiling/timers.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_closure(false, "closure"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_closure(false, "closure"); #ifndef NDEBUG grpc_closure *grpc_closure_init(const char *file, int line, diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 898a18cb9e7..e1e2c653bec 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -37,9 +37,8 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_error_refcount(false, "error_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount(false, + "error_refcount"); static const char *error_int_name(grpc_error_ints key) { switch (key) { diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index bdcaf926b4e..89a5a229574 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -57,9 +57,8 @@ #define MAX_EPOLL_EVENTS 100 #define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5 -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_pollable_refcount(false, "pollable_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false, + "pollable_refcount"); /******************************************************************************* * pollable Declarations diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index 2016d5d808c..64e47e677e5 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -34,9 +34,7 @@ #include "src/core/lib/debug/trace.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); struct grpc_pollset { uv_timer_t timer; diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index 88354991d5d..07bd586f290 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -30,9 +30,7 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); gpr_mu grpc_polling_mu; static grpc_pollset_worker *g_active_poller; From 3e3f806cff69a3a0a1df9f4098d76c5f13b32f38 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Wed, 18 Oct 2017 17:16:56 -0700 Subject: [PATCH 05/27] Fix compile after flowctl merge --- src/core/ext/transport/chttp2/transport/chttp2_transport.cc | 1 - src/core/ext/transport/chttp2/transport/chttp2_transport.h | 1 - src/core/ext/transport/chttp2/transport/flow_control.cc | 2 ++ src/core/ext/transport/chttp2/transport/flow_control.h | 4 ++-- src/core/ext/transport/chttp2/transport/internal.h | 1 - src/core/lib/debug/trace.cc | 2 ++ src/core/lib/debug/trace.h | 2 +- 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 8f837b6a14d..de62995ecf1 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -91,7 +91,6 @@ static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; #define MAX_CLIENT_STREAM_ID 0x7fffffffu grpc_core::TraceFlag grpc_http_trace(false, "http"); -grpc_core::TraceFlag grpc_flowctl_trace(false, "flowctl"); grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index 408759a2925..982db403d8a 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -28,7 +28,6 @@ extern "C" { #endif extern grpc_core::TraceFlag grpc_http_trace; -extern grpc_core::TraceFlag grpc_flowctl_trace; extern grpc_core::TraceFlag grpc_trace_http2_stream_state; #ifndef NDEBUG diff --git a/src/core/ext/transport/chttp2/transport/flow_control.cc b/src/core/ext/transport/chttp2/transport/flow_control.cc index dd80036530c..5a1358e260a 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 d5107d467b9..59ba758d520 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 "C" grpc_tracer_flag grpc_flowctl_trace; +extern grpc_core::TraceFlag grpc_flowctl_trace; namespace grpc_core { namespace chttp2 { @@ -112,7 +112,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/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index f658b663914..ee6974a6d57 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -679,7 +679,6 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) extern grpc_core::TraceFlag grpc_http_trace; -extern grpc_core::TraceFlag grpc_flowctl_trace; #define GRPC_CHTTP2_IF_TRACING(stmt) \ if (!grpc_http_trace.enabled()) \ diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 52cfbe52ea3..8fb6393a36e 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -29,6 +29,8 @@ int grpc_tracer_set_enabled(const char *name, int enabled); namespace grpc_core { +TraceFlag* TraceFlag::root_tracer_ = nullptr; + TraceFlag::TraceFlag(bool default_enabled, const char *name) : next_tracer_(root_tracer_), name_(name), value_(default_enabled) { root_tracer_ = this; diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index ad12e451270..f7a6005825d 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -47,7 +47,7 @@ namespace grpc_core { class TraceFlag { public: TraceFlag(bool default_enabled, const char *name); - ~TraceFlag(); + ~TraceFlag() { } static bool Set(const char *tracer, bool enabled); From 3cffe1fce58b027e9679ab3f38d9803d93a9bc80 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 13:56:23 -0800 Subject: [PATCH 06/27] Get NDEBUG to build --- .../ext/filters/client_channel/resolver.cc | 4 +- src/core/lib/iomgr/ev_epoll1_linux.cc | 52 +++++++++---------- src/core/lib/surface/alarm.cc | 6 +-- src/core/lib/surface/completion_queue.cc | 4 +- src/core/lib/transport/metadata.cc | 14 ++--- src/core/lib/transport/transport.cc | 4 +- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 21ce14e82d3..a5271be9e2e 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -34,7 +34,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, @@ -49,7 +49,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/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 61da9967810..fe1faa68fb4 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -276,7 +276,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_asprintf(&fd_name, "%s fd=%d", name, fd); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); #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); } #endif @@ -651,7 +651,7 @@ static grpc_error* do_epoll_wait(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, 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); } @@ -673,7 +673,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; 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); } @@ -692,7 +692,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, retry_lock_neighborhood: gpr_mu_lock(&neighborhood->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", pollset, worker, kick_state_string(worker->state), is_reassigning); @@ -744,7 +744,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, worker->initialized_cv = true; gpr_cv_init(&worker->cv); 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", pollset, worker, kick_state_string(worker->state), pollset->shutting_down); @@ -761,7 +761,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_exec_ctx_invalidate_now(exec_ctx); } - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, "PS:%p BEGIN_DONE:%p kick_state=%s shutdown=%d " "kicked_without_poller: %d", @@ -806,7 +806,7 @@ static bool check_neighborhood_for_available_poller( case UNKICKED: if (gpr_atm_no_barrier_cas(&g_active_poller, 0, (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", inspect_worker); } @@ -817,7 +817,7 @@ static bool check_neighborhood_for_available_poller( gpr_cv_signal(&inspect_worker->cv); } } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, " .. beaten to choose next poller"); } } @@ -835,7 +835,7 @@ static bool check_neighborhood_for_available_poller( } while (!found_worker && inspect_worker != inspect->root_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); } inspect->seen_inactive = true; @@ -857,7 +857,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* worker, grpc_pollset_worker** worker_hdl) { 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); } if (worker_hdl != NULL) *worker_hdl = NULL; @@ -867,7 +867,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, &exec_ctx->closure_list); if (gpr_atm_no_barrier_load(&g_active_poller) == (gpr_atm)worker) { 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_ASSERT(worker->next->initialized_cv); @@ -921,7 +921,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (worker->initialized_cv) { gpr_cv_destroy(&worker->cv); } - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, " .. remove worker"); } if (EMPTIED == worker_remove(pollset, worker)) { @@ -993,7 +993,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, GPR_TIMER_BEGIN("pollset_kick", 0); GRPC_STATS_INC_POLLSET_KICK(exec_ctx); grpc_error* ret_err = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_strvec log; gpr_strvec_init(&log); char* tmp; @@ -1026,7 +1026,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (root_worker == NULL) { GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); pollset->kicked_without_poller = true; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_ERROR, " .. kicked_without_poller"); } goto done; @@ -1034,14 +1034,14 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* next_worker = root_worker->next; if (root_worker->state == KICKED) { 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); } SET_KICK_STATE(root_worker, KICKED); goto done; } else if (next_worker->state == KICKED) { 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); } SET_KICK_STATE(next_worker, KICKED); @@ -1052,7 +1052,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, root_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load( &g_active_poller)) { 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); } SET_KICK_STATE(root_worker, KICKED); @@ -1060,7 +1060,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else if (next_worker->state == UNKICKED) { 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_ASSERT(next_worker->initialized_cv); @@ -1069,7 +1069,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else if (next_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_ERROR, " .. kicked root non-poller %p (initialized_cv=%d) (poller=%p)", @@ -1083,7 +1083,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else { 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, root_worker); } @@ -1099,7 +1099,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } } else { 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"); } goto done; @@ -1109,14 +1109,14 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } 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"); } goto done; } else if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { 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); } SET_KICK_STATE(specific_worker, KICKED); @@ -1124,7 +1124,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } else if (specific_worker == (grpc_pollset_worker*)gpr_atm_no_barrier_load(&g_active_poller)) { 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"); } SET_KICK_STATE(specific_worker, KICKED); @@ -1132,7 +1132,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else if (specific_worker->initialized_cv) { 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"); } SET_KICK_STATE(specific_worker, KICKED); @@ -1140,7 +1140,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, goto done; } else { 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"); } SET_KICK_STATE(specific_worker, KICKED); diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 9af9e5cb981..af1a48247c3 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -58,7 +58,7 @@ static void alarm_unref(grpc_alarm* alarm) { #ifndef NDEBUG static void alarm_ref_dbg(grpc_alarm* alarm, const char* reason, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "Alarm:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, @@ -70,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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "Alarm:%p Unref %" PRIdPTR " -> %" PRIdPTR " %s", alarm, val, @@ -102,7 +102,7 @@ grpc_alarm* grpc_alarm_create(void* reserved) { grpc_alarm* alarm = (grpc_alarm*)gpr_malloc(sizeof(grpc_alarm)); #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); } #endif diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 8e74a0ad3a4..72b62d42202 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -526,7 +526,7 @@ int grpc_get_cq_poll_num(grpc_completion_queue* cq) { #ifndef NDEBUG void grpc_cq_internal_ref(grpc_completion_queue* cq, const char* reason, const char* file, int line) { - if (grpc_trace_cq_refcount.enabled() { + if (grpc_trace_cq_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val + 1, @@ -547,7 +547,7 @@ static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* arg, #ifndef NDEBUG void grpc_cq_internal_unref(grpc_exec_ctx* exec_ctx, grpc_completion_queue* cq, const char* reason, const char* file, int line) { - if (grpc_trace_cq_refcount.enabled() { + if (grpc_trace_cq_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&cq->owning_refs.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", cq, val, val - 1, diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 71130077392..8022688bffc 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -148,7 +148,7 @@ static int is_mdelem_static(grpc_mdelem e) { static void ref_md_locked(mdtab_shard* shard, interned_metadata* md DEBUG_ARGS) { #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -251,7 +251,7 @@ grpc_mdelem grpc_mdelem_create( allocated->value = grpc_slice_ref_internal(value); gpr_atm_rel_store(&allocated->refcnt, 1); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(allocated->key); char* value_str = grpc_slice_to_c_string(allocated->value); gpr_log(GPR_DEBUG, "ELM ALLOC:%p:%" PRIdPTR ": '%s' = '%s'", @@ -305,7 +305,7 @@ grpc_mdelem grpc_mdelem_create( shard->elems[idx] = md; gpr_mu_init(&md->mu_user_data); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(GPR_DEBUG, "ELM NEW:%p:%" PRIdPTR ": '%s' = '%s'", (void*)md, @@ -372,7 +372,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -394,7 +394,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -424,7 +424,7 @@ void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata* md = (interned_metadata*)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -450,7 +450,7 @@ void grpc_mdelem_unref(grpc_exec_ctx* exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata* md = (allocated_metadata*)GRPC_MDELEM_DATA(gmd); #ifndef NDEBUG - if (GRPC_TRACER_ON(grpc_trace_metadata)) { + if (grpc_trace_metadata.enabled()) { char* key_str = grpc_slice_to_c_string(md->key); char* value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index dee68c8f76c..95f2b658466 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -37,7 +37,7 @@ grpc_core::TraceFlag grpc_trace_stream_refcount(false, "stream_refcount"); #ifndef NDEBUG void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason) { - if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { + if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p REF %" PRIdPTR "->%" PRIdPTR " %s", refcount->object_type, refcount, refcount->destroy.cb_arg, val, @@ -52,7 +52,7 @@ void grpc_stream_ref(grpc_stream_refcount* refcount) { #ifndef NDEBUG void grpc_stream_unref(grpc_exec_ctx* exec_ctx, grpc_stream_refcount* refcount, const char* reason) { - if (GRPC_TRACER_ON(grpc_trace_stream_refcount)) { + if (grpc_trace_stream_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&refcount->refs.count); gpr_log(GPR_DEBUG, "%s %p:%p UNREF %" PRIdPTR "->%" PRIdPTR " %s", refcount->object_type, refcount, refcount->destroy.cb_arg, val, From 9ffb1494674f53bad5f547d5f6989fcdcb944227 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 14:00:49 -0800 Subject: [PATCH 07/27] Portability --- src/core/lib/iomgr/ev_epollex_linux.cc | 62 ++++++++++++------------- src/core/lib/iomgr/ev_epollsig_linux.cc | 10 ++-- src/core/lib/iomgr/tcp_server_uv.cc | 8 ++-- src/core/lib/iomgr/tcp_uv.cc | 16 +++---- src/core/lib/iomgr/tcp_windows.cc | 4 +- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 0ce63209eab..b47f7f85317 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -262,7 +262,7 @@ static gpr_mu fd_freelist_mu; unref_by(ec, fd, n, reason, __FILE__, __LINE__) static void ref_by(grpc_fd* fd, int n, 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, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -296,7 +296,7 @@ static void fd_destroy(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { #ifndef NDEBUG static void unref_by(grpc_exec_ctx* exec_ctx, grpc_fd* fd, int n, 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, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -359,7 +359,7 @@ static grpc_fd* fd_create(int fd, const char* name) { gpr_asprintf(&fd_name, "%s fd=%d", name, fd); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); #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); } #endif @@ -482,7 +482,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { static pollable* pollable_ref(pollable* p) { #else 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); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p ref %d->%d %s", p, r, r + 1, reason); @@ -497,7 +497,7 @@ static void pollable_unref(pollable* p) { #else static void pollable_unref(pollable* p, int line, const char* reason) { 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); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); @@ -515,7 +515,7 @@ static grpc_error* pollable_add_fd(pollable* p, grpc_fd* fd) { static const char* err_desc = "pollable_add_fd"; 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); } @@ -557,7 +557,7 @@ static void pollset_global_shutdown(void) { /* pollset->mu must be held while calling this function */ static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p (pollable:%p) maybe_finish_shutdown sc=%p (target:!NULL) " "rw=%p (target:NULL) cpsc=%d (target:0)", @@ -580,14 +580,14 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, grpc_core::mu_guard lock(&p->mu); GPR_ASSERT(specific_worker != NULL); 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); } GRPC_STATS_INC_POLLSET_KICKED_AGAIN(exec_ctx); return GRPC_ERROR_NONE; } 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); } GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); @@ -596,7 +596,7 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, } if (specific_worker == p->root_worker) { 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); } specific_worker->kicked = true; @@ -605,7 +605,7 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, } if (specific_worker->initialized_cv) { 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); } specific_worker->kicked = true; @@ -620,7 +620,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, grpc_pollset_worker* specific_worker) { GRPC_STATS_INC_POLLSET_KICK(exec_ctx); - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kick %p tls_pollset=%p tls_worker=%p pollset.root_worker=%p", pollset, specific_worker, @@ -630,7 +630,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (specific_worker == NULL) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { 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); } GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); @@ -656,7 +656,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, exec_ctx, pollset->root_worker->links[PWLINK_POLLSET].next); } } else { - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_but_awake", pollset); } GRPC_STATS_INC_POLLSET_KICK_OWN_THREAD(exec_ctx); @@ -764,7 +764,7 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, struct epoll_event* ev = &pollable_obj->events[n]; void* data_ptr = ev->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); } append_error(&error, @@ -776,7 +776,7 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, bool cancel = (ev->events & (EPOLLERR | EPOLLHUP)) != 0; bool read_ev = (ev->events & (EPOLLIN | EPOLLPRI)) != 0; bool write_ev = (ev->events & EPOLLOUT) != 0; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p got fd %p: cancel=%d read=%d " "write=%d", @@ -804,7 +804,7 @@ static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, grpc_millis 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); gpr_log(GPR_DEBUG, "POLLABLE:%p[%s] poll for %dms", p, desc, timeout); gpr_free(desc); @@ -824,7 +824,7 @@ static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, 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); } @@ -892,7 +892,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, worker->initialized_cv = true; gpr_cv_init(&worker->cv); gpr_mu_unlock(&pollset->mu); - if (GRPC_TRACER_ON(grpc_polling_trace) && + if (grpc_polling_trace.enabled() && worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p wait %p w=%p for %dms", pollset, worker->pollable_obj, worker, @@ -901,18 +901,18 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, while (do_poll && worker->pollable_obj->root_worker != worker) { if (gpr_cv_wait(&worker->cv, &worker->pollable_obj->mu, 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, worker->pollable_obj, worker); } do_poll = false; } 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, worker->pollable_obj, worker); } do_poll = false; - } else if (GRPC_TRACER_ON(grpc_polling_trace) && + } else if (grpc_polling_trace.enabled() && worker->pollable_obj->root_worker != worker) { gpr_log(GPR_DEBUG, "PS:%p spurious_wakeup %p w=%p", pollset, worker->pollable_obj, worker); @@ -983,7 +983,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, #ifndef NDEBUG WORKER_PTR->originator = gettid(); #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 " deadline=%" PRIdPTR " kwp=%d pollable=%p", @@ -1026,7 +1026,7 @@ static grpc_error* pollset_transition_pollable_from_empty_to_fd_locked( grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_fd* fd) { static const char* err_desc = "pollset_transition_pollable_from_empty_to_fd"; grpc_error* error = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p add fd %p (%d); transition pollable from empty to fd", pollset, fd, fd->fd); @@ -1042,7 +1042,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) { static const char* err_desc = "pollset_transition_pollable_from_fd_to_multi"; grpc_error* error = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_polling_trace)) { + if (grpc_polling_trace.enabled()) { gpr_log( GPR_DEBUG, "PS:%p add fd %p (%d); transition pollable from fd %p to multipoller", @@ -1192,7 +1192,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, 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); } grpc_error* error = GRPC_ERROR_NONE; @@ -1216,7 +1216,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, 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); } pss = pss_lock_adam(pss); @@ -1237,7 +1237,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, 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); } pss = pss_lock_adam(pss); @@ -1288,7 +1288,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, 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); } grpc_error* error = GRPC_ERROR_NONE; @@ -1325,7 +1325,7 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, grpc_pollset_set* a, 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); } grpc_error* error = GRPC_ERROR_NONE; @@ -1359,7 +1359,7 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, if (b_size > a_size) { 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_ref(&a->refs); diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 42806e9d148..128c3adbff6 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -55,7 +55,7 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1) #define GRPC_POLLING_TRACE(...) \ - if (GRPC_TRACER_ON(grpc_polling_trace)) { \ + if (grpc_polling_trace.enabled()) { \ gpr_log(GPR_INFO, __VA_ARGS__); \ } @@ -289,7 +289,7 @@ static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi); #ifndef NDEBUG static void pi_add_ref_dbg(polling_island* pi, 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_log(GPR_DEBUG, "Add ref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR @@ -301,7 +301,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, 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_log(GPR_DEBUG, "Unref pi: %p, old:%" PRIdPTR " -> new:%" PRIdPTR @@ -733,7 +733,7 @@ static gpr_mu fd_freelist_mu; #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, int line) { - if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) { + if (grpc_trace_fd_refcount.enabled()) { gpr_log(GPR_DEBUG, "FD %d %p ref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -750,7 +750,7 @@ static void ref_by(grpc_fd* fd, int n) { #ifndef NDEBUG static void unref_by(grpc_fd* fd, int n, 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, "FD %d %p unref %d %" PRIdPTR " -> %" PRIdPTR " [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index 0eed4d428fb..2c76fae7fd6 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -213,7 +213,7 @@ static void finish_accept(grpc_exec_ctx* exec_ctx, grpc_tcp_listener* sp) { } else { 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) { gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", 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); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { 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); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { char* port_string; grpc_sockaddr_to_string(&port_string, addr, 0); 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)pollset_count; 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_ASSERT(on_accept_cb); diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 1d04eeeb0dc..b752153fc79 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -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__) static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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); tcp->read_slice = alloc_read_slice(&exec_ctx, tcp->resource_user); error = GRPC_ERROR_NONE; - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { size_t i; const char* str = grpc_error_string(error); 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_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); 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 { 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); 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; GRPC_UV_ASSERT_SAME_THREAD(); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { size_t j; for (j = 0; j < write_slices->count; j++) { @@ -320,7 +320,7 @@ static void uv_endpoint_shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_error* why) { grpc_tcp* tcp = (grpc_tcp*)ep; if (!tcp->shutting_down) { - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(why); gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->handle, str); } @@ -367,7 +367,7 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); 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); } diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index f29dd135294..33868cdc7a7 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -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__) static void tcp_unref(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "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, 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_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, From 047e0fd1cf0bbd7d7d522e397f06d670d985f98f Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 14:01:47 -0800 Subject: [PATCH 08/27] Portability --- src/core/lib/iomgr/ev_epollex_linux.cc | 4 ---- src/core/lib/iomgr/tcp_client_uv.cc | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index b47f7f85317..aa9d0735ac8 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -1460,10 +1460,6 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux( return NULL; } -#ifndef NDEBUG - grpc_register_tracer(&grpc_trace_pollable_refcount); -#endif - fd_global_init(); if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc index a5998162832..7a5727ec534 100644 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ b/src/core/lib/iomgr/tcp_client_uv.cc @@ -59,7 +59,7 @@ static void uv_tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { int done; 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); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", 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->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", connect->addr_name); } From 756acb689378ca5170f32c75ce022f2a3b116e76 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 15:27:05 -0800 Subject: [PATCH 09/27] Fix TSAN build --- src/core/lib/debug/trace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index fe4c875ebb3..20bb623e784 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -55,7 +55,7 @@ class TraceFlag { bool enabled() { #ifdef GRPC_THREADSAFE_TRACER - gpr_atm_no_barrier_load(&value_) != 0 + return gpr_atm_no_barrier_load(&value_) != 0; #else return value_; #endif @@ -66,7 +66,7 @@ class TraceFlag { void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER - gpr_atm_no_barrier_store(&value, enabled); + gpr_atm_no_barrier_store(&value_, enabled); #else value_ = enabled; #endif From 05fbb9d13de546560b1fb799cb4b1ff622c47713 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 16:32:40 -0800 Subject: [PATCH 10/27] Fix test compile --- src/core/lib/debug/trace.h | 8 +++++--- test/core/iomgr/timer_list_test.cc | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 20bb623e784..274849d1572 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -61,9 +61,8 @@ class TraceFlag { #endif } - private: - static void List(); - + // Only to be used for testing purposes. Tracers should usually be set using + // the static Set function void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER gpr_atm_no_barrier_store(&value_, enabled); @@ -72,6 +71,9 @@ class TraceFlag { #endif } + private: + static void List(); + static TraceFlag *root_tracer_; TraceFlag *next_tracer_; const char *const name_; diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 4d92cc658a1..1fdcbc45d45 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -31,8 +31,8 @@ #define MAX_CB 30 -grpc_core::TraceFlag grpc_timer_trace; -grpc_core::TraceFlag grpc_timer_check_trace; +extern grpc_core::TraceFlag grpc_timer_trace; +extern grpc_core::TraceFlag grpc_timer_check_trace; static int cb_called[MAX_CB][2]; @@ -48,8 +48,8 @@ static void add_test(void) { gpr_log(GPR_INFO, "add_test"); grpc_timer_list_init(&exec_ctx); - grpc_timer_trace.value = 1; - grpc_timer_check_trace.value = 1; + grpc_timer_trace.set_enabled(1); + grpc_timer_check_trace.set_enabled(1); memset(cb_called, 0, sizeof(cb_called)); grpc_millis start = grpc_exec_ctx_now(&exec_ctx); @@ -117,8 +117,8 @@ void destruction_test(void) { exec_ctx.now_is_valid = true; exec_ctx.now = 0; grpc_timer_list_init(&exec_ctx); - grpc_timer_trace.value = 1; - grpc_timer_check_trace.value = 1; + grpc_timer_trace.set_enabled(1); + grpc_timer_check_trace.set_enabled(1); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( From 05294b682b8d6a3970138fc87b0bc356b31ded97 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 10 Nov 2017 16:57:53 -0800 Subject: [PATCH 11/27] Make debug flags DebugOnly --- .../ext/filters/client_channel/client_channel_plugin.cc | 4 ---- src/core/ext/filters/client_channel/lb_policy.h | 4 +--- src/core/ext/filters/client_channel/resolver.cc | 4 +--- src/core/ext/filters/client_channel/resolver.h | 4 +--- src/core/ext/transport/chttp2/transport/chttp2_plugin.cc | 6 +----- .../ext/transport/chttp2/transport/chttp2_transport.cc | 5 +---- .../ext/transport/chttp2/transport/chttp2_transport.h | 5 +---- src/core/lib/debug/trace.cc | 4 ++-- src/core/lib/debug/trace.h | 2 +- src/core/lib/iomgr/closure.h | 4 +--- src/core/lib/iomgr/error.h | 4 +--- src/core/lib/iomgr/ev_epollex_linux.cc | 4 +--- src/core/lib/iomgr/ev_posix.cc | 5 +---- src/core/lib/iomgr/pollset.h | 4 +--- src/core/lib/security/context/security_context.cc | 4 +--- src/core/lib/security/context/security_context.h | 4 +--- src/core/lib/security/transport/security_connector.cc | 4 +--- src/core/lib/security/transport/security_connector.h | 4 +--- src/core/lib/surface/alarm.cc | 4 +--- src/core/lib/surface/alarm_internal.h | 4 ++-- src/core/lib/surface/completion_queue.cc | 6 ++---- src/core/lib/surface/completion_queue.h | 7 ++----- src/core/lib/surface/init.cc | 4 ---- src/core/lib/surface/init_secure.cc | 9 +-------- src/core/lib/transport/metadata.cc | 3 ++- src/core/lib/transport/metadata.h | 4 +--- src/core/lib/transport/transport.cc | 4 +--- src/core/lib/transport/transport.h | 4 +--- 28 files changed, 31 insertions(+), 93 deletions(-) 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 198ef7578bd..0675dc2b1bf 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 @@ extern "C" 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(); - -#ifndef NDEBUG - -#endif } extern "C" void grpc_client_channel_shutdown(void) { diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 00ac0b1157f..cd40b4dcf72 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -33,9 +33,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_core::TraceFlag 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/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index a5271be9e2e..9daf45b3ec0 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -19,9 +19,7 @@ #include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/lib/iomgr/combiner.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_resolver_refcount(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, diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index e61b1867b1b..b5806ad8d75 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -29,9 +29,7 @@ extern "C" { typedef struct grpc_resolver grpc_resolver; typedef struct grpc_resolver_vtable grpc_resolver_vtable; -#ifndef NDEBUG -extern grpc_core::TraceFlag 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/transport/chttp2/transport/chttp2_plugin.cc b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc index 13c39667627..2569347def7 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc @@ -20,10 +20,6 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/metadata.h" -extern "C" void grpc_chttp2_plugin_init(void) { -#ifndef NDEBUG - -#endif -} +extern "C" void grpc_chttp2_plugin_init(void) {} extern "C" 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 a6ec7bb1d2e..cd77dcbe961 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -91,10 +91,7 @@ static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; #define MAX_CLIENT_STREAM_ID 0x7fffffffu grpc_core::TraceFlag grpc_http_trace(false, "http"); - -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); -#endif +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, diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index 44702d44eff..54abbe6e5f1 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -25,10 +25,7 @@ extern grpc_core::TraceFlag grpc_http_trace; extern grpc_core::TraceFlag grpc_trace_http2_stream_state; - -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_chttp2_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount; #ifdef __cplusplus extern "C" { diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 8fb6393a36e..5d377135460 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -36,7 +36,7 @@ TraceFlag::TraceFlag(bool default_enabled, const char *name) root_tracer_ = this; } -void TraceFlag::List() { +void TraceFlag::LogAllTracers() { gpr_log(GPR_DEBUG, "available tracers:"); TraceFlag *t; for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { @@ -51,7 +51,7 @@ bool TraceFlag::Set(const char *name, bool enabled) { t->set_enabled(enabled); } } else if (0 == strcmp(name, "list_tracers")) { - List(); + LogAllTracers(); } else if (0 == strcmp(name, "refcount")) { for (t = root_tracer_; t; t = t->next_tracer_) { if (strstr(t->name_, "refcount") != NULL) { diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 274849d1572..162090a248e 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -72,7 +72,7 @@ class TraceFlag { } private: - static void List(); + static void LogAllTracers(); static TraceFlag *root_tracer_; TraceFlag *next_tracer_; diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 527075e566a..5171ac1529a 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -33,9 +33,7 @@ extern "C" { struct grpc_closure; typedef struct grpc_closure grpc_closure; -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_closure; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_closure; typedef struct grpc_closure_list { grpc_closure* head; diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 271938bf284..c81429ef8a6 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -38,9 +38,7 @@ extern "C" { typedef struct grpc_error grpc_error; -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_error_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_error_refcount; typedef enum { /// 'errno' from the operating system diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index aa9d0735ac8..9abd569ee01 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -59,9 +59,7 @@ #define MAX_EPOLL_EVENTS 100 #define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5 -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_pollable_refcount(false, "pollable_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false, "pollable_refcount"); /******************************************************************************* * pollable Declarations diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index b6669174648..5b4b66b989a 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -37,10 +37,7 @@ #include "src/core/lib/support/env.h" grpc_core::TraceFlag grpc_polling_trace(false, "polling"); /* Disabled by default */ - -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); /** Default poll() function - a pointer so that it can be overridden by some * tests */ diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index c48ff982c6b..6911a8ee12b 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -29,9 +29,7 @@ extern "C" { #endif -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_fd_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount; /* A grpc_pollset is a set of file descriptors that a higher level item is interested in. For example: diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index f12b312299c..31e7510d357 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -29,10 +29,8 @@ #include #include -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_auth_context_refcount(false, +grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount(false, "auth_context_refcount"); -#endif /* --- grpc_call --- */ diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h index 57344df96bc..5b27d1a42e9 100644 --- a/src/core/lib/security/context/security_context.h +++ b/src/core/lib/security/context/security_context.h @@ -22,9 +22,7 @@ #include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/security/credentials/credentials.h" -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_auth_context_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount; #ifdef __cplusplus extern "C" { diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 23e92c0b8f4..308fdce05b4 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -44,10 +44,8 @@ #include "src/core/tsi/ssl_transport_security.h" #include "src/core/tsi/transport_security_adapter.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_security_connector_refcount( +grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount( false, "security_connector_refcount"); -#endif /* -- Constants. -- */ diff --git a/src/core/lib/security/transport/security_connector.h b/src/core/lib/security/transport/security_connector.h index 10a4ef1a6d4..7cde358b41c 100644 --- a/src/core/lib/security/transport/security_connector.h +++ b/src/core/lib/security/transport/security_connector.h @@ -33,9 +33,7 @@ extern "C" { #endif -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_security_connector_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_security_connector_refcount; /* --- status enum. --- */ diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index af1a48247c3..8ba4a93525d 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -27,9 +27,7 @@ #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/surface/completion_queue.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_alarm_refcount(false, "alarm_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount(false, "alarm_refcount"); struct grpc_alarm { gpr_refcount refs; diff --git a/src/core/lib/surface/alarm_internal.h b/src/core/lib/surface/alarm_internal.h index fa86815ed0c..47fd1acaf09 100644 --- a/src/core/lib/surface/alarm_internal.h +++ b/src/core/lib/surface/alarm_internal.h @@ -26,9 +26,9 @@ extern "C" { #endif -#ifndef NDEBUG +extern grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount; -extern grpc_core::TraceFlag grpc_trace_alarm_refcount; +#ifndef NDEBUG #define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__) #define GRPC_ALARM_UNREF(a, reason) \ diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 72b62d42202..b5ae87ee667 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -41,10 +41,8 @@ #include "src/core/lib/surface/event_string.h" grpc_core::TraceFlag grpc_trace_operation_failures(false, "op_failure"); -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_pending_tags(false, "pending_tags"); -grpc_core::TraceFlag grpc_trace_cq_refcount(false, "cq_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_pending_tags(false, "pending_tags"); +grpc_core::DebugOnlyTraceFlag grpc_trace_cq_refcount(false, "cq_refcount"); // Specifies a cq thread local cache. // The first event that occurs on a thread diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 945b6734b11..9fdb48dd23d 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -30,11 +30,8 @@ extern grpc_core::TraceFlag grpc_cq_pluck_trace; extern grpc_core::TraceFlag grpc_cq_event_timeout_trace; extern grpc_core::TraceFlag grpc_trace_operation_failures; - -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_pending_tags; -extern grpc_core::TraceFlag grpc_trace_cq_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_pending_tags; +extern grpc_core::DebugOnlyTraceFlag grpc_trace_cq_refcount; #ifdef __cplusplus extern "C" { diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index c8a28e3be63..e4aa9231fe6 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -126,10 +126,6 @@ void grpc_init(void) { grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); - -#ifndef NDEBUG - -#endif grpc_security_pre_init(); grpc_iomgr_init(&exec_ctx); gpr_timers_global_init(); diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index fcca71c822a..4df622521b9 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -32,16 +32,9 @@ #include "src/core/lib/security/transport/security_handshaker.h" #include "src/core/lib/surface/channel_init.h" #include "src/core/tsi/transport_security_interface.h" - -#ifndef NDEBUG #include "src/core/lib/security/context/security_context.h" -#endif - -void grpc_security_pre_init(void) { -#ifndef NDEBUG -#endif -} +void grpc_security_pre_init(void) {} static bool maybe_prepend_client_auth_filter( grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 8022688bffc..d58381852a0 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -48,8 +48,9 @@ * used to determine which kind of element a pointer refers to. */ +grpc_core::DebugOnlyTraceFlag grpc_trace_metadata(false, "metadata"); + #ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_metadata(false, "metadata"); #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s), __FILE__, __LINE__) diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 2f112523af9..931ba0b44fe 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -25,9 +25,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_metadata; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_metadata; #ifdef __cplusplus extern "C" { diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 95f2b658466..2aa89426dff 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -31,9 +31,7 @@ #include "src/core/lib/support/string.h" #include "src/core/lib/transport/transport_impl.h" -#ifndef NDEBUG -grpc_core::TraceFlag grpc_trace_stream_refcount(false, "stream_refcount"); -#endif +grpc_core::DebugOnlyTraceFlag grpc_trace_stream_refcount(false, "stream_refcount"); #ifndef NDEBUG void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason) { diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 6750f8cca34..2347005c621 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -43,9 +43,7 @@ typedef struct grpc_transport grpc_transport; for a stream. */ typedef struct grpc_stream grpc_stream; -#ifndef NDEBUG -extern grpc_core::TraceFlag grpc_trace_stream_refcount; -#endif +extern grpc_core::DebugOnlyTraceFlag grpc_trace_stream_refcount; typedef struct grpc_stream_refcount { gpr_refcount refs; From c384d81325f828b1201ed7ebf9b9fd46bf3f2b7d Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Sun, 12 Nov 2017 20:14:27 -0800 Subject: [PATCH 12/27] clang fmt --- .../ext/filters/client_channel/resolver.cc | 3 +- .../chttp2/transport/chttp2_transport.cc | 6 ++-- .../ext/transport/chttp2/transport/internal.h | 8 ++--- .../ext/transport/inproc/inproc_transport.cc | 4 +-- src/core/lib/channel/channel_stack_builder.cc | 2 +- src/core/lib/debug/trace.cc | 32 +++++++++---------- src/core/lib/debug/trace.h | 16 +++++----- src/core/lib/iomgr/ev_epollex_linux.cc | 3 +- src/core/lib/iomgr/ev_epollsig_linux.cc | 4 +-- src/core/lib/iomgr/ev_posix.cc | 3 +- src/core/lib/iomgr/ev_windows.cc | 2 +- .../lib/security/context/security_context.cc | 4 +-- src/core/lib/surface/alarm.cc | 3 +- src/core/lib/surface/completion_queue.cc | 25 ++++++--------- src/core/lib/surface/init_secure.cc | 2 +- src/core/lib/transport/transport.cc | 3 +- 16 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver.cc b/src/core/ext/filters/client_channel/resolver.cc index 9daf45b3ec0..c16b1515c7c 100644 --- a/src/core/ext/filters/client_channel/resolver.cc +++ b/src/core/ext/filters/client_channel/resolver.cc @@ -19,7 +19,8 @@ #include "src/core/ext/filters/client_channel/resolver.h" #include "src/core/lib/iomgr/combiner.h" -grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false, "resolver_refcount"); +grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false, + "resolver_refcount"); void grpc_resolver_init(grpc_resolver* resolver, const grpc_resolver_vtable* vtable, diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index cd77dcbe961..b130bfa90e1 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -91,7 +91,8 @@ static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; #define MAX_CLIENT_STREAM_ID 0x7fffffffu grpc_core::TraceFlag grpc_http_trace(false, "http"); -grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); +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, @@ -3112,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_resource_quota_trace.enabled()) { + } 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", diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 17eecbd7fd6..4555b7b0250 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -677,10 +677,10 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, // extern grpc_core::TraceFlag grpc_http_trace; // extern grpc_core::TraceFlag grpc_flowctl_trace; -#define GRPC_CHTTP2_IF_TRACING(stmt) \ - if (!(grpc_http_trace.enabled())) \ - ; \ - 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/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index baefabe1b38..c18f8781aae 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -32,8 +32,8 @@ #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/transport_impl.h" -#define INPROC_LOG(...) \ - do { \ +#define INPROC_LOG(...) \ + do { \ if (grpc_inproc_trace.enabled()) gpr_log(__VA_ARGS__); \ } while (0) diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 5cd274dfc96..2bea27d3c2e 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -24,7 +24,7 @@ #include grpc_core::TraceFlag grpc_trace_channel_stack_builder(false, - "channel_stack_builder"); + "channel_stack_builder"); typedef struct filter_node { struct filter_node* next; diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 5d377135460..304ee48a2fa 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -25,27 +25,27 @@ #include #include "src/core/lib/support/env.h" -int grpc_tracer_set_enabled(const char *name, int enabled); +int grpc_tracer_set_enabled(const char* name, int enabled); namespace grpc_core { TraceFlag* TraceFlag::root_tracer_ = nullptr; -TraceFlag::TraceFlag(bool default_enabled, const char *name) +TraceFlag::TraceFlag(bool default_enabled, const char* name) : next_tracer_(root_tracer_), name_(name), value_(default_enabled) { root_tracer_ = this; } void TraceFlag::LogAllTracers() { gpr_log(GPR_DEBUG, "available tracers:"); - TraceFlag *t; + TraceFlag* t; for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { gpr_log(GPR_DEBUG, "\t%s", t->name_); } } -bool TraceFlag::Set(const char *name, bool enabled) { - TraceFlag *t; +bool TraceFlag::Set(const char* name, bool enabled) { + TraceFlag* t; if (0 == strcmp(name, "all")) { for (t = root_tracer_; t; t = t->next_tracer_) { t->set_enabled(enabled); @@ -76,23 +76,23 @@ bool TraceFlag::Set(const char *name, bool enabled) { } // 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 np = n + 1; - char *s; + char* s; size_t len; GPR_ASSERT(end >= beg); len = (size_t)(end - beg); - s = (char *)gpr_malloc(len + 1); + s = (char*)gpr_malloc(len + 1); memcpy(s, beg, len); s[len] = 0; - *ss = (char **)gpr_realloc(*ss, sizeof(char **) * np); + *ss = (char**)gpr_realloc(*ss, sizeof(char**) * np); (*ss)[n] = s; *ns = np; } -static void split(const char *s, char ***ss, size_t *ns) { - const char *c = strchr(s, ','); +static void split(const char* s, char*** ss, size_t* ns) { + const char* c = strchr(s, ','); if (c == NULL) { add(s, s + strlen(s), ss, ns); } else { @@ -101,8 +101,8 @@ static void split(const char *s, char ***ss, size_t *ns) { } } -static void parse(const char *s) { - char **strings = NULL; +static void parse(const char* s) { + char** strings = NULL; size_t nstrings = 0; size_t i; split(s, &strings, &nstrings); @@ -121,8 +121,8 @@ static void parse(const char *s) { gpr_free(strings); } -void grpc_tracer_init(const char *env_var) { - char *e = gpr_getenv(env_var); +void grpc_tracer_init(const char* env_var) { + char* e = gpr_getenv(env_var); if (e != NULL) { parse(e); gpr_free(e); @@ -131,6 +131,6 @@ void grpc_tracer_init(const char *env_var) { void grpc_tracer_shutdown(void) {} -int grpc_tracer_set_enabled(const char *name, int enabled) { +int grpc_tracer_set_enabled(const char* name, int enabled) { return grpc_core::TraceFlag::Set(name, enabled != 0); } diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 162090a248e..cc9d9d2b2d4 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -27,7 +27,7 @@ extern "C" { #endif -void grpc_tracer_init(const char *env_var_name); +void grpc_tracer_init(const char* env_var_name); void grpc_tracer_shutdown(void); #ifdef __cplusplus @@ -46,10 +46,10 @@ namespace grpc_core { class TraceFlag { public: - TraceFlag(bool default_enabled, const char *name); - ~TraceFlag() { } + TraceFlag(bool default_enabled, const char* name); + ~TraceFlag() {} - static bool Set(const char *tracer, bool enabled); + static bool Set(const char* tracer, bool enabled); const char* name() const { return name_; } @@ -74,9 +74,9 @@ class TraceFlag { private: static void LogAllTracers(); - static TraceFlag *root_tracer_; - TraceFlag *next_tracer_; - const char *const name_; + static TraceFlag* root_tracer_; + TraceFlag* next_tracer_; + const char* const name_; #ifdef GRPC_THREADSAFE_TRACER gpr_atm value_; #else @@ -89,7 +89,7 @@ typedef TraceFlag DebugOnlyTraceFlag; #else class DebugOnlyTraceFlag { public: - DebugOnlyTraceFlag(bool default_enabled, const char *name) {} + DebugOnlyTraceFlag(bool default_enabled, const char* name) {} bool enabled() { return false; } }; #endif diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 9abd569ee01..246634a76f0 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -59,7 +59,8 @@ #define MAX_EPOLL_EVENTS 100 #define MAX_EPOLL_EVENTS_HANDLED_EACH_POLL_CALL 5 -grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false, "pollable_refcount"); +grpc_core::DebugOnlyTraceFlag grpc_trace_pollable_refcount(false, + "pollable_refcount"); /******************************************************************************* * pollable Declarations diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 128c3adbff6..3ee63d71285 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -54,9 +54,9 @@ #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker*)1) -#define GRPC_POLLING_TRACE(...) \ +#define GRPC_POLLING_TRACE(...) \ if (grpc_polling_trace.enabled()) { \ - gpr_log(GPR_INFO, __VA_ARGS__); \ + gpr_log(GPR_INFO, __VA_ARGS__); \ } static int grpc_wakeup_signal = -1; diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 5b4b66b989a..d5ea169cb65 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -36,7 +36,8 @@ #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/support/env.h" -grpc_core::TraceFlag grpc_polling_trace(false, "polling"); /* Disabled by default */ +grpc_core::TraceFlag grpc_polling_trace(false, + "polling"); /* Disabled by default */ grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); /** Default poll() function - a pointer so that it can be overridden by some diff --git a/src/core/lib/iomgr/ev_windows.cc b/src/core/lib/iomgr/ev_windows.cc index cb66de0a06b..697697d0b00 100644 --- a/src/core/lib/iomgr/ev_windows.cc +++ b/src/core/lib/iomgr/ev_windows.cc @@ -23,6 +23,6 @@ #include "src/core/lib/debug/trace.h" grpc_core::TraceFlag grpc_polling_trace(false, - "polling"); /* Disabled by default */ + "polling"); /* Disabled by default */ #endif // GRPC_WINSOCK_SOCKET diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 31e7510d357..e44fcdd65ea 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -29,8 +29,8 @@ #include #include -grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount(false, - "auth_context_refcount"); +grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount( + false, "auth_context_refcount"); /* --- grpc_call --- */ diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index 8ba4a93525d..4247b79fae0 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -27,7 +27,8 @@ #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/surface/completion_queue.h" -grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount(false, "alarm_refcount"); +grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount(false, + "alarm_refcount"); struct grpc_alarm { gpr_refcount refs; diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index b5ae87ee667..ddde82c143e 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -336,13 +336,12 @@ static const cq_vtable g_cq_vtable[] = { grpc_core::TraceFlag grpc_cq_pluck_trace(true, "queue_pluck"); grpc_core::TraceFlag grpc_cq_event_timeout_trace(true, "queue_timeout"); -#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ - if (grpc_api_trace.enabled() && \ - (grpc_cq_pluck_trace.enabled() || \ - (event)->type != GRPC_QUEUE_TIMEOUT)) { \ - char* _ev = grpc_event_string(event); \ - gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ - gpr_free(_ev); \ +#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \ + if (grpc_api_trace.enabled() && (grpc_cq_pluck_trace.enabled() || \ + (event)->type != GRPC_QUEUE_TIMEOUT)) { \ + char* _ev = grpc_event_string(event); \ + gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \ + gpr_free(_ev); \ } static void on_pollset_shutdown_done(grpc_exec_ctx* exec_ctx, void* cq, @@ -648,15 +647,13 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, GPR_TIMER_BEGIN("cq_end_op_for_next", 0); if (grpc_api_trace.enabled() || - (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE)) { + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_next(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); - if (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE) { + if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } @@ -737,15 +734,13 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, GPR_TIMER_BEGIN("cq_end_op_for_pluck", 0); if (grpc_api_trace.enabled() || - (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE)) { + (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE)) { const char* errmsg = grpc_error_string(error); GRPC_API_TRACE( "cq_end_op_for_pluck(exec_ctx=%p, cq=%p, tag=%p, error=%s, " "done=%p, done_arg=%p, storage=%p)", 7, (exec_ctx, cq, tag, errmsg, done, done_arg, storage)); - if (grpc_trace_operation_failures.enabled() && - error != GRPC_ERROR_NONE) { + if (grpc_trace_operation_failures.enabled() && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } } diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index 4df622521b9..95e12d66923 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -24,6 +24,7 @@ #include #include "src/core/lib/debug/trace.h" +#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/plugin/plugin_credentials.h" #include "src/core/lib/security/transport/auth_filters.h" @@ -32,7 +33,6 @@ #include "src/core/lib/security/transport/security_handshaker.h" #include "src/core/lib/surface/channel_init.h" #include "src/core/tsi/transport_security_interface.h" -#include "src/core/lib/security/context/security_context.h" void grpc_security_pre_init(void) {} diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 2aa89426dff..e32ca75d603 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -31,7 +31,8 @@ #include "src/core/lib/support/string.h" #include "src/core/lib/transport/transport_impl.h" -grpc_core::DebugOnlyTraceFlag grpc_trace_stream_refcount(false, "stream_refcount"); +grpc_core::DebugOnlyTraceFlag grpc_trace_stream_refcount(false, + "stream_refcount"); #ifndef NDEBUG void grpc_stream_ref(grpc_stream_refcount* refcount, const char* reason) { From 6bf73e8cf6d9d2ede844ab628a0b88000ffc9afa Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Sun, 12 Nov 2017 20:18:35 -0800 Subject: [PATCH 13/27] Fix test compile --- test/core/transport/connectivity_state_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 8cd7b30b663..d88240bb8b1 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -136,7 +136,7 @@ static void test_subscribe_with_failure_then_destroy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_connectivity_state_trace.value = 1; + grpc_connectivity_state_trace.set_enabled(1); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); From 6870e6f1fdfe150cb5d3b391cf9a6f667e14c50c Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 13 Nov 2017 17:08:48 -0800 Subject: [PATCH 14/27] clang tidy --- .../filters/client_channel/client_channel.cc | 224 +++++++++--------- .../ext/transport/chttp2/transport/parsing.cc | 4 +- src/core/lib/debug/trace.cc | 8 +- .../security/transport/security_connector.cc | 154 ++++++------ src/core/lib/surface/call.cc | 122 +++++----- 5 files changed, 256 insertions(+), 256 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index a4936120de0..04b138305a1 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -114,7 +114,7 @@ static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { buf[len - 1] = '\0'; // Remove trailing 's'. char* decimal_point = strchr(buf, '.'); int nanos = 0; - if (decimal_point != NULL) { + if (decimal_point != nullptr) { *decimal_point = '\0'; nanos = gpr_parse_nonnegative_int(decimal_point + 1); if (nanos == -1) { @@ -140,14 +140,14 @@ static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { static void* method_parameters_create_from_json(const grpc_json* json) { wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; grpc_millis timeout = 0; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) continue; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) continue; if (strcmp(field->key, "waitForReady") == 0) { - if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. - if (!parse_wait_for_ready(field, &wait_for_ready)) return NULL; + if (wait_for_ready != WAIT_FOR_READY_UNSET) return nullptr; // Duplicate. + if (!parse_wait_for_ready(field, &wait_for_ready)) return nullptr; } else if (strcmp(field->key, "timeout") == 0) { - if (timeout > 0) return NULL; // Duplicate. - if (!parse_timeout(field, &timeout)) return NULL; + if (timeout > 0) return nullptr; // Duplicate. + if (!parse_timeout(field, &timeout)) return nullptr; } } method_parameters* value = @@ -233,7 +233,7 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, * - Make it possible for policies to return GRPC_CHANNEL_TRANSIENT_FAILURE. * - Hand over pending picks from old policies during the switch that happens * when resolver provides an update. */ - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { /* cancel picks with wait_for_ready=false */ grpc_lb_policy_cancel_picks_locked( @@ -265,11 +265,11 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, w->lb_policy, grpc_connectivity_state_name(w->state)); } - if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != NULL) { + if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != nullptr) { publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_resolver_channel_saw_error_locked(exec_ctx, w->chand->resolver); GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); - w->chand->lb_policy = NULL; + w->chand->lb_policy = nullptr; } set_channel_connectivity_state_locked(exec_ctx, w->chand, publish_state, GRPC_ERROR_REF(error), "lb_changed"); @@ -317,13 +317,13 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { service_config_parsing_state* parsing_state = (service_config_parsing_state*)arg; if (strcmp(field->key, "retryThrottling") == 0) { - if (parsing_state->retry_throttle_data != NULL) return; // Duplicate. + if (parsing_state->retry_throttle_data != nullptr) return; // Duplicate. if (field->type != GRPC_JSON_OBJECT) return; int max_milli_tokens = 0; int milli_token_ratio = 0; - for (grpc_json* sub_field = field->child; sub_field != NULL; + for (grpc_json* sub_field = field->child; sub_field != nullptr; sub_field = sub_field->next) { - if (sub_field->key == NULL) return; + if (sub_field->key == nullptr) return; if (strcmp(sub_field->key, "maxTokens") == 0) { if (max_milli_tokens != 0) return; // Duplicate. if (sub_field->type != GRPC_JSON_NUMBER) return; @@ -338,7 +338,7 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { uint32_t multiplier = 1; uint32_t decimal_value = 0; const char* decimal_point = strchr(sub_field->value, '.'); - if (decimal_point != NULL) { + if (decimal_point != nullptr) { whole_len = (size_t)(decimal_point - sub_field->value); multiplier = 1000; size_t decimal_len = strlen(decimal_point + 1); @@ -377,18 +377,18 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } // Extract the following fields from the resolver result, if non-NULL. bool lb_policy_updated = false; - char* lb_policy_name_dup = NULL; + char* lb_policy_name_dup = nullptr; bool lb_policy_name_changed = false; - grpc_lb_policy* new_lb_policy = NULL; - char* service_config_json = NULL; - grpc_server_retry_throttle_data* retry_throttle_data = NULL; - grpc_slice_hash_table* method_params_table = NULL; - if (chand->resolver_result != NULL) { + grpc_lb_policy* new_lb_policy = nullptr; + char* service_config_json = nullptr; + grpc_server_retry_throttle_data* retry_throttle_data = nullptr; + grpc_slice_hash_table* method_params_table = nullptr; + if (chand->resolver_result != nullptr) { // Find LB policy name. - const char* lb_policy_name = NULL; + const char* lb_policy_name = nullptr; const grpc_arg* channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); - if (channel_arg != NULL) { + if (channel_arg != nullptr) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); lb_policy_name = channel_arg->value.string; } @@ -396,7 +396,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // the grpclb policy, regardless of what the resolver actually specified. channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); - if (channel_arg != NULL && channel_arg->type == GRPC_ARG_POINTER) { + if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_POINTER) { grpc_lb_addresses* addresses = (grpc_lb_addresses*)channel_arg->value.pointer.p; bool found_balancer_address = false; @@ -407,7 +407,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } } if (found_balancer_address) { - if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { + if (lb_policy_name != nullptr && strcmp(lb_policy_name, "grpclb") != 0) { gpr_log(GPR_INFO, "resolver requested LB policy %s but provided at least one " "balancer address -- forcing use of grpclb LB policy", @@ -418,7 +418,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } // Use pick_first if nothing was specified and we didn't select grpclb // above. - if (lb_policy_name == NULL) lb_policy_name = "pick_first"; + if (lb_policy_name == nullptr) lb_policy_name = "pick_first"; grpc_lb_policy_args lb_policy_args; lb_policy_args.args = chand->resolver_result; lb_policy_args.client_channel_factory = chand->client_channel_factory; @@ -429,9 +429,9 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // only thing that modifies its value, and it can only be invoked // once at any given time. lb_policy_name_changed = - chand->info_lb_policy_name == NULL || + chand->info_lb_policy_name == nullptr || strcmp(chand->info_lb_policy_name, lb_policy_name) != 0; - if (chand->lb_policy != NULL && !lb_policy_name_changed) { + if (chand->lb_policy != nullptr && !lb_policy_name_changed) { // Continue using the same LB policy. Update with new addresses. lb_policy_updated = true; grpc_lb_policy_update_locked(exec_ctx, chand->lb_policy, &lb_policy_args); @@ -439,22 +439,22 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // Instantiate new LB policy. new_lb_policy = grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); - if (new_lb_policy == NULL) { + if (new_lb_policy == nullptr) { gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", lb_policy_name); } } // Find service config. channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVICE_CONFIG); - if (channel_arg != NULL) { + if (channel_arg != nullptr) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); service_config_json = gpr_strdup(channel_arg->value.string); grpc_service_config* service_config = grpc_service_config_create(service_config_json); - if (service_config != NULL) { + if (service_config != nullptr) { channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVER_URI); - GPR_ASSERT(channel_arg != NULL); + GPR_ASSERT(channel_arg != nullptr); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); grpc_uri* uri = grpc_uri_parse(exec_ctx, channel_arg->value.string, true); @@ -478,7 +478,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // The copy will be saved in chand->lb_policy_name below. lb_policy_name_dup = gpr_strdup(lb_policy_name); grpc_channel_args_destroy(exec_ctx, chand->resolver_result); - chand->resolver_result = NULL; + chand->resolver_result = nullptr; } if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, @@ -493,22 +493,22 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // // First, swap out the data used by cc_get_channel_info(). gpr_mu_lock(&chand->info_mu); - if (lb_policy_name_dup != NULL) { + if (lb_policy_name_dup != nullptr) { gpr_free(chand->info_lb_policy_name); chand->info_lb_policy_name = lb_policy_name_dup; } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { gpr_free(chand->info_service_config_json); chand->info_service_config_json = service_config_json; } gpr_mu_unlock(&chand->info_mu); // Swap out the retry throttle data. - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } chand->retry_throttle_data = retry_throttle_data; // Swap out the method params table. - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } chand->method_params_table = method_params_table; @@ -518,9 +518,9 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // Note that we do NOT do this if either (a) we updated the existing // LB policy above or (b) we failed to create the new LB policy (in // which case we want to continue using the most recent one we had). - if (new_lb_policy != NULL || error != GRPC_ERROR_NONE || - chand->resolver == NULL) { - if (chand->lb_policy != NULL) { + if (new_lb_policy != nullptr || error != GRPC_ERROR_NONE || + chand->resolver == nullptr) { + if (chand->lb_policy != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, chand->lb_policy); @@ -534,17 +534,17 @@ 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 == NULL) { + if (error != GRPC_ERROR_NONE || chand->resolver == nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand); } - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); } grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; + chand->resolver = nullptr; } set_channel_connectivity_state_locked( exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, @@ -561,7 +561,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_error* state_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy"); - if (new_lb_policy != NULL) { + if (new_lb_policy != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); } @@ -598,46 +598,46 @@ static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, (grpc_channel_element*)op->handler_private.extra_arg; channel_data* chand = (channel_data*)elem->channel_data; - if (op->on_connectivity_state_change != NULL) { + if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( exec_ctx, &chand->state_tracker, op->connectivity_state, op->on_connectivity_state_change); - op->on_connectivity_state_change = NULL; - op->connectivity_state = NULL; + op->on_connectivity_state_change = nullptr; + op->connectivity_state = nullptr; } - if (op->send_ping != NULL) { - if (chand->lb_policy == NULL) { + if (op->send_ping != nullptr) { + if (chand->lb_policy == nullptr) { GRPC_CLOSURE_SCHED( exec_ctx, op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Ping with no load balancing")); } else { grpc_lb_policy_ping_one_locked(exec_ctx, chand->lb_policy, op->send_ping); - op->bind_pollset = NULL; + op->bind_pollset = nullptr; } - op->send_ping = NULL; + op->send_ping = nullptr; } if (op->disconnect_with_error != GRPC_ERROR_NONE) { - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { set_channel_connectivity_state_locked( exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; + chand->resolver = nullptr; if (!chand->started_resolving) { grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_REF(op->disconnect_with_error)); GRPC_CLOSURE_LIST_SCHED(exec_ctx, &chand->waiting_for_resolver_result_closures); } - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_pollset_set_del_pollset_set(exec_ctx, chand->lb_policy->interested_parties, chand->interested_parties); GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); - chand->lb_policy = NULL; + chand->lb_policy = nullptr; } } GRPC_ERROR_UNREF(op->disconnect_with_error); @@ -653,7 +653,7 @@ static void cc_start_transport_op(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(op->set_accept_stream == false); - if (op->bind_pollset != NULL) { + if (op->bind_pollset != nullptr) { grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, op->bind_pollset); } @@ -672,15 +672,15 @@ static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, const grpc_channel_info* info) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_lock(&chand->info_mu); - if (info->lb_policy_name != NULL) { - *info->lb_policy_name = chand->info_lb_policy_name == NULL - ? NULL + if (info->lb_policy_name != nullptr) { + *info->lb_policy_name = chand->info_lb_policy_name == nullptr + ? nullptr : gpr_strdup(chand->info_lb_policy_name); } - if (info->service_config_json != NULL) { + if (info->service_config_json != nullptr) { *info->service_config_json = - chand->info_service_config_json == NULL - ? NULL + chand->info_service_config_json == nullptr + ? nullptr : gpr_strdup(chand->info_service_config_json); } gpr_mu_unlock(&chand->info_mu); @@ -699,7 +699,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, gpr_mu_init(&chand->external_connectivity_watcher_list_mu); gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); - chand->external_connectivity_watcher_list_head = NULL; + chand->external_connectivity_watcher_list_head = nullptr; gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); chand->owning_stack = args->channel_stack; @@ -713,7 +713,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, // Record client channel factory. const grpc_arg* arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); - if (arg == NULL) { + if (arg == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Missing client channel factory in args for client channel filter"); } @@ -727,7 +727,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, (grpc_client_channel_factory*)arg->value.pointer.p; // Get server name to resolve, using proxy mapper if needed. arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); - if (arg == NULL) { + if (arg == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Missing server uri in args for client channel filter"); } @@ -735,18 +735,18 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "server uri arg must be a string"); } - char* proxy_name = NULL; - grpc_channel_args* new_args = NULL; + char* proxy_name = nullptr; + grpc_channel_args* new_args = nullptr; grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, &proxy_name, &new_args); // Instantiate resolver. chand->resolver = grpc_resolver_create( - exec_ctx, proxy_name != NULL ? proxy_name : arg->value.string, - new_args != NULL ? new_args : args->channel_args, + exec_ctx, proxy_name != nullptr ? proxy_name : arg->value.string, + new_args != nullptr ? new_args : args->channel_args, chand->interested_parties, chand->combiner); - if (proxy_name != NULL) gpr_free(proxy_name); - if (new_args != NULL) grpc_channel_args_destroy(exec_ctx, new_args); - if (chand->resolver == NULL) { + if (proxy_name != nullptr) gpr_free(proxy_name); + if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); + if (chand->resolver == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed"); } chand->deadline_checking_enabled = @@ -765,17 +765,17 @@ static void shutdown_resolver_locked(grpc_exec_ctx* exec_ctx, void* arg, static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { GRPC_CLOSURE_SCHED( exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } - if (chand->client_channel_factory != NULL) { + if (chand->client_channel_factory != nullptr) { grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); } - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_pollset_set_del_pollset_set(exec_ctx, chand->lb_policy->interested_parties, chand->interested_parties); @@ -783,10 +783,10 @@ static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, } gpr_free(chand->info_lb_policy_name); gpr_free(chand->info_service_config_json); - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } grpc_client_channel_stop_backup_polling(exec_ctx, chand->interested_parties); @@ -869,7 +869,7 @@ grpc_subchannel_call* grpc_client_channel_get_subchannel_call( static void waiting_for_pick_batches_add( call_data* calld, grpc_transport_stream_op_batch* batch) { if (batch->send_initial_metadata) { - GPR_ASSERT(calld->initial_metadata_batch == NULL); + GPR_ASSERT(calld->initial_metadata_batch == nullptr); calld->initial_metadata_batch = batch; } else { GPR_ASSERT(calld->waiting_for_pick_batches_count < MAX_WAITING_BATCHES); @@ -911,7 +911,7 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, GRPC_ERROR_REF(error), "waiting_for_pick_batches_fail"); } - if (calld->initial_metadata_batch != NULL) { + if (calld->initial_metadata_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, calld->initial_metadata_batch, GRPC_ERROR_REF(error), calld->call_combiner); @@ -955,7 +955,7 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, GRPC_ERROR_NONE, "waiting_for_pick_batches_resume"); } - GPR_ASSERT(calld->initial_metadata_batch != NULL); + GPR_ASSERT(calld->initial_metadata_batch != nullptr); grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, calld->initial_metadata_batch); } @@ -970,14 +970,14 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", chand, calld); } - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { calld->retry_throttle_data = grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); } - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { calld->method_params = (method_parameters*)grpc_method_config_table_get( exec_ctx, chand->method_params_table, calld->path); - if (calld->method_params != NULL) { + if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one // from the client API, reset the deadline timer. @@ -1030,7 +1030,7 @@ static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_error* error) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - if (calld->connected_subchannel == NULL) { + if (calld->connected_subchannel == nullptr) { // Failed to create subchannel. GRPC_ERROR_UNREF(calld->error); calld->error = error == GRPC_ERROR_NONE @@ -1071,7 +1071,7 @@ static void pick_callback_cancel_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 (calld->lb_policy != NULL) { + if (calld->lb_policy != nullptr) { 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); @@ -1094,9 +1094,9 @@ static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", chand, calld); } - GPR_ASSERT(calld->lb_policy != NULL); + GPR_ASSERT(calld->lb_policy != nullptr); GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); - calld->lb_policy = NULL; + calld->lb_policy = nullptr; async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } @@ -1122,7 +1122,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, initial_metadata_flags & GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET; const bool wait_for_ready_set_from_service_config = - calld->method_params != NULL && + calld->method_params != nullptr && calld->method_params->wait_for_ready != WAIT_FOR_READY_UNSET; if (!wait_for_ready_set_from_api && wait_for_ready_set_from_service_config) { if (calld->method_params->wait_for_ready == WAIT_FOR_READY_TRUE) { @@ -1142,7 +1142,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, grpc_combiner_scheduler(chand->combiner)); const bool pick_done = grpc_lb_policy_pick_locked( exec_ctx, chand->lb_policy, &inputs, &calld->connected_subchannel, - calld->subchannel_call_context, NULL, &calld->lb_pick_closure); + calld->subchannel_call_context, nullptr, &calld->lb_pick_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ if (grpc_client_channel_trace.enabled()) { @@ -1150,7 +1150,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, chand, calld); } GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); - calld->lb_policy = NULL; + calld->lb_policy = nullptr; } else { GRPC_CALL_STACK_REF(calld->owning_call, "pick_callback_cancel"); grpc_call_combiner_set_notify_on_cancel( @@ -1230,7 +1230,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, chand, calld); } async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); - } else if (chand->lb_policy != NULL) { + } else if (chand->lb_policy != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", chand, calld); @@ -1251,7 +1251,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, // removed in https://github.com/grpc/grpc/pull/12297. Need to figure // out what is actually causing this to occur and then figure out the // right way to deal with it. - else if (chand->resolver != NULL) { + else if (chand->resolver != nullptr) { // No LB policy, so try again. if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, @@ -1298,8 +1298,8 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - GPR_ASSERT(calld->connected_subchannel == NULL); - if (chand->lb_policy != NULL) { + GPR_ASSERT(calld->connected_subchannel == nullptr); + if (chand->lb_policy != nullptr) { // We already have an LB policy, so ask it for a pick. if (pick_callback_start_locked(exec_ctx, elem)) { // Pick completed synchronously. @@ -1308,7 +1308,7 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, } } else { // We do not yet have an LB policy, so wait for a resolver result. - if (chand->resolver == NULL) { + if (chand->resolver == nullptr) { pick_done_locked(exec_ctx, elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); return; @@ -1330,7 +1330,7 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - if (calld->retry_throttle_data != NULL) { + if (calld->retry_throttle_data != nullptr) { if (error == GRPC_ERROR_NONE) { grpc_server_retry_throttle_data_record_success( calld->retry_throttle_data); @@ -1381,7 +1381,7 @@ static void cc_start_transport_stream_op_batch( } // If we have a subchannel call, send the cancellation batch down. // Otherwise, fail all pending batches. - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); } else { waiting_for_pick_batches_add(calld, batch); @@ -1393,7 +1393,7 @@ static void cc_start_transport_stream_op_batch( // Intercept on_complete for recv_trailing_metadata so that we can // check retry throttle status. if (batch->recv_trailing_metadata) { - GPR_ASSERT(batch->on_complete != NULL); + GPR_ASSERT(batch->on_complete != nullptr); calld->original_on_complete = batch->on_complete; GRPC_CLOSURE_INIT(&calld->on_complete, on_complete, elem, grpc_schedule_on_exec_ctx); @@ -1403,7 +1403,7 @@ static void cc_start_transport_stream_op_batch( // Note that once we have completed the pick, we do not need to enter // the channel combiner, which is more efficient (especially for // streaming calls). - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { if (grpc_client_channel_trace.enabled()) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, @@ -1472,20 +1472,20 @@ static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_deadline_state_destroy(exec_ctx, elem); } grpc_slice_unref_internal(exec_ctx, calld->path); - if (calld->method_params != NULL) { + if (calld->method_params != nullptr) { method_parameters_unref(calld->method_params); } GRPC_ERROR_UNREF(calld->error); - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { grpc_subchannel_call_set_cleanup_closure(calld->subchannel_call, then_schedule_closure); - then_schedule_closure = NULL; + then_schedule_closure = nullptr; GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, calld->subchannel_call, "client_channel_destroy_call"); } - GPR_ASSERT(calld->lb_policy == NULL); + GPR_ASSERT(calld->lb_policy == nullptr); GPR_ASSERT(calld->waiting_for_pick_batches_count == 0); - if (calld->connected_subchannel != NULL) { + if (calld->connected_subchannel != nullptr) { GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, calld->connected_subchannel, "picked"); } @@ -1526,11 +1526,11 @@ const grpc_channel_filter grpc_client_channel_filter = { static void try_to_connect_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error_ignored) { channel_data* chand = (channel_data*)arg; - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); } else { chand->exit_idle_when_lb_policy_arrives = true; - if (!chand->started_resolving && chand->resolver != NULL) { + if (!chand->started_resolving && chand->resolver != nullptr) { start_resolving_locked(exec_ctx, chand); } } @@ -1568,7 +1568,7 @@ static external_connectivity_watcher* lookup_external_connectivity_watcher( gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL && w->on_complete != on_complete) { + while (w != nullptr && w->on_complete != on_complete) { w = w->next; } gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); @@ -1598,7 +1598,7 @@ static void external_connectivity_watcher_list_remove( } external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL) { + while (w != nullptr) { if (w->next == too_remove) { w->next = w->next->next; gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); @@ -1617,7 +1617,7 @@ int grpc_client_channel_num_external_connectivity_watchers( gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL) { + while (w != nullptr) { count++; w = w->next; } @@ -1642,8 +1642,8 @@ static void on_external_watch_complete_locked(grpc_exec_ctx* exec_ctx, static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error_ignored) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; - external_connectivity_watcher* found = NULL; - if (w->state != NULL) { + external_connectivity_watcher* found = nullptr; + if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete_locked, w, @@ -1651,12 +1651,12 @@ static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_connectivity_state_notify_on_state_change( exec_ctx, &w->chand->state_tracker, w->state, &w->my_closure); } else { - GPR_ASSERT(w->watcher_timer_init == NULL); + GPR_ASSERT(w->watcher_timer_init == nullptr); found = lookup_external_connectivity_watcher(w->chand, w->on_complete); if (found) { GPR_ASSERT(found->on_complete == w->on_complete); grpc_connectivity_state_notify_on_state_change( - exec_ctx, &found->chand->state_tracker, NULL, &found->my_closure); + exec_ctx, &found->chand->state_tracker, nullptr, &found->my_closure); } grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, w->chand->interested_parties); diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 80f12c1022a..f8775d59264 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -252,10 +252,10 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, t->incoming_frame_size -= (uint32_t)(end - cur); return GRPC_ERROR_NONE; } - GPR_UNREACHABLE_CODE(return 0); + GPR_UNREACHABLE_CODE(return nullptr); } - GPR_UNREACHABLE_CODE(return 0); + GPR_UNREACHABLE_CODE(return nullptr); } static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 304ee48a2fa..5df2229aae3 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -54,7 +54,7 @@ bool TraceFlag::Set(const char* name, bool enabled) { LogAllTracers(); } else if (0 == strcmp(name, "refcount")) { for (t = root_tracer_; t; t = t->next_tracer_) { - if (strstr(t->name_, "refcount") != NULL) { + if (strstr(t->name_, "refcount") != nullptr) { t->set_enabled(enabled); } } @@ -93,7 +93,7 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) { static void split(const char* s, char*** ss, size_t* ns) { const char* c = strchr(s, ','); - if (c == NULL) { + if (c == nullptr) { add(s, s + strlen(s), ss, ns); } else { add(s, c, ss, ns); @@ -102,7 +102,7 @@ static void split(const char* s, char*** ss, size_t* ns) { } static void parse(const char* s) { - char** strings = NULL; + char** strings = nullptr; size_t nstrings = 0; size_t i; split(s, &strings, &nstrings); @@ -123,7 +123,7 @@ static void parse(const char* s) { void grpc_tracer_init(const char* env_var) { char* e = gpr_getenv(env_var); - if (e != NULL) { + if (e != nullptr) { parse(e); gpr_free(e); } diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 308fdce05b4..93e6896f702 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -58,7 +58,7 @@ static const char* installed_roots_path = /* -- Overridden default roots. -- */ -static grpc_ssl_roots_override_callback ssl_roots_override_cb = NULL; +static grpc_ssl_roots_override_callback ssl_roots_override_cb = nullptr; void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) { ssl_roots_override_cb = cb; @@ -72,11 +72,11 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) { "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384" static gpr_once cipher_suites_once = GPR_ONCE_INIT; -static const char* cipher_suites = NULL; +static const char* cipher_suites = nullptr; static void init_cipher_suites(void) { char* overridden = gpr_getenv("GRPC_SSL_CIPHER_SUITES"); - cipher_suites = overridden != NULL ? overridden : GRPC_SSL_CIPHER_SUITES; + cipher_suites = overridden != nullptr ? overridden : GRPC_SSL_CIPHER_SUITES; } static const char* ssl_cipher_suites(void) { @@ -90,7 +90,7 @@ static const char* ssl_cipher_suites(void) { const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, const char* name) { size_t i; - if (peer == NULL) return NULL; + if (peer == nullptr) return nullptr; for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* property = &peer->properties[i]; if (name == NULL && property->name == NULL) { @@ -101,13 +101,13 @@ const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, return property; } } - return NULL; + return nullptr; } void grpc_channel_security_connector_add_handshakers( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr) { - if (connector != NULL) { + if (connector != nullptr) { connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } @@ -115,7 +115,7 @@ void grpc_channel_security_connector_add_handshakers( void grpc_server_security_connector_add_handshakers( grpc_exec_ctx* exec_ctx, grpc_server_security_connector* connector, grpc_handshake_manager* handshake_mgr) { - if (connector != NULL) { + if (connector != nullptr) { connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } @@ -125,7 +125,7 @@ void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - if (sc == NULL) { + if (sc == nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check peer -- no security connector")); @@ -137,7 +137,7 @@ void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, int grpc_security_connector_cmp(grpc_security_connector* sc, grpc_security_connector* other) { - if (sc == NULL || other == NULL) return GPR_ICMP(sc, other); + if (sc == nullptr || other == nullptr) return GPR_ICMP(sc, other); int c = GPR_ICMP(sc->vtable, other->vtable); if (c != 0) return c; return sc->vtable->cmp(sc, other); @@ -145,8 +145,8 @@ int grpc_security_connector_cmp(grpc_security_connector* sc, int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, grpc_channel_security_connector* sc2) { - GPR_ASSERT(sc1->channel_creds != NULL); - GPR_ASSERT(sc2->channel_creds != NULL); + GPR_ASSERT(sc1->channel_creds != nullptr); + GPR_ASSERT(sc2->channel_creds != nullptr); int c = GPR_ICMP(sc1->channel_creds, sc2->channel_creds); if (c != 0) return c; c = GPR_ICMP(sc1->request_metadata_creds, sc2->request_metadata_creds); @@ -161,8 +161,8 @@ int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, grpc_server_security_connector* sc2) { - GPR_ASSERT(sc1->server_creds != NULL); - GPR_ASSERT(sc2->server_creds != NULL); + GPR_ASSERT(sc1->server_creds != nullptr); + GPR_ASSERT(sc2->server_creds != nullptr); int c = GPR_ICMP(sc1->server_creds, sc2->server_creds); if (c != 0) return c; return GPR_ICMP((void*)sc1->add_handshakers, (void*)sc2->add_handshakers); @@ -172,7 +172,7 @@ bool grpc_channel_security_connector_check_call_host( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, grpc_error** error) { - if (sc == NULL || sc->check_call_host == NULL) { + if (sc == nullptr || sc->check_call_host == nullptr) { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check call host -- no security connector"); return true; @@ -184,7 +184,7 @@ bool grpc_channel_security_connector_check_call_host( void grpc_channel_security_connector_cancel_check_call_host( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, grpc_error* error) { - if (sc == NULL || sc->cancel_check_call_host == NULL) { + if (sc == nullptr || sc->cancel_check_call_host == nullptr) { GRPC_ERROR_UNREF(error); return; } @@ -195,7 +195,7 @@ void grpc_channel_security_connector_cancel_check_call_host( grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* sc, const char* file, int line, const char* reason) { - if (sc == NULL) return NULL; + if (sc == nullptr) return nullptr; if (grpc_trace_security_connector_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -216,7 +216,7 @@ void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, const char* file, int line, const char* reason) { - if (sc == NULL) return; + if (sc == nullptr) return; if (grpc_trace_security_connector_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -255,11 +255,11 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) { } grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return NULL; + if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_ARG_SECURITY_CONNECTOR); - return NULL; + return nullptr; } return (grpc_security_connector*)arg->value.pointer.p; } @@ -267,13 +267,13 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { grpc_security_connector* grpc_security_connector_find_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_security_connector* sc = grpc_security_connector_from_arg(&args->args[i]); if (sc != NULL) return sc; } - return NULL; + return nullptr; } static tsi_client_certificate_request_type @@ -326,9 +326,9 @@ static void fake_server_destroy(grpc_exec_ctx* exec_ctx, static bool fake_check_target(const char* target_type, const char* target, const char* set_str) { - GPR_ASSERT(target_type != NULL); - GPR_ASSERT(target != NULL); - char** set = NULL; + GPR_ASSERT(target_type != nullptr); + GPR_ASSERT(target != nullptr); + char** set = nullptr; size_t set_size = 0; gpr_string_split(set_str, ",", &set, &set_size); bool found = false; @@ -345,8 +345,8 @@ static bool fake_check_target(const char* target_type, const char* target, static void fake_secure_name_check(const char* target, const char* expected_targets, bool is_lb_channel) { - if (expected_targets == NULL) return; - char** lbs_and_backends = NULL; + if (expected_targets == nullptr) return; + char** lbs_and_backends = nullptr; size_t lbs_and_backends_size = 0; bool success = false; gpr_string_split(expected_targets, ";", &lbs_and_backends, @@ -392,18 +392,18 @@ static void fake_check_peer(grpc_exec_ctx* exec_ctx, grpc_closure* on_peer_checked) { const char* prop_name; grpc_error* error = GRPC_ERROR_NONE; - *auth_context = NULL; + *auth_context = nullptr; if (peer.property_count != 1) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Fake peers should only have 1 property."); goto end; } prop_name = peer.properties[0].name; - if (prop_name == NULL || + if (prop_name == nullptr || strcmp(prop_name, TSI_CERTIFICATE_TYPE_PEER_PROPERTY)) { char* msg; gpr_asprintf(&msg, "Unexpected property in fake peer: %s.", - prop_name == NULL ? "" : prop_name); + prop_name == nullptr ? "" : prop_name); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); goto end; @@ -414,7 +414,7 @@ static void fake_check_peer(grpc_exec_ctx* exec_ctx, "Invalid value for cert type property."); goto end; } - *auth_context = grpc_auth_context_create(NULL); + *auth_context = grpc_auth_context_create(nullptr); grpc_auth_context_add_cstring_property( *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_FAKE_TRANSPORT_SECURITY_TYPE); @@ -450,7 +450,7 @@ static int fake_channel_cmp(grpc_security_connector* sc1, if (c != 0) return c; c = strcmp(c1->target, c2->target); if (c != 0) return c; - if (c1->expected_targets == NULL || c2->expected_targets == NULL) { + if (c1->expected_targets == nullptr || c2->expected_targets == nullptr) { c = GPR_ICMP(c1->expected_targets, c2->expected_targets); } else { c = strcmp(c1->expected_targets, c2->expected_targets); @@ -525,7 +525,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( c->target = gpr_strdup(target); const char* expected_targets = grpc_fake_transport_get_expected_targets(args); c->expected_targets = gpr_strdup(expected_targets); - c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL); + c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != nullptr); return &c->base; } @@ -558,11 +558,11 @@ typedef struct { static bool server_connector_has_cert_config_fetcher( grpc_ssl_server_security_connector* c) { - GPR_ASSERT(c != NULL); + GPR_ASSERT(c != nullptr); grpc_ssl_server_credentials* server_creds = (grpc_ssl_server_credentials*)c->base.server_creds; - GPR_ASSERT(server_creds != NULL); - return server_creds->certificate_config_fetcher.cb != NULL; + GPR_ASSERT(server_creds != nullptr); + return server_creds->certificate_config_fetcher.cb != nullptr; } static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, @@ -572,9 +572,9 @@ static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_credentials_unref(exec_ctx, c->base.channel_creds); grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory); - c->client_handshaker_factory = NULL; - if (c->target_name != NULL) gpr_free(c->target_name); - if (c->overridden_target_name != NULL) gpr_free(c->overridden_target_name); + c->client_handshaker_factory = nullptr; + if (c->target_name != nullptr) gpr_free(c->target_name); + if (c->overridden_target_name != nullptr) gpr_free(c->overridden_target_name); gpr_free(sc); } @@ -584,7 +584,7 @@ static void ssl_server_destroy(grpc_exec_ctx* exec_ctx, (grpc_ssl_server_security_connector*)sc; grpc_server_credentials_unref(exec_ctx, c->base.server_creds); tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory); - c->server_handshaker_factory = NULL; + c->server_handshaker_factory = nullptr; gpr_free(sc); } @@ -594,10 +594,10 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; // Instantiate TSI handshaker. - tsi_handshaker* tsi_hs = NULL; + tsi_handshaker* tsi_hs = nullptr; tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( c->client_handshaker_factory, - c->overridden_target_name != NULL ? c->overridden_target_name + c->overridden_target_name != nullptr ? c->overridden_target_name : c->target_name, &tsi_hs); if (result != TSI_OK) { @@ -630,7 +630,7 @@ static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { static bool try_replace_server_handshaker_factory( grpc_ssl_server_security_connector* sc, const grpc_ssl_server_certificate_config* config) { - if (config == NULL) { + if (config == nullptr) { gpr_log(GPR_ERROR, "Server certificate config callback returned invalid (NULL) " "config."); @@ -643,7 +643,7 @@ static bool try_replace_server_handshaker_factory( fill_alpn_protocol_strings(&num_alpn_protocols); tsi_ssl_pem_key_cert_pair* cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs( config->pem_key_cert_pairs, config->num_key_cert_pairs); - tsi_ssl_server_handshaker_factory* new_handshaker_factory = NULL; + tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr; grpc_ssl_server_credentials* server_creds = (grpc_ssl_server_credentials*)sc->base.server_creds; tsi_result result = tsi_create_ssl_server_handshaker_factory_ex( @@ -670,10 +670,10 @@ static bool try_replace_server_handshaker_factory( * an error. Returns true if new credentials were sucessfully loaded. */ static bool try_fetch_ssl_server_credentials( grpc_ssl_server_security_connector* sc) { - grpc_ssl_server_certificate_config* certificate_config = NULL; + grpc_ssl_server_certificate_config* certificate_config = nullptr; bool status; - GPR_ASSERT(sc != NULL); + GPR_ASSERT(sc != nullptr); if (!server_connector_has_cert_config_fetcher(sc)) return false; grpc_ssl_server_credentials* server_creds = @@ -695,7 +695,7 @@ static bool try_fetch_ssl_server_credentials( status = false; } - if (certificate_config != NULL) { + if (certificate_config != nullptr) { grpc_ssl_server_certificate_config_destroy(certificate_config); } return status; @@ -708,7 +708,7 @@ static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, (grpc_ssl_server_security_connector*)sc; // Instantiate TSI handshaker. try_fetch_ssl_server_credentials(c); - tsi_handshaker* tsi_hs = NULL; + tsi_handshaker* tsi_hs = nullptr; tsi_result result = tsi_ssl_server_handshaker_factory_create_handshaker( c->server_handshaker_factory, &tsi_hs); if (result != TSI_OK) { @@ -724,10 +724,10 @@ static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, } static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { - char* allocated_name = NULL; + char* allocated_name = nullptr; int r; - if (strchr(peer_name, ':') != NULL) { + if (strchr(peer_name, ':') != nullptr) { char* ignored_port; gpr_split_host_port(peer_name, &allocated_name, &ignored_port); gpr_free(ignored_port); @@ -741,12 +741,12 @@ static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) { size_t i; - grpc_auth_context* ctx = NULL; - const char* peer_identity_property_name = NULL; + grpc_auth_context* ctx = nullptr; + const char* peer_identity_property_name = nullptr; /* The caller has checked the certificate type property. */ GPR_ASSERT(peer->property_count >= 1); - ctx = grpc_auth_context_create(NULL); + ctx = grpc_auth_context_create(nullptr); grpc_auth_context_add_cstring_property( ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_SSL_TRANSPORT_SECURITY_TYPE); @@ -770,7 +770,7 @@ grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) { prop->value.data, prop->value.length); } } - if (peer_identity_property_name != NULL) { + if (peer_identity_property_name != nullptr) { GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name( ctx, peer_identity_property_name) == 1); } @@ -783,7 +783,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, /* Check the ALPN. */ const tsi_peer_property* p = tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); - if (p == NULL) { + if (p == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Cannot check peer: missing selected ALPN property."); } @@ -793,7 +793,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, } /* Check the peer name if specified. */ - if (peer_name != NULL && !ssl_host_matches_name(peer, peer_name)) { + if (peer_name != nullptr && !ssl_host_matches_name(peer, peer_name)) { char* msg; gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name); grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); @@ -811,7 +811,7 @@ static void ssl_channel_check_peer(grpc_exec_ctx* exec_ctx, grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; grpc_error* error = ssl_check_peer(sc, - c->overridden_target_name != NULL + c->overridden_target_name != nullptr ? c->overridden_target_name : c->target_name, &peer, auth_context); @@ -823,7 +823,7 @@ static void ssl_server_check_peer(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - grpc_error* error = ssl_check_peer(sc, NULL, &peer, auth_context); + grpc_error* error = ssl_check_peer(sc, nullptr, &peer, auth_context); tsi_peer_destruct(&peer); GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); } @@ -838,8 +838,8 @@ static int ssl_channel_cmp(grpc_security_connector* sc1, if (c != 0) return c; c = strcmp(c1->target_name, c2->target_name); if (c != 0) return c; - return (c1->overridden_target_name == NULL || - c2->overridden_target_name == NULL) + return (c1->overridden_target_name == nullptr || + c2->overridden_target_name == nullptr) ? GPR_ICMP(c1->overridden_target_name, c2->overridden_target_name) : strcmp(c1->overridden_target_name, c2->overridden_target_name); } @@ -875,7 +875,7 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props * sizeof(tsi_peer_property)); it = grpc_auth_context_property_iterator(auth_context); - while ((prop = grpc_auth_property_iterator_next(&it)) != NULL) { + while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) { if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) { add_shallow_auth_property_to_peer( &peer, prop, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY); @@ -892,7 +892,7 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( } void tsi_shallow_peer_destruct(tsi_peer* peer) { - if (peer->properties != NULL) gpr_free(peer->properties); + if (peer->properties != nullptr) gpr_free(peer->properties); } static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, @@ -909,7 +909,7 @@ static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, /* If the target name was overridden, then the original target_name was 'checked' transitively during the previous peer check at the end of the handshake. */ - if (c->overridden_target_name != NULL && strcmp(host, c->target_name) == 0) { + if (c->overridden_target_name != nullptr && strcmp(host, c->target_name) == 0) { status = GRPC_SECURITY_OK; } if (status != GRPC_SECURITY_OK) { @@ -939,7 +939,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) { /* First try to load the roots from the environment. */ char* default_root_certs_path = gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR); - if (default_root_certs_path != NULL) { + if (default_root_certs_path != nullptr) { GRPC_LOG_IF_ERROR("load_file", grpc_load_file(default_root_certs_path, 1, &result)); gpr_free(default_root_certs_path); @@ -948,10 +948,10 @@ static grpc_slice compute_default_pem_root_certs_once(void) { /* Try overridden roots if needed. */ grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL; if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != NULL) { - char* pem_root_certs = NULL; + char* pem_root_certs = nullptr; ovrd_res = ssl_roots_override_cb(&pem_root_certs); if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) { - GPR_ASSERT(pem_root_certs != NULL); + GPR_ASSERT(pem_root_certs != nullptr); result = grpc_slice_from_copied_buffer( pem_root_certs, strlen(pem_root_certs) + 1); // NULL terminator. @@ -1002,13 +1002,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create( char* port; bool has_key_cert_pair; - if (config == NULL || target_name == NULL) { + if (config == nullptr || target_name == nullptr) { gpr_log(GPR_ERROR, "An ssl channel needs a config and a target name."); goto error; } - if (config->pem_root_certs == NULL) { + if (config->pem_root_certs == nullptr) { pem_root_certs = grpc_get_default_ssl_roots(); - if (pem_root_certs == NULL) { + if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); goto error; } @@ -1030,13 +1030,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create( c->base.add_handshakers = ssl_channel_add_handshakers; gpr_split_host_port(target_name, &c->target_name, &port); gpr_free(port); - if (overridden_target_name != NULL) { + if (overridden_target_name != nullptr) { c->overridden_target_name = gpr_strdup(overridden_target_name); } - has_key_cert_pair = config->pem_key_cert_pair != NULL && - config->pem_key_cert_pair->private_key != NULL && - config->pem_key_cert_pair->cert_chain != NULL; + has_key_cert_pair = config->pem_key_cert_pair != nullptr && + config->pem_key_cert_pair->private_key != nullptr && + config->pem_key_cert_pair->cert_chain != nullptr; result = tsi_create_ssl_client_handshaker_factory( has_key_cert_pair ? config->pem_key_cert_pair : NULL, pem_root_certs, ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols, @@ -1045,7 +1045,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); ssl_channel_destroy(exec_ctx, &c->base.base); - *sc = NULL; + *sc = nullptr; goto error; } *sc = &c->base; @@ -1079,8 +1079,8 @@ grpc_security_status grpc_ssl_server_security_connector_create( (grpc_ssl_server_credentials*)gsc; grpc_security_status retval = GRPC_SECURITY_OK; - GPR_ASSERT(server_credentials != NULL); - GPR_ASSERT(sc != NULL); + GPR_ASSERT(server_credentials != nullptr); + GPR_ASSERT(sc != nullptr); grpc_ssl_server_security_connector* c = grpc_ssl_server_security_connector_initialize(gsc); @@ -1113,8 +1113,8 @@ grpc_security_status grpc_ssl_server_security_connector_create( if (retval == GRPC_SECURITY_OK) { *sc = &c->base; } else { - if (c != NULL) ssl_server_destroy(exec_ctx, &c->base.base); - if (sc != NULL) *sc = NULL; + if (c != nullptr) ssl_server_destroy(exec_ctx, &c->base.base); + if (sc != nullptr) *sc = nullptr; } return retval; } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 173f6985f70..4e3290ac4dd 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -306,7 +306,7 @@ void* grpc_call_arena_alloc(grpc_call* call, size_t size) { static parent_call* get_or_create_parent_call(grpc_call* call) { parent_call* p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); - if (p == NULL) { + if (p == nullptr) { p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p)); gpr_mu_init(&p->child_list_mu); if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm)NULL, (gpr_atm)p)) { @@ -344,7 +344,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, call->start_time = gpr_now(GPR_CLOCK_MONOTONIC); /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); - call->is_client = args->server_transport_data == NULL; + call->is_client = args->server_transport_data == nullptr; if (call->is_client) { GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx); } else { @@ -377,7 +377,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, bool immediately_cancel = false; - if (args->parent != NULL) { + if (args->parent != nullptr) { child_call* cc = call->child = (child_call*)gpr_arena_alloc(arena, sizeof(child_call)); call->child->parent = args->parent; @@ -405,7 +405,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, } grpc_call_context_set(call, GRPC_CONTEXT_TRACING, args->parent->context[GRPC_CONTEXT_TRACING].value, - NULL); + nullptr); } else if (args->propagation_mask & GRPC_PROPAGATE_CENSUS_STATS_CONTEXT) { add_init_error(&error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Census context propagation requested " @@ -418,7 +418,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, } } - if (pc->first_child == NULL) { + if (pc->first_child == nullptr) { pc->first_child = call; cc->sibling_next = cc->sibling_prev = call; } else { @@ -453,15 +453,15 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); } - if (args->cq != NULL) { + if (args->cq != nullptr) { GPR_ASSERT( - args->pollset_set_alternative == NULL && + args->pollset_set_alternative == nullptr && "Only one of 'cq' and 'pollset_set_alternative' should be non-NULL."); GRPC_CQ_INTERNAL_REF(args->cq, "bind"); call->pollent = grpc_polling_entity_create_from_pollset(grpc_cq_pollset(args->cq)); } - if (args->pollset_set_alternative != NULL) { + if (args->pollset_set_alternative != nullptr) { call->pollent = grpc_polling_entity_create_from_pollset_set( args->pollset_set_alternative); } @@ -480,7 +480,7 @@ void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_completion_queue* cq) { GPR_ASSERT(cq); - if (grpc_polling_entity_pollset_set(&call->pollent) != NULL) { + if (grpc_polling_entity_pollset_set(&call->pollent) != nullptr) { gpr_log(GPR_ERROR, "A pollset_set is already registered for this call."); abort(); } @@ -526,11 +526,11 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, grpc_metadata_batch_destroy( exec_ctx, &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); } - if (c->receiving_stream != NULL) { + if (c->receiving_stream != nullptr) { grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } parent_call* pc = get_parent_call(c); - if (pc != NULL) { + if (pc != nullptr) { gpr_mu_destroy(&pc->child_list_mu); } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { @@ -546,7 +546,7 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, } get_final_status(exec_ctx, c, set_status_value_directly, - &c->final_info.final_status, NULL); + &c->final_info.final_status, nullptr); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); @@ -578,7 +578,7 @@ void grpc_call_unref(grpc_call* c) { if (c == pc->first_child) { pc->first_child = cc->sibling_next; if (c == pc->first_child) { - pc->first_child = NULL; + pc->first_child = nullptr; } } cc->sibling_prev->child->sibling_next = cc->sibling_next; @@ -599,7 +599,7 @@ void grpc_call_unref(grpc_call* c) { // effect of scheduling the previously set cancellation closure, if // any, so that it can release any internal references it may be // holding to the call stack. - grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, NULL); + grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, nullptr); } GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); grpc_exec_ctx_finish(&exec_ctx); @@ -643,9 +643,9 @@ static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, char* grpc_call_get_peer(grpc_call* call) { char* peer_string = (char*)gpr_atm_acq_load(&call->peer_string); - if (peer_string != NULL) return gpr_strdup(peer_string); + if (peer_string != nullptr) return gpr_strdup(peer_string); peer_string = grpc_channel_get_target(call->channel); - if (peer_string != NULL) return peer_string; + if (peer_string != nullptr) return peer_string; return gpr_strdup("unknown"); } @@ -666,7 +666,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", 4, (c, (int)status, description, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); cancel_with_status(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, status, description); grpc_exec_ctx_finish(&exec_ctx); @@ -741,13 +741,13 @@ static bool get_final_status_from(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_status_code code; grpc_slice slice = grpc_empty_slice(); grpc_error_get_status(exec_ctx, error, call->send_deadline, &code, &slice, - NULL); + nullptr); if (code == GRPC_STATUS_OK && !allow_ok_status) { return false; } set_value(code, set_value_user_data); - if (details != NULL) { + if (details != nullptr) { *details = grpc_slice_ref_internal(slice); } return true; @@ -867,7 +867,7 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != NULL) { + if (accepted_user_data != nullptr) { call->encodings_accepted_by_peer = (uint32_t)(((uintptr_t)accepted_user_data) - 1); return; @@ -914,7 +914,7 @@ static void set_stream_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != NULL) { + if (accepted_user_data != nullptr) { call->stream_encodings_accepted_by_peer = (uint32_t)(((uintptr_t)accepted_user_data) - 1); return; @@ -1051,7 +1051,7 @@ static uint32_t decode_status(grpc_mdelem md) { if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_1)) return 1; if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2; user_data = grpc_mdelem_get_user_data(md, destroy_status); - if (user_data != NULL) { + if (user_data != nullptr) { status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; } else { if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) { @@ -1107,7 +1107,7 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, dest->metadata = (grpc_metadata*)gpr_realloc( dest->metadata, sizeof(grpc_metadata) * dest->capacity); } - for (grpc_linked_mdelem* l = b->list.head; l != NULL; l = l->next) { + for (grpc_linked_mdelem* l = b->list.head; l != nullptr; l = l->next) { mdusr = &dest->metadata[dest->count++]; /* we pass back borrowed slices that are valid whilst the call is valid */ mdusr->key = GRPC_MDKEY(l->md); @@ -1118,8 +1118,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_metadata_batch* b) { - if (b->idx.named.content_encoding != NULL) { - if (b->idx.named.grpc_encoding != NULL) { + if (b->idx.named.content_encoding != nullptr) { + if (b->idx.named.grpc_encoding != nullptr) { gpr_log(GPR_ERROR, "Received both content-encoding and grpc-encoding header. " "Ignoring grpc-encoding."); @@ -1130,21 +1130,21 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, call, decode_stream_compression(b->idx.named.content_encoding->md)); GPR_TIMER_END("incoming_stream_compression_algorithm", 0); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_encoding); - } else if (b->idx.named.grpc_encoding != NULL) { + } else if (b->idx.named.grpc_encoding != nullptr) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm( call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); } - if (b->idx.named.grpc_accept_encoding != NULL) { + if (b->idx.named.grpc_accept_encoding != nullptr) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.grpc_accept_encoding->md); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } - if (b->idx.named.accept_encoding != NULL) { + if (b->idx.named.accept_encoding != nullptr) { GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); set_stream_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.accept_encoding->md); @@ -1157,7 +1157,7 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, grpc_metadata_batch* b) { grpc_call* call = (grpc_call*)args; - if (b->idx.named.grpc_status != NULL) { + if (b->idx.named.grpc_status != nullptr) { uint32_t status_code = decode_status(b->idx.named.grpc_status->md); grpc_error* error = status_code == GRPC_STATUS_OK @@ -1166,7 +1166,7 @@ static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, "Error received from peer"), GRPC_ERROR_INT_GRPC_STATUS, (intptr_t)status_code); - if (b->idx.named.grpc_message != NULL) { + if (b->idx.named.grpc_message != nullptr) { error = grpc_error_set_str( error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); @@ -1239,13 +1239,13 @@ static batch_control* allocate_batch_control(grpc_call* call, size_t num_ops) { int slot = batch_slot_for_op(ops[0].op); batch_control** pslot = &call->active_batches[slot]; - if (*pslot == NULL) { + if (*pslot == nullptr) { *pslot = (batch_control*)gpr_arena_alloc(call->arena, sizeof(batch_control)); } batch_control* bctl = *pslot; - if (bctl->call != NULL) { - return NULL; + if (bctl->call != nullptr) { + return nullptr; } memset(bctl, 0, sizeof(*bctl)); bctl->call = call; @@ -1257,7 +1257,7 @@ static void finish_batch_completion(grpc_exec_ctx* exec_ctx, void* user_data, grpc_cq_completion* storage) { batch_control* bctl = (batch_control*)user_data; grpc_call* call = bctl->call; - bctl->call = NULL; + bctl->call = nullptr; GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } @@ -1269,7 +1269,7 @@ static grpc_error* consolidate_batch_errors(batch_control* bctl) { /* Skip creating a composite error in the case that only one error was logged */ grpc_error* e = bctl->errors[0]; - bctl->errors[0] = NULL; + bctl->errors[0] = nullptr; return e; } else { grpc_error* error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -1309,11 +1309,11 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, /* propagate cancellation to any interested children */ gpr_atm_rel_store(&call->received_final_op_atm, 1); parent_call* pc = get_parent_call(call); - if (pc != NULL) { + if (pc != nullptr) { grpc_call* child; gpr_mu_lock(&pc->child_list_mu); child = pc->first_child; - if (child != NULL) { + if (child != nullptr) { do { next_child_call = child->child->sibling_next; if (child->cancellation_is_inherited) { @@ -1334,21 +1334,21 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, call->final_op.client.status_details); } else { get_final_status(exec_ctx, call, set_cancelled_value, - call->final_op.server.cancelled, NULL); + call->final_op.server.cancelled, nullptr); } GRPC_ERROR_UNREF(error); error = GRPC_ERROR_NONE; } if (error != GRPC_ERROR_NONE && bctl->op.recv_message && - *call->receiving_buffer != NULL) { + *call->receiving_buffer != nullptr) { grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; } if (bctl->completion_data.notify_tag.is_closure) { /* unrefs bctl->error */ - bctl->call = NULL; + bctl->call = nullptr; GRPC_CLOSURE_RUN( exec_ctx, (grpc_closure*)bctl->completion_data.notify_tag.tag, error); GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); @@ -1376,7 +1376,7 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, if (remaining == 0) { call->receiving_message = 0; grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; finish_batch_step(exec_ctx, bctl); return; } @@ -1389,9 +1389,9 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, call->receiving_slice); } else { grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); return; @@ -1428,9 +1428,9 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error)); } grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); if (release_error) { @@ -1442,8 +1442,8 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, static void process_data_after_md(grpc_exec_ctx* exec_ctx, batch_control* bctl) { grpc_call* call = bctl->call; - if (call->receiving_stream == NULL) { - *call->receiving_buffer = NULL; + if (call->receiving_stream == nullptr) { + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); } else { @@ -1466,9 +1466,9 @@ static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; if (error != GRPC_ERROR_NONE) { - if (call->receiving_stream != NULL) { + if (call->receiving_stream != nullptr) { grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; } add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), true); cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, @@ -1477,7 +1477,7 @@ static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, /* If recv_state is RECV_NONE, we will save the batch_control * object with rel_cas, and will not use it after the cas. Its corresponding * acq_load is in receiving_initial_metadata_ready() */ - if (error != GRPC_ERROR_NONE || call->receiving_stream == NULL || + if (error != GRPC_ERROR_NONE || call->receiving_stream == nullptr || !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) { process_data_after_md(exec_ctx, bctl); } @@ -1503,7 +1503,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, GRPC_STREAM_COMPRESS_NONE) { const grpc_stream_compression_algorithm algo = call->incoming_stream_compression_algorithm; - char* error_msg = NULL; + char* error_msg = nullptr; const grpc_compression_options compression_options = grpc_channel_compression_options(call->channel); if (algo >= GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) { @@ -1515,7 +1515,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (grpc_compression_options_is_stream_compression_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_stream_compression_algorithm_name(algo, &algo_name); gpr_asprintf(&error_msg, "Stream compression algorithm '%s' is disabled.", algo_name); @@ -1529,7 +1529,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, if (!GPR_BITGET(call->stream_encodings_accepted_by_peer, call->incoming_stream_compression_algorithm)) { if (grpc_compression_trace.enabled()) { - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_stream_compression_algorithm_name( call->incoming_stream_compression_algorithm, &algo_name); gpr_log( @@ -1543,7 +1543,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (call->incoming_compression_algorithm != GRPC_COMPRESS_NONE) { const grpc_compression_algorithm algo = call->incoming_compression_algorithm; - char* error_msg = NULL; + char* error_msg = nullptr; const grpc_compression_options compression_options = grpc_channel_compression_options(call->channel); /* check if algorithm is known */ @@ -1556,7 +1556,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_compression_algorithm_name(algo, &algo_name); gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); @@ -1572,7 +1572,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, if (!GPR_BITGET(call->encodings_accepted_by_peer, call->incoming_compression_algorithm)) { if (grpc_compression_trace.enabled()) { - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_compression_algorithm_name(call->incoming_compression_algorithm, &algo_name); gpr_log(GPR_ERROR, @@ -1620,7 +1620,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, } } - grpc_closure* saved_rsr_closure = NULL; + grpc_closure* saved_rsr_closure = nullptr; while (true) { gpr_atm rsr_bctlp = gpr_atm_acq_load(&call->recv_state); /* Should only receive initial metadata once */ @@ -1644,7 +1644,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, break; } } - if (saved_rsr_closure != NULL) { + if (saved_rsr_closure != nullptr) { GRPC_CLOSURE_RUN(exec_ctx, saved_rsr_closure, GRPC_ERROR_REF(error)); } @@ -1695,7 +1695,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, } bctl = allocate_batch_control(call, ops, nops); - if (bctl == NULL) { + if (bctl == nullptr) { return GRPC_CALL_ERROR_TOO_MANY_OPERATIONS; } bctl->completion_data.notify_tag.tag = notify_tag; @@ -2080,7 +2080,7 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, "reserved=%p)", 5, (call, ops, (unsigned long)nops, tag, reserved)); - if (reserved != NULL) { + if (reserved != nullptr) { err = GRPC_CALL_ERROR; } else { err = call_start_batch(&exec_ctx, call, ops, nops, tag, 0); From d9d5c8f100b0f9b7bcbba2480d85053cf6ccbf88 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Mon, 13 Nov 2017 17:09:10 -0800 Subject: [PATCH 15/27] clang fmt --- src/core/ext/filters/client_channel/client_channel.cc | 6 ++++-- src/core/lib/security/transport/security_connector.cc | 5 +++-- src/core/lib/surface/call.cc | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 04b138305a1..8a3d09eb1d2 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -265,7 +265,8 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, w->lb_policy, grpc_connectivity_state_name(w->state)); } - if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != nullptr) { + if (publish_state == GRPC_CHANNEL_SHUTDOWN && + w->chand->resolver != nullptr) { publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_resolver_channel_saw_error_locked(exec_ctx, w->chand->resolver); GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); @@ -407,7 +408,8 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } } if (found_balancer_address) { - if (lb_policy_name != nullptr && strcmp(lb_policy_name, "grpclb") != 0) { + if (lb_policy_name != nullptr && + strcmp(lb_policy_name, "grpclb") != 0) { gpr_log(GPR_INFO, "resolver requested LB policy %s but provided at least one " "balancer address -- forcing use of grpclb LB policy", diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 93e6896f702..5c508fabea5 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -598,7 +598,7 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( c->client_handshaker_factory, c->overridden_target_name != nullptr ? c->overridden_target_name - : c->target_name, + : c->target_name, &tsi_hs); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.", @@ -909,7 +909,8 @@ static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, /* If the target name was overridden, then the original target_name was 'checked' transitively during the previous peer check at the end of the handshake. */ - if (c->overridden_target_name != nullptr && strcmp(host, c->target_name) == 0) { + if (c->overridden_target_name != nullptr && + strcmp(host, c->target_name) == 0) { status = GRPC_SECURITY_OK; } if (status != GRPC_SECURITY_OK) { diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 4e3290ac4dd..52aaf723b3c 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -599,7 +599,8 @@ void grpc_call_unref(grpc_call* c) { // effect of scheduling the previously set cancellation closure, if // any, so that it can release any internal references it may be // holding to the call stack. - grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, nullptr); + grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, + nullptr); } GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); grpc_exec_ctx_finish(&exec_ctx); From 19c34b60bee64788063ee1bbfca5f7374ccf5b77 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Tue, 14 Nov 2017 14:29:22 -0800 Subject: [PATCH 16/27] Reviewer comments --- include/grpc/grpc.h | 2 +- src/core/lib/iomgr/timer_generic.cc | 97 +++++++++++++++------------ src/core/lib/iomgr/timer_uv.cc | 2 - src/core/lib/surface/alarm_internal.h | 4 +- src/core/lib/surface/api_trace.h | 4 +- 5 files changed, 60 insertions(+), 49 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 72e971dca3b..f083bc591e6 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -428,7 +428,7 @@ GRPCAPI void grpc_server_destroy(grpc_server* server); /** Enable or disable a tracer. - TraceFlags (usually controlled by the environment variable GRPC_TRACE) + Tracers (usually controlled by the environment variable GRPC_TRACE) allow printf-style debugging on GRPC internals, and are useful for tracking down problems in the field. diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index d5c4875eab4..a4bfbcb342c 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -25,6 +25,7 @@ #include "src/core/lib/iomgr/timer.h" #include +#include #include #include #include @@ -37,14 +38,15 @@ #define INVALID_HEAP_INDEX 0xffffffffu -#define LOG2_NUM_SHARDS 5 -#define NUM_SHARDS (1 << LOG2_NUM_SHARDS) #define ADD_DEADLINE_SCALE 0.33 #define MIN_QUEUE_WINDOW_DURATION 0.01 #define MAX_QUEUE_WINDOW_DURATION 1 -grpc_core::TraceFlag grpc_timer_trace(false, "timer"); -grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); +extern "C" { +grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); +grpc_tracer_flag grpc_timer_check_trace = + GRPC_TRACER_INITIALIZER(false, "timer_check"); +} /* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with * deadlines earlier than 'queue_deadline" cap are maintained in the heap and @@ -71,14 +73,16 @@ typedef struct { grpc_timer list; } timer_shard; +static size_t g_num_shards; + /* Array of timer shards. Whenever a timer (grpc_timer *) is added, its address * is hashed to select the timer shard to add the timer to */ -static timer_shard g_shards[NUM_SHARDS]; +static timer_shard* g_shards; /* Maintains a sorted list of timer shards (sorted by their min_deadline, i.e * the deadline of the next timer in each shard). * Access to this is protected by g_shared_mutables.mu */ -static timer_shard* g_shard_queue[NUM_SHARDS]; +static timer_shard** g_shard_queue; #ifndef NDEBUG @@ -87,7 +91,7 @@ static timer_shard* g_shard_queue[NUM_SHARDS]; #define NUM_HASH_BUCKETS 1009 /* Prime number close to 1000 */ static gpr_mu g_hash_mu[NUM_HASH_BUCKETS]; /* One mutex per bucket */ -static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {NULL}; +static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {nullptr}; static void init_timer_ht() { for (int i = 0; i < NUM_HASH_BUCKETS; i++) { @@ -100,7 +104,7 @@ static bool is_in_ht(grpc_timer* t) { gpr_mu_lock(&g_hash_mu[i]); grpc_timer* p = g_timer_ht[i]; - while (p != NULL && p != t) { + while (p != nullptr && p != t) { p = p->hash_table_next; } gpr_mu_unlock(&g_hash_mu[i]); @@ -114,7 +118,7 @@ static void add_to_ht(grpc_timer* t) { gpr_mu_lock(&g_hash_mu[i]); grpc_timer* p = g_timer_ht[i]; - while (p != NULL && p != t) { + while (p != nullptr && p != t) { p = p->hash_table_next; } @@ -142,9 +146,9 @@ static void remove_from_ht(grpc_timer* t) { if (g_timer_ht[i] == t) { g_timer_ht[i] = g_timer_ht[i]->hash_table_next; removed = true; - } else if (g_timer_ht[i] != NULL) { + } else if (g_timer_ht[i] != nullptr) { grpc_timer* p = g_timer_ht[i]; - while (p->hash_table_next != NULL && p->hash_table_next != t) { + while (p->hash_table_next != nullptr && p->hash_table_next != t) { p = p->hash_table_next; } @@ -165,7 +169,7 @@ static void remove_from_ht(grpc_timer* t) { abort(); } - t->hash_table_next = NULL; + t->hash_table_next = nullptr; } /* If a timer is added to a timer shard (either heap or a list), it cannot @@ -238,14 +242,21 @@ static gpr_atm compute_min_deadline(timer_shard* shard) { void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { uint32_t i; + g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); + g_shards = (timer_shard*)gpr_zalloc(g_num_shards * sizeof(*g_shards)); + g_shard_queue = + (timer_shard**)gpr_zalloc(g_num_shards * sizeof(*g_shard_queue)); + g_shared_mutables.initialized = true; g_shared_mutables.checker_mu = GPR_SPINLOCK_INITIALIZER; gpr_mu_init(&g_shared_mutables.mu); g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); gpr_tls_init(&g_last_seen_min_timer); 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 < g_num_shards; i++) { timer_shard* shard = &g_shards[i]; gpr_mu_init(&shard->mu); grpc_time_averaged_stats_init(&shard->stats, 1.0 / ADD_DEADLINE_SCALE, 0.1, @@ -262,17 +273,19 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { } void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) { - int i; + size_t i; run_some_expired_timers( - exec_ctx, GPR_ATM_MAX, NULL, + exec_ctx, GPR_ATM_MAX, nullptr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown")); - for (i = 0; i < NUM_SHARDS; i++) { + for (i = 0; i < g_num_shards; i++) { timer_shard* shard = &g_shards[i]; gpr_mu_destroy(&shard->mu); grpc_timer_heap_destroy(&shard->heap); } gpr_mu_destroy(&g_shared_mutables.mu); gpr_tls_destroy(&g_last_seen_min_timer); + gpr_free(g_shards); + gpr_free(g_shard_queue); g_shared_mutables.initialized = false; } @@ -306,7 +319,7 @@ static void note_deadline_change(timer_shard* shard) { g_shard_queue[shard->shard_queue_index - 1]->min_deadline) { swap_adjacent_shards_in_queue(shard->shard_queue_index - 1); } - while (shard->shard_queue_index < NUM_SHARDS - 1 && + while (shard->shard_queue_index < g_num_shards - 1 && shard->min_deadline > g_shard_queue[shard->shard_queue_index + 1]->min_deadline) { swap_adjacent_shards_in_queue(shard->shard_queue_index); @@ -318,15 +331,15 @@ void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; } void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, grpc_millis deadline, grpc_closure* closure) { int is_first_timer = 0; - timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, NUM_SHARDS)]; + timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer->closure = closure; timer->deadline = deadline; #ifndef NDEBUG - timer->hash_table_next = NULL; + timer->hash_table_next = nullptr; #endif - if (grpc_timer_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); @@ -362,7 +375,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, timer->heap_index = INVALID_HEAP_INDEX; list_join(&shard->list, timer); } - if (grpc_timer_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, " .. add to shard %d with queue_deadline_cap=%" PRIdPTR " => is_first_timer=%s", @@ -384,7 +397,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, grpc_timer_check. */ if (is_first_timer) { gpr_mu_lock(&g_shared_mutables.mu); - if (grpc_timer_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, " .. old shard min_deadline=%" PRIdPTR, shard->min_deadline); } @@ -412,9 +425,9 @@ void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { return; } - timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, NUM_SHARDS)]; + timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; gpr_mu_lock(&shard->mu); - if (grpc_timer_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: CANCEL pending=%s", timer, timer->pending ? "true" : "false"); } @@ -455,7 +468,7 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { saturating_add(GPR_MAX(now, shard->queue_deadline_cap), (gpr_atm)(deadline_delta * 1000.0)); - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. shard[%d]->queue_deadline_cap --> %" PRIdPTR, (int)(shard - g_shards), shard->queue_deadline_cap); } @@ -463,7 +476,7 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { next = timer->next; if (timer->deadline < shard->queue_deadline_cap) { - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. add timer with deadline %" PRIdPTR " to heap", timer->deadline); } @@ -480,23 +493,23 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { grpc_timer* timer; for (;;) { - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s", (int)(shard - g_shards), grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); } if (grpc_timer_heap_is_empty(&shard->heap)) { - if (now < shard->queue_deadline_cap) return NULL; - if (!refill_heap(shard, now)) return NULL; + if (now < shard->queue_deadline_cap) return nullptr; + if (!refill_heap(shard, now)) return nullptr; } timer = grpc_timer_heap_top(&shard->heap); - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR, timer->deadline, now); } - if (timer->deadline > now) return NULL; - if (grpc_timer_trace.enabled()) { + if (timer->deadline > now) return nullptr; + if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: FIRE %" PRIdPTR "ms late via %s scheduler", timer, now - timer->deadline, timer->closure->scheduler->vtable->name); @@ -521,7 +534,7 @@ static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard, } *new_min_deadline = compute_min_deadline(shard); gpr_mu_unlock(&shard->mu); - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. shard[%d] popped %" PRIdPTR, (int)(shard - g_shards), n); } @@ -537,7 +550,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, gpr_atm min_timer = gpr_atm_no_barrier_load(&g_shared_mutables.min_timer); gpr_tls_set(&g_last_seen_min_timer, min_timer); if (now < min_timer) { - if (next != NULL) *next = GPR_MIN(*next, min_timer); + if (next != nullptr) *next = GPR_MIN(*next, min_timer); return GRPC_TIMERS_CHECKED_AND_EMPTY; } @@ -545,7 +558,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, gpr_mu_lock(&g_shared_mutables.mu); result = GRPC_TIMERS_CHECKED_AND_EMPTY; - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. shard[%d]->min_deadline = %" PRIdPTR, (int)(g_shard_queue[0] - g_shards), g_shard_queue[0]->min_deadline); @@ -563,7 +576,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, result = GRPC_TIMERS_FIRED; } - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, " .. result --> %d" ", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR @@ -605,10 +618,10 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, mutable cacheline in the common case */ grpc_millis min_timer = gpr_tls_get(&g_last_seen_min_timer); if (now < min_timer) { - if (next != NULL) { + if (next != nullptr) { *next = GPR_MIN(*next, min_timer); } - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { gpr_log(GPR_DEBUG, "TIMER CHECK SKIP: now=%" PRIdPTR " min_timer=%" PRIdPTR, now, min_timer); @@ -622,9 +635,9 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, : GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system"); // tracing - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { char* next_str; - if (next == NULL) { + if (next == nullptr) { next_str = gpr_strdup("NULL"); } else { gpr_asprintf(&next_str, "%" PRIdPTR, *next); @@ -640,9 +653,9 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, grpc_timer_check_result r = run_some_expired_timers(exec_ctx, now, next, shutdown_error); // tracing - if (grpc_timer_check_trace.enabled()) { + if (GRPC_TRACER_ON(grpc_timer_check_trace)) { char* next_str; - if (next == NULL) { + if (next == nullptr) { next_str = gpr_strdup("NULL"); } else { gpr_asprintf(&next_str, "%" PRIdPTR, *next); diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index b55a09d8933..fac2026fa93 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -29,10 +29,8 @@ #include -extern "C" { grpc_core::TraceFlag grpc_timer_trace(false, "timer"); grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); -} static void timer_close_callback(uv_handle_t* handle) { gpr_free(handle); } diff --git a/src/core/lib/surface/alarm_internal.h b/src/core/lib/surface/alarm_internal.h index 47fd1acaf09..2ee3a311f79 100644 --- a/src/core/lib/surface/alarm_internal.h +++ b/src/core/lib/surface/alarm_internal.h @@ -22,12 +22,12 @@ #include #include "src/core/lib/debug/trace.h" +extern grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount; + #ifdef __cplusplus extern "C" { #endif -extern grpc_core::DebugOnlyTraceFlag grpc_trace_alarm_refcount; - #ifndef NDEBUG #define GRPC_ALARM_REF(a, reason) alarm_ref_dbg(a, reason, __FILE__, __LINE__) diff --git a/src/core/lib/surface/api_trace.h b/src/core/lib/surface/api_trace.h index 9838bccacf0..b475dceface 100644 --- a/src/core/lib/surface/api_trace.h +++ b/src/core/lib/surface/api_trace.h @@ -22,12 +22,12 @@ #include #include "src/core/lib/debug/trace.h" +extern grpc_core::TraceFlag grpc_api_trace; + #ifdef __cplusplus extern "C" { #endif -extern grpc_core::TraceFlag grpc_api_trace; - /* Provide unwrapping macros because we're in C89 and variadic macros weren't introduced until C99... */ #define GRPC_API_TRACE_UNWRAP0() From 4fde068b04825444e9239b8a24d642549e606f2d Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 14 Nov 2017 14:36:54 -0800 Subject: [PATCH 17/27] Fix merge of timer_generic --- src/core/lib/iomgr/timer_generic.cc | 39 +++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index a4bfbcb342c..fa95c43dbe3 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -42,11 +42,8 @@ #define MIN_QUEUE_WINDOW_DURATION 0.01 #define MAX_QUEUE_WINDOW_DURATION 1 -extern "C" { -grpc_tracer_flag grpc_timer_trace = GRPC_TRACER_INITIALIZER(false, "timer"); -grpc_tracer_flag grpc_timer_check_trace = - GRPC_TRACER_INITIALIZER(false, "timer_check"); -} +grpc_core::TraceFlag grpc_timer_trace(false, "timer"); +grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); /* A "timer shard". Contains a 'heap' and a 'list' of timers. All timers with * deadlines earlier than 'queue_deadline" cap are maintained in the heap and @@ -253,8 +250,6 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { g_shared_mutables.min_timer = grpc_exec_ctx_now(exec_ctx); gpr_tls_init(&g_last_seen_min_timer); 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 < g_num_shards; i++) { timer_shard* shard = &g_shards[i]; @@ -339,7 +334,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, timer->hash_table_next = nullptr; #endif - if (GRPC_TRACER_ON(grpc_timer_trace)) { + if (grpc_timer_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER %p: SET %" PRIdPTR " now %" PRIdPTR " call %p[%p]", timer, deadline, grpc_exec_ctx_now(exec_ctx), closure, closure->cb); @@ -375,7 +370,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, timer->heap_index = INVALID_HEAP_INDEX; 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 " => is_first_timer=%s", @@ -397,7 +392,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, grpc_timer_check. */ if (is_first_timer) { 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, shard->min_deadline); } @@ -427,7 +422,7 @@ void grpc_timer_cancel(grpc_exec_ctx* exec_ctx, grpc_timer* timer) { timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; 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, timer->pending ? "true" : "false"); } @@ -468,7 +463,7 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { saturating_add(GPR_MAX(now, shard->queue_deadline_cap), (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, (int)(shard - g_shards), shard->queue_deadline_cap); } @@ -476,7 +471,7 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { next = timer->next; 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", timer->deadline); } @@ -493,7 +488,7 @@ static int refill_heap(timer_shard* shard, gpr_atm now) { static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { grpc_timer* timer; for (;;) { - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. shard[%d]: heap_empty=%s", (int)(shard - g_shards), grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); @@ -503,13 +498,13 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { if (!refill_heap(shard, now)) return nullptr; } 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, " .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR, timer->deadline, now); } if (timer->deadline > now) return nullptr; - 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", timer, now - timer->deadline, timer->closure->scheduler->vtable->name); @@ -534,7 +529,7 @@ static size_t pop_timers(grpc_exec_ctx* exec_ctx, timer_shard* shard, } *new_min_deadline = compute_min_deadline(shard); 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, (int)(shard - g_shards), n); } @@ -558,7 +553,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, gpr_mu_lock(&g_shared_mutables.mu); 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, (int)(g_shard_queue[0] - g_shards), g_shard_queue[0]->min_deadline); @@ -576,7 +571,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, result = GRPC_TIMERS_FIRED; } - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, " .. result --> %d" ", shard[%d]->min_deadline %" PRIdPTR " --> %" PRIdPTR @@ -621,7 +616,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, if (next != nullptr) { *next = GPR_MIN(*next, min_timer); } - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { gpr_log(GPR_DEBUG, "TIMER CHECK SKIP: now=%" PRIdPTR " min_timer=%" PRIdPTR, now, min_timer); @@ -635,7 +630,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, : GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutting down timer system"); // tracing - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { char* next_str; if (next == nullptr) { next_str = gpr_strdup("NULL"); @@ -653,7 +648,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, grpc_timer_check_result r = run_some_expired_timers(exec_ctx, now, next, shutdown_error); // tracing - if (GRPC_TRACER_ON(grpc_timer_check_trace)) { + if (grpc_timer_check_trace.enabled()) { char* next_str; if (next == nullptr) { next_str = gpr_strdup("NULL"); From 882dfeddd5e4503493a3a88733ed9a0fc4af436e Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Tue, 14 Nov 2017 14:58:20 -0800 Subject: [PATCH 18/27] clang tidy --- .../filters/client_channel/client_channel.cc | 2 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 216 +++++++++--------- .../lb_policy/pick_first/pick_first.cc | 70 +++--- .../lb_policy/round_robin/round_robin.cc | 58 ++--- .../lb_policy/subchannel_list.cc | 22 +- .../ext/transport/chttp2/transport/parsing.cc | 34 +-- .../ext/transport/inproc/inproc_transport.cc | 122 +++++----- src/core/lib/iomgr/ev_epollex_linux.cc | 98 ++++---- src/core/lib/iomgr/resource_quota.cc | 56 ++--- src/core/lib/iomgr/tcp_posix.cc | 38 +-- .../lib/security/context/security_context.cc | 50 ++-- .../security/transport/security_connector.cc | 22 +- src/core/lib/surface/call.cc | 16 +- src/core/lib/transport/connectivity_state.cc | 18 +- 14 files changed, 411 insertions(+), 411 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 8a3d09eb1d2..03c1b6f4bd5 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -1492,7 +1492,7 @@ static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, "picked"); } for (size_t i = 0; i < GRPC_CONTEXT_COUNT; ++i) { - if (calld->subchannel_call_context[i].value != NULL) { + if (calld->subchannel_call_context[i].value != nullptr) { calld->subchannel_call_context[i].destroy( calld->subchannel_call_context[i].value); } 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 e64ba536044..005df3c6d1f 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 @@ -133,7 +133,7 @@ grpc_core::TraceFlag grpc_lb_glb_trace(false, "glb"); static grpc_error* initial_metadata_add_lb_token( grpc_exec_ctx* exec_ctx, grpc_metadata_batch* initial_metadata, grpc_linked_mdelem* lb_token_mdelem_storage, grpc_mdelem lb_token) { - GPR_ASSERT(lb_token_mdelem_storage != NULL); + GPR_ASSERT(lb_token_mdelem_storage != nullptr); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, lb_token_mdelem_storage, lb_token); @@ -190,14 +190,14 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { wrapped_rr_closure_arg* wc_arg = (wrapped_rr_closure_arg*)arg; - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); - if (wc_arg->rr_policy != NULL) { + if (wc_arg->rr_policy != nullptr) { /* if *target is NULL, no pick has been made by the RR policy (eg, all * addresses failed to connect). There won't be any user_data/token * available */ - if (*wc_arg->target != NULL) { + if (*wc_arg->target != nullptr) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, @@ -211,7 +211,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, abort(); } // Pass on client stats via context. Passes ownership of the reference. - GPR_ASSERT(wc_arg->client_stats != NULL); + GPR_ASSERT(wc_arg->client_stats != nullptr); wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].value = wc_arg->client_stats; wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; } else { @@ -223,7 +223,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, } GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); } - GPR_ASSERT(wc_arg->free_when_done != NULL); + GPR_ASSERT(wc_arg->free_when_done != nullptr); gpr_free(wc_arg->free_when_done); } @@ -455,12 +455,12 @@ static bool is_server_valid(const grpc_grpclb_server* server, size_t idx, /* vtable for LB tokens in grpc_lb_addresses. */ static void* lb_token_copy(void* token) { - return token == NULL - ? NULL + return token == nullptr + ? nullptr : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; } static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) { - if (token != NULL) { + if (token != nullptr) { GRPC_MDELEM_UNREF(exec_ctx, grpc_mdelem{(uintptr_t)token}); } } @@ -543,7 +543,7 @@ static grpc_lb_addresses* process_serverlist_locked( grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len, false /* is_balancer */, - NULL /* balancer_name */, user_data); + nullptr /* balancer_name */, user_data); ++addr_idx; } GPR_ASSERT(addr_idx == num_valid); @@ -569,7 +569,7 @@ static grpc_lb_addresses* extract_backend_addresses_locked( const grpc_resolved_address* addr = &addresses->addresses[i].address; grpc_lb_addresses_set_address(backend_addresses, num_copied, &addr->addr, addr->len, false /* is_balancer */, - NULL /* balancer_name */, + nullptr /* balancer_name */, (void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload); ++num_copied; } @@ -645,7 +645,7 @@ static bool pick_from_internal_rr_locked( const grpc_lb_policy_pick_args* pick_args, bool force_async, grpc_connected_subchannel** target, wrapped_rr_closure_arg* wc_arg) { // Check for drops if we are not using fallback backend addresses. - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { // Look at the index into the serverlist to see if we should drop this call. grpc_grpclb_server* server = glb_policy->serverlist->servers[glb_policy->serverlist_index++]; @@ -664,12 +664,12 @@ static bool pick_from_internal_rr_locked( // the client_load_reporting filter, because we do not create a // subchannel call (and therefore no client_load_reporting filter) // for dropped calls. - GPR_ASSERT(wc_arg->client_stats != NULL); + GPR_ASSERT(wc_arg->client_stats != nullptr); grpc_grpclb_client_stats_add_call_dropped_locked( server->load_balance_token, wc_arg->client_stats); grpc_grpclb_client_stats_unref(wc_arg->client_stats); if (force_async) { - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; @@ -694,11 +694,11 @@ static bool pick_from_internal_rr_locked( pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); // Pass on client stats via context. Passes ownership of the reference. - GPR_ASSERT(wc_arg->client_stats != NULL); + GPR_ASSERT(wc_arg->client_stats != nullptr); wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].value = wc_arg->client_stats; wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; if (force_async) { - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; @@ -715,7 +715,7 @@ static bool pick_from_internal_rr_locked( static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { grpc_lb_addresses* addresses; - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { GPR_ASSERT(glb_policy->serverlist->num_servers > 0); addresses = process_serverlist_locked(exec_ctx, glb_policy->serverlist); } else { @@ -723,10 +723,10 @@ static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, // serverlist from the balancer, we use the fallback backends returned by // the resolver. Note that the fallback backend list may be empty, in which // case the new round_robin policy will keep the requested picks pending. - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); addresses = grpc_lb_addresses_copy(glb_policy->fallback_backend_addresses); } - GPR_ASSERT(addresses != NULL); + GPR_ASSERT(addresses != nullptr); grpc_lb_policy_args* args = (grpc_lb_policy_args*)gpr_zalloc(sizeof(*args)); args->client_channel_factory = glb_policy->cc_factory; args->combiner = glb_policy->base.combiner; @@ -751,11 +751,11 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, grpc_lb_policy_args* args) { - GPR_ASSERT(glb_policy->rr_policy == NULL); + GPR_ASSERT(glb_policy->rr_policy == nullptr); grpc_lb_policy* new_rr_policy = grpc_lb_policy_create(exec_ctx, "round_robin", args); - if (new_rr_policy == NULL) { + if (new_rr_policy == nullptr) { gpr_log(GPR_ERROR, "[grpclb %p] Failure creating a RoundRobin policy for serverlist " "update with %" PRIuPTR @@ -767,7 +767,7 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, return; } glb_policy->rr_policy = new_rr_policy; - grpc_error* rr_state_error = NULL; + grpc_error* rr_state_error = nullptr; const grpc_connectivity_state rr_state = grpc_lb_policy_check_connectivity_locked(exec_ctx, glb_policy->rr_policy, &rr_state_error); @@ -835,8 +835,8 @@ static void rr_handover_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { if (glb_policy->shutting_down) return; grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); - GPR_ASSERT(args != NULL); - if (glb_policy->rr_policy != NULL) { + GPR_ASSERT(args != nullptr); + if (glb_policy->rr_policy != nullptr) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_DEBUG, "[grpclb %p] Updating RR policy %p", glb_policy, glb_policy->rr_policy); @@ -868,7 +868,7 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, * sink, policies can't transition back from it. .*/ GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "rr_connectivity_shutdown"); - glb_policy->rr_policy = NULL; + glb_policy->rr_policy = nullptr; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); @@ -923,7 +923,7 @@ static grpc_channel_args* build_lb_channel_args( * instantiated and used in that case. Otherwise, something has gone wrong. */ GPR_ASSERT(num_grpclb_addrs > 0); grpc_lb_addresses* lb_addresses = - grpc_lb_addresses_create(num_grpclb_addrs, NULL); + grpc_lb_addresses_create(num_grpclb_addrs, nullptr); grpc_slice_hash_table_entry* targets_info_entries = (grpc_slice_hash_table_entry*)gpr_zalloc(sizeof(*targets_info_entries) * num_grpclb_addrs); @@ -931,7 +931,7 @@ static grpc_channel_args* build_lb_channel_args( size_t lb_addresses_idx = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (!addresses->addresses[i].is_balancer) continue; - if (addresses->addresses[i].user_data != NULL) { + if (addresses->addresses[i].user_data != nullptr) { gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } @@ -945,7 +945,7 @@ static grpc_channel_args* build_lb_channel_args( grpc_lb_addresses_set_address( lb_addresses, lb_addresses_idx++, addresses->addresses[i].address.addr, addresses->addresses[i].address.len, false /* is balancer */, - addresses->addresses[i].balancer_name, NULL /* user data */); + addresses->addresses[i].balancer_name, nullptr /* user data */); } GPR_ASSERT(num_grpclb_addrs == lb_addresses_idx); grpc_slice_hash_table* targets_info = @@ -970,18 +970,18 @@ static grpc_channel_args* build_lb_channel_args( static void glb_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; - GPR_ASSERT(glb_policy->pending_picks == NULL); - GPR_ASSERT(glb_policy->pending_pings == NULL); + GPR_ASSERT(glb_policy->pending_picks == nullptr); + GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); - if (glb_policy->client_stats != NULL) { + if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } - if (glb_policy->fallback_backend_addresses != NULL) { + if (glb_policy->fallback_backend_addresses != nullptr) { grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); } grpc_fake_resolver_response_generator_unref(glb_policy->response_generator); @@ -1002,8 +1002,8 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { * because glb_policy->lb_call is only assigned in lb_call_init_locked as part * of query_for_backends_locked, which can only be invoked while * glb_policy->shutting_down is false. */ - if (lb_call != NULL) { - grpc_call_cancel(lb_call, NULL); + if (lb_call != nullptr) { + grpc_call_cancel(lb_call, nullptr); /* lb_on_server_status_received will pick up the cancel and clean up */ } if (glb_policy->retry_timer_active) { @@ -1016,27 +1016,27 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { } pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; + glb_policy->pending_picks = nullptr; pending_ping* pping = glb_policy->pending_pings; - glb_policy->pending_pings = NULL; - if (glb_policy->rr_policy != NULL) { + glb_policy->pending_pings = nullptr; + if (glb_policy->rr_policy != nullptr) { GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "glb_shutdown"); } // We destroy the LB channel here because // glb_lb_channel_on_connectivity_changed_cb needs a valid glb_policy // instance. Destroying the lb channel in glb_destroy would likely result in // a callback invocation without a valid glb_policy arg. - if (glb_policy->lb_channel != NULL) { + if (glb_policy->lb_channel != nullptr) { grpc_channel_destroy(glb_policy->lb_channel); - glb_policy->lb_channel = NULL; + glb_policy->lb_channel = nullptr; } grpc_connectivity_state_set( exec_ctx, &glb_policy->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown"), "glb_shutdown"); - while (pp != NULL) { + while (pp != nullptr) { pending_pick* next = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown")); @@ -1044,7 +1044,7 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pp = next; } - while (pping != NULL) { + while (pping != nullptr) { pending_ping* next = pping->next; GRPC_CLOSURE_SCHED( exec_ctx, &pping->wrapped_notify_arg.wrapper_closure, @@ -1069,11 +1069,11 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; - while (pp != NULL) { + glb_policy->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); @@ -1083,7 +1083,7 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } pp = next; } - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_pick_locked(exec_ctx, glb_policy->rr_policy, target, GRPC_ERROR_REF(error)); } @@ -1107,8 +1107,8 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; - while (pp != NULL) { + glb_policy->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->pick_args.initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { @@ -1121,7 +1121,7 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, } pp = next; } - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_picks_locked( exec_ctx, glb_policy->rr_policy, initial_metadata_flags_mask, initial_metadata_flags_eq, GRPC_ERROR_REF(error)); @@ -1137,7 +1137,7 @@ static void start_picking_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { /* start a timer to fall back */ if (glb_policy->lb_fallback_timeout_ms > 0 && - glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { + glb_policy->serverlist == nullptr && !glb_policy->fallback_timer_active) { grpc_millis deadline = grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); @@ -1166,8 +1166,8 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { - if (pick_args->lb_token_mdelem_storage == NULL) { - *target = NULL; + if (pick_args->lb_token_mdelem_storage == nullptr) { + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, on_complete, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No mdelem storage for the LB token. Load reporting " @@ -1176,10 +1176,10 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } glb_lb_policy* glb_policy = (glb_lb_policy*)pol; bool pick_done = false; - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { const grpc_connectivity_state rr_connectivity_state = grpc_lb_policy_check_connectivity_locked(exec_ctx, - glb_policy->rr_policy, NULL); + glb_policy->rr_policy, nullptr); // The glb_policy->rr_policy may have transitioned to SHUTDOWN but the // callback registered to capture this event // (glb_rr_connectivity_changed_locked) may not have been invoked yet. We @@ -1208,7 +1208,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, wc_arg->rr_policy = glb_policy->rr_policy; wc_arg->target = target; wc_arg->context = context; - GPR_ASSERT(glb_policy->client_stats != NULL); + GPR_ASSERT(glb_policy->client_stats != nullptr); wc_arg->client_stats = grpc_grpclb_client_stats_ref(glb_policy->client_stats); wc_arg->wrapped_closure = on_complete; @@ -1270,7 +1270,7 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; glb_policy->retry_timer_active = false; - if (!glb_policy->shutting_down && glb_policy->lb_call == NULL && + if (!glb_policy->shutting_down && glb_policy->lb_call == nullptr && error == GRPC_ERROR_NONE) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Restarting call to LB server", glb_policy); @@ -1337,8 +1337,8 @@ static void client_load_report_done_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); - glb_policy->client_load_report_payload = NULL; - if (error != GRPC_ERROR_NONE || glb_policy->lb_call == NULL) { + glb_policy->client_load_report_payload = nullptr; + if (error != GRPC_ERROR_NONE || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "client_load_report"); @@ -1356,23 +1356,23 @@ static bool load_report_counters_are_zero(grpc_grpclb_request* request) { request->client_stats.num_calls_finished_with_client_failed_to_send == 0 && request->client_stats.num_calls_finished_known_received == 0 && - (drop_entries == NULL || drop_entries->num_entries == 0); + (drop_entries == nullptr || drop_entries->num_entries == 0); } static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == NULL) { + if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "client_load_report"); - if (glb_policy->lb_call == NULL) { + if (glb_policy->lb_call == nullptr) { maybe_restart_lb_call(exec_ctx, glb_policy); } return; } // Construct message payload. - GPR_ASSERT(glb_policy->client_load_report_payload == NULL); + GPR_ASSERT(glb_policy->client_load_report_payload == nullptr); grpc_grpclb_request* request = grpc_grpclb_load_report_request_create_locked(glb_policy->client_stats); // Skip client load report if the counters were all zero in the last @@ -1415,9 +1415,9 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->server_name != NULL); + GPR_ASSERT(glb_policy->server_name != nullptr); GPR_ASSERT(glb_policy->server_name[0] != '\0'); - GPR_ASSERT(glb_policy->lb_call == NULL); + GPR_ASSERT(glb_policy->lb_call == nullptr); GPR_ASSERT(!glb_policy->shutting_down); /* Note the following LB call progresses every time there's activity in \a @@ -1429,13 +1429,13 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, ? GRPC_MILLIS_INF_FUTURE : grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( - exec_ctx, glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, + exec_ctx, glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, - &host, deadline, NULL); + &host, deadline, nullptr); grpc_slice_unref_internal(exec_ctx, host); - if (glb_policy->client_stats != NULL) { + if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } glb_policy->client_stats = grpc_grpclb_client_stats_create(); @@ -1471,9 +1471,9 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->lb_call != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_unref(glb_policy->lb_call); - glb_policy->lb_call = NULL; + glb_policy->lb_call = nullptr; grpc_metadata_array_destroy(&glb_policy->lb_initial_metadata_recv); grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); @@ -1491,7 +1491,7 @@ static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, */ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->lb_channel != NULL); + GPR_ASSERT(glb_policy->lb_channel != nullptr); if (glb_policy->shutting_down) return; lb_call_init_locked(exec_ctx, glb_policy); @@ -1501,7 +1501,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, "[grpclb %p] Query for backends (lb_channel: %p, lb_call: %p)", glb_policy, glb_policy->lb_channel, glb_policy->lb_call); } - GPR_ASSERT(glb_policy->lb_call != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_error call_error; grpc_op ops[3]; @@ -1511,22 +1511,22 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = &glb_policy->lb_initial_metadata_recv; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; - GPR_ASSERT(glb_policy->lb_request_payload != NULL); + GPR_ASSERT(glb_policy->lb_request_payload != nullptr); op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = glb_policy->lb_request_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; call_error = grpc_call_start_batch_and_execute(exec_ctx, glb_policy->lb_call, - ops, (size_t)(op - ops), NULL); + ops, (size_t)(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); op = ops; @@ -1537,7 +1537,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->data.recv_status_on_client.status_details = &glb_policy->lb_call_status_details; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* take a weak ref (won't prevent calling of \a glb_shutdown if the strong ref * count goes to zero) to be unref'd in lb_on_server_status_received_locked */ @@ -1552,7 +1552,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &glb_policy->lb_response_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* take another weak ref to be unref'd/reused in * lb_on_response_received_locked */ @@ -1569,7 +1569,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_op ops[2]; memset(ops, 0, sizeof(ops)); grpc_op* op = ops; - if (glb_policy->lb_response_payload != NULL) { + if (glb_policy->lb_response_payload != nullptr) { grpc_backoff_reset(&glb_policy->lb_call_backoff_state); /* Received data from the LB server. Look inside * glb_policy->lb_response_payload, for a serverlist. */ @@ -1579,10 +1579,10 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_byte_buffer_reader_destroy(&bbr); grpc_byte_buffer_destroy(glb_policy->lb_response_payload); - grpc_grpclb_initial_response* response = NULL; + grpc_grpclb_initial_response* response = nullptr; if (!glb_policy->seen_initial_response && (response = grpc_grpclb_initial_response_parse(response_slice)) != - NULL) { + nullptr) { if (response->has_client_stats_report_interval) { glb_policy->client_stats_report_interval = GPR_MAX( GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( @@ -1610,8 +1610,8 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_grpclb_serverlist* serverlist = grpc_grpclb_response_parse_serverlist(response_slice); - if (serverlist != NULL) { - GPR_ASSERT(glb_policy->lb_call != NULL); + if (serverlist != nullptr) { + GPR_ASSERT(glb_policy->lb_call != nullptr); if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Serverlist with %" PRIuPTR " servers received", @@ -1638,14 +1638,14 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, } grpc_grpclb_destroy_serverlist(serverlist); } else { /* new serverlist */ - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { /* dispose of the old serverlist */ grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } else { /* or dispose of the fallback */ grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); - glb_policy->fallback_backend_addresses = NULL; + glb_policy->fallback_backend_addresses = nullptr; if (glb_policy->fallback_timer_active) { grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; @@ -1679,7 +1679,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &glb_policy->lb_response_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* reuse the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() */ @@ -1705,14 +1705,14 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy->fallback_timer_active = false; /* If we receive a serverlist after the timer fires but before this callback * actually runs, don't fall back. */ - if (glb_policy->serverlist == NULL) { + if (glb_policy->serverlist == nullptr) { if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) { if (grpc_lb_glb_trace.enabled()) { gpr_log(GPR_INFO, "[grpclb %p] Falling back to use backends from resolver", glb_policy); } - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); rr_handover_locked(exec_ctx, glb_policy); } } @@ -1723,7 +1723,7 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, 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 != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); if (grpc_lb_glb_trace.enabled()) { char* status_details = grpc_slice_to_c_string(glb_policy->lb_call_status_details); @@ -1747,7 +1747,7 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, static void fallback_update_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, const grpc_lb_addresses* addresses) { - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = extract_backend_addresses_locked(exec_ctx, addresses); @@ -1762,8 +1762,8 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, glb_lb_policy* glb_policy = (glb_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - if (glb_policy->lb_channel == NULL) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + if (glb_policy->lb_channel == nullptr) { // If we don't have a current channel to the LB, go into TRANSIENT // FAILURE. grpc_connectivity_state_set( @@ -1783,10 +1783,10 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, (const grpc_lb_addresses*)arg->value.pointer.p; // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. - if (glb_policy->serverlist == NULL) { + if (glb_policy->serverlist == nullptr) { fallback_update_locked(exec_ctx, glb_policy, addresses); } - GPR_ASSERT(glb_policy->lb_channel != NULL); + GPR_ASSERT(glb_policy->lb_channel != nullptr); // Propagate updates to the LB channel (pick_first) through the fake // resolver. grpc_channel_args* lb_channel_args = build_lb_channel_args( @@ -1809,7 +1809,7 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, - &glb_policy->lb_channel_on_connectivity_changed, NULL); + &glb_policy->lb_channel_on_connectivity_changed, nullptr); } } @@ -1837,7 +1837,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, - &glb_policy->lb_channel_on_connectivity_changed, NULL); + &glb_policy->lb_channel_on_connectivity_changed, nullptr); break; } case GRPC_CHANNEL_IDLE: @@ -1845,9 +1845,9 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, // call to kick the lb channel into gear. /* fallthrough */ case GRPC_CHANNEL_READY: - if (glb_policy->lb_call != NULL) { + if (glb_policy->lb_call != nullptr) { glb_policy->updating_lb_call = true; - grpc_call_cancel(glb_policy->lb_call, NULL); + grpc_call_cancel(glb_policy->lb_call, nullptr); // lb_on_server_status_received() will pick up the cancel and reinit // lb_call. } else if (glb_policy->started_picking && !glb_policy->shutting_down) { @@ -1886,21 +1886,21 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, /* Count the number of gRPC-LB addresses. There must be at least one. */ const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - return NULL; + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + return nullptr; } grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; } - if (num_grpclb_addrs == 0) return NULL; + if (num_grpclb_addrs == 0) return nullptr; glb_lb_policy* glb_policy = (glb_lb_policy*)gpr_zalloc(sizeof(*glb_policy)); /* Get server name. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); - GPR_ASSERT(arg != NULL); + GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg->type == GRPC_ARG_STRING); grpc_uri* uri = grpc_uri_parse(exec_ctx, arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); @@ -1914,7 +1914,7 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, grpc_uri_destroy(uri); glb_policy->cc_factory = args->client_channel_factory; - GPR_ASSERT(glb_policy->cc_factory != NULL); + GPR_ASSERT(glb_policy->cc_factory != nullptr); arg = grpc_channel_args_find(args->args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS); glb_policy->lb_call_timeout_ms = @@ -1952,11 +1952,11 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, exec_ctx, glb_policy->response_generator, lb_channel_args); grpc_channel_args_destroy(exec_ctx, lb_channel_args); gpr_free(uri_str); - if (glb_policy->lb_channel == NULL) { + if (glb_policy->lb_channel == nullptr) { gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); gpr_free(glb_policy); - return NULL; + return nullptr; } grpc_subchannel_index_ref(); GRPC_CLOSURE_INIT(&glb_policy->lb_channel_on_connectivity_changed, @@ -1990,10 +1990,10 @@ static bool maybe_add_client_load_reporting_filter( grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* channel_arg = grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME); - if (channel_arg != NULL && channel_arg->type == GRPC_ARG_STRING && + if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING && strcmp(channel_arg->value.string, "grpclb") == 0) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } return true; } 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 4388d6a83e2..0f0d245f82f 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 @@ -59,9 +59,9 @@ typedef struct { static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; - GPR_ASSERT(p->subchannel_list == NULL); - GPR_ASSERT(p->latest_pending_subchannel_list == NULL); - GPR_ASSERT(p->pending_picks == NULL); + GPR_ASSERT(p->subchannel_list == nullptr); + GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); + GPR_ASSERT(p->pending_picks == nullptr); grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); gpr_free(p); grpc_subchannel_index_unref(); @@ -77,24 +77,24 @@ static void shutdown_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p, } p->shutdown = true; pending_pick* pp; - while ((pp = p->pending_picks) != NULL) { + while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), "shutdown"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_shutdown"); - p->subchannel_list = NULL; + p->subchannel_list = nullptr; } - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "pf_shutdown"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } GRPC_ERROR_UNREF(error); } @@ -109,11 +109,11 @@ static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); @@ -133,8 +133,8 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { @@ -154,7 +154,7 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, static void start_picking_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p) { p->started_picking = true; - if (p->subchannel_list != NULL && p->subchannel_list->num_subchannels > 0) { + if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) { p->subchannel_list->checking_subchannel = 0; grpc_lb_subchannel_list_ref_for_connectivity_watch( p->subchannel_list, "connectivity_watch+start_picking"); @@ -177,7 +177,7 @@ static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_closure* on_complete) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; // If we have a selected subchannel already, return synchronously. - if (p->selected != NULL) { + if (p->selected != nullptr) { *target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected->connected_subchannel, "picked"); return 1; @@ -241,8 +241,8 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, pick_first_lb_policy* p = (pick_first_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - if (p->subchannel_list == NULL) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + if (p->subchannel_list == nullptr) { // If we don't have a current subchannel list, go into TRANSIENT FAILURE. grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, @@ -273,18 +273,18 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "pf_update_empty"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // Empty list. - p->selected = NULL; + p->selected = nullptr; return; } - if (p->selected == NULL) { + if (p->selected == nullptr) { // We don't yet have a selected subchannel, so replace the current // subchannel list immediately. - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_update_before_selected"); } @@ -306,12 +306,12 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+replace_selected"); grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "pf_update_includes_selected"); } p->subchannel_list = subchannel_list; - if (p->selected->connected_subchannel != NULL) { + if (p->selected->connected_subchannel != nullptr) { sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( p->selected->connected_subchannel, "pf_update_includes_selected"); } @@ -320,11 +320,11 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // If there was a previously pending update (which may or may // not have contained the currently selected subchannel), drop // it, so that it doesn't override what we've done here. - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "pf_update_includes_selected+outdated"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } return; } @@ -333,7 +333,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // pending subchannel list to the new subchannel list. We will wait // for it to report READY before swapping it into the current // subchannel list. - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down latest pending subchannel list " @@ -401,12 +401,12 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // If the new state is anything other than READY and there is a // pending update, switch to the pending update. if (sd->curr_connectivity_state != GRPC_CHANNEL_READY && - p->latest_pending_subchannel_list != NULL) { - p->selected = NULL; + p->latest_pending_subchannel_list != nullptr) { + p->selected = nullptr; grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "selected_not_ready+switch_to_update"); p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update"); @@ -444,11 +444,11 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // Case 2. Promote p->latest_pending_subchannel_list to // p->subchannel_list. if (sd->subchannel_list == p->latest_pending_subchannel_list) { - GPR_ASSERT(p->subchannel_list != NULL); + GPR_ASSERT(p->subchannel_list != nullptr); grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "finish_update"); p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } // Cases 1 and 2. grpc_connectivity_state_set(exec_ctx, &p->state_tracker, @@ -490,7 +490,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, sd->subchannel_list->num_subchannels; sd = &sd->subchannel_list ->subchannels[sd->subchannel_list->checking_subchannel]; - } while (sd->subchannel == NULL); + } while (sd->subchannel == nullptr); // Case 1: Only set state to TRANSIENT_FAILURE if we've tried // all subchannels. if (sd->subchannel_list->checking_subchannel == 0 && @@ -527,7 +527,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, sd->subchannel_list->num_subchannels; sd = &sd->subchannel_list ->subchannels[sd->subchannel_list->checking_subchannel]; - } while (sd->subchannel == NULL && sd != original_sd); + } while (sd->subchannel == nullptr && sd != original_sd); if (sd == original_sd) { grpc_lb_subchannel_list_unref_for_connectivity_watch( exec_ctx, sd->subchannel_list, "pf_candidate_shutdown"); @@ -567,7 +567,7 @@ static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { - GPR_ASSERT(args->client_channel_factory != NULL); + GPR_ASSERT(args->client_channel_factory != nullptr); pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); if (grpc_lb_pick_first_trace.enabled()) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); 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 f4ad7461579..5e54d1fc77e 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 @@ -99,7 +99,7 @@ typedef struct round_robin_lb_policy { * The caller must do that if it returns a pick. */ static size_t get_next_ready_subchannel_index_locked( const round_robin_lb_policy* p) { - GPR_ASSERT(p->subchannel_list != NULL); + GPR_ASSERT(p->subchannel_list != nullptr); if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " @@ -160,8 +160,8 @@ static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", (void*)pol, (void*)pol); } - GPR_ASSERT(p->subchannel_list == NULL); - GPR_ASSERT(p->latest_pending_subchannel_list == NULL); + GPR_ASSERT(p->subchannel_list == nullptr); + GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); grpc_subchannel_index_unref(); gpr_free(p); @@ -174,25 +174,25 @@ static void shutdown_locked(grpc_exec_ctx* exec_ctx, round_robin_lb_policy* p, } p->shutdown = true; pending_pick* pp; - while ((pp = p->pending_picks) != NULL) { + while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), "rr_shutdown"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_rr_shutdown"); - p->subchannel_list = NULL; + p->subchannel_list = nullptr; } - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "sl_shutdown_pending_rr_shutdown"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } GRPC_ERROR_UNREF(error); } @@ -208,11 +208,11 @@ static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); @@ -232,12 +232,12 @@ static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); @@ -280,7 +280,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, p->shutdown); } GPR_ASSERT(!p->shutdown); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { /* readily available, report right away */ @@ -288,7 +288,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, &p->subchannel_list->subchannels[next_ready_index]; *target = GRPC_CONNECTED_SUBCHANNEL_REF(sd->connected_subchannel, "rr_picked"); - if (user_data != NULL) { + if (user_data != nullptr) { *user_data = sd->user_data; } if (grpc_lb_round_robin_trace.enabled()) { @@ -471,7 +471,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } } else { // sd not in SHUTDOWN if (sd->curr_connectivity_state == GRPC_CHANNEL_READY) { - if (sd->connected_subchannel == NULL) { + if (sd->connected_subchannel == nullptr) { sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( grpc_subchannel_get_connected_subchannel(sd->subchannel), "connected"); @@ -485,7 +485,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, GPR_ASSERT(!sd->subchannel_list->shutting_down); if (grpc_lb_round_robin_trace.enabled()) { const unsigned long num_subchannels = - p->subchannel_list != NULL + p->subchannel_list != nullptr ? (unsigned long)p->subchannel_list->num_subchannels : 0; gpr_log(GPR_DEBUG, @@ -494,13 +494,13 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, (void*)p, (void*)p->subchannel_list, num_subchannels, (void*)sd->subchannel_list, num_subchannels); } - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { // dispose of the current subchannel_list grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "sl_phase_out_shutdown"); } p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } /* at this point we know there's at least one suitable subchannel. Go * ahead and pick one and notify the pending suitors in @@ -509,7 +509,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, GPR_ASSERT(next_ready_index < p->subchannel_list->num_subchannels); grpc_lb_subchannel_data* selected = &p->subchannel_list->subchannels[next_ready_index]; - if (p->pending_picks != NULL) { + if (p->pending_picks != nullptr) { // if the selected subchannel is going to be used for the pending // picks, update the last picked pointer update_last_ready_subchannel_index_locked(p, next_ready_index); @@ -519,7 +519,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, p->pending_picks = pp->next; *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF( selected->connected_subchannel, "rr_picked"); - if (pp->user_data != NULL) { + if (pp->user_data != nullptr) { *pp->user_data = selected->user_data; } if (grpc_lb_round_robin_trace.enabled()) { @@ -576,11 +576,11 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, round_robin_lb_policy* p = (round_robin_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", p); // If we don't have a current subchannel list, go into TRANSIENT_FAILURE. // Otherwise, keep using the current subchannel list (ignore this update). - if (p->subchannel_list == NULL) { + if (p->subchannel_list == nullptr) { grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), @@ -601,7 +601,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "rr_update_empty"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } @@ -609,7 +609,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, return; } if (p->started_picking) { - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { if (grpc_lb_round_robin_trace.enabled()) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down latest pending subchannel list %p, " @@ -634,7 +634,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, } else { // The policy isn't picking yet. Save the update for later, disposing of // previous version if any. - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "rr_update_before_started_picking"); } @@ -661,7 +661,7 @@ static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { - GPR_ASSERT(args->client_channel_factory != NULL); + GPR_ASSERT(args->client_channel_factory != nullptr); round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); 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 ec3fb4e7a2a..7d39cc009fd 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 @@ -31,7 +31,7 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { - if (sd->subchannel != NULL) { + if (sd->subchannel != nullptr) { if (sd->subchannel_list->tracer->enabled()) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -42,16 +42,16 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, sd->subchannel_list->num_subchannels, sd->subchannel); } GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, reason); - sd->subchannel = NULL; - if (sd->connected_subchannel != NULL) { + sd->subchannel = nullptr; + if (sd->connected_subchannel != nullptr) { GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, sd->connected_subchannel, reason); - sd->connected_subchannel = NULL; + sd->connected_subchannel = nullptr; } - if (sd->user_data != NULL) { - GPR_ASSERT(sd->user_data_vtable != NULL); + if (sd->user_data != nullptr) { + GPR_ASSERT(sd->user_data_vtable != nullptr); sd->user_data_vtable->destroy(exec_ctx, sd->user_data); - sd->user_data = NULL; + sd->user_data = nullptr; } } } @@ -126,7 +126,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); grpc_channel_args_destroy(exec_ctx, new_args); - if (subchannel == NULL) { + if (subchannel == nullptr) { // Subchannel could not be created. if (tracer->enabled()) { char* address_uri = @@ -162,7 +162,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( sd->curr_connectivity_state = GRPC_CHANNEL_IDLE; sd->pending_connectivity_state_unsafe = GRPC_CHANNEL_IDLE; sd->user_data_vtable = addresses->user_data_vtable; - if (sd->user_data_vtable != NULL) { + if (sd->user_data_vtable != nullptr) { sd->user_data = sd->user_data_vtable->copy(addresses->addresses[i].user_data); } @@ -240,7 +240,7 @@ static void subchannel_data_cancel_connectivity_watch( (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } - grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, NULL, NULL, + grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, nullptr, &sd->connectivity_changed_closure); } @@ -261,7 +261,7 @@ void grpc_lb_subchannel_list_shutdown_and_unref( // Otherwise, unref the subchannel directly. if (sd->connectivity_notification_pending) { subchannel_data_cancel_connectivity_watch(exec_ctx, sd, reason); - } else if (sd->subchannel != NULL) { + } else if (sd->subchannel != nullptr) { grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, reason); } } diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index f8775d59264..46ec3fbaa61 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -191,7 +191,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, if (err != GRPC_ERROR_NONE) { return err; } - t->incoming_stream = NULL; + t->incoming_stream = nullptr; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_0; return GRPC_ERROR_NONE; @@ -225,7 +225,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, return err; } t->deframe_state = GRPC_DTS_FH_0; - t->incoming_stream = NULL; + t->incoming_stream = nullptr; return GRPC_ERROR_NONE; } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { size_t cur_offset = (size_t)(cur - beg); @@ -238,7 +238,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, return err; } cur += t->incoming_frame_size; - t->incoming_stream = NULL; + t->incoming_stream = nullptr; goto dts_fh_0; /* loop */ } else { err = @@ -337,7 +337,7 @@ static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, t->parser = grpc_chttp2_header_parser_parse; t->parser_data = &t->hpack_parser; t->hpack_parser.on_header = skip_header; - t->hpack_parser.on_header_user_data = NULL; + t->hpack_parser.on_header_user_data = nullptr; t->hpack_parser.is_boundary = is_eoh; t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); } else { @@ -369,7 +369,7 @@ static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, if (err != GRPC_ERROR_NONE) { goto error_handler; } - if (s == NULL) { + if (s == nullptr) { return init_skip_frame_parser(exec_ctx, t, 0); } s->received_bytes += t->incoming_frame_size; @@ -391,9 +391,9 @@ error_handler: t->ping_policy.max_pings_without_data; t->ping_state.last_ping_sent_time = GRPC_MILLIS_INF_PAST; return GRPC_ERROR_NONE; - } 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, nullptr)) { /* handle stream errors by closing the stream */ - if (s != NULL) { + if (s != nullptr) { grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, err); } grpc_slice_buffer_add( @@ -415,7 +415,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_TIMER_BEGIN("on_initial_header", 0); - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); if (grpc_http_trace.enabled()) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); @@ -437,7 +437,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_millis* cached_timeout = static_cast(grpc_mdelem_get_user_data(md, free_timeout)); grpc_millis timeout; - if (cached_timeout != NULL) { + if (cached_timeout != nullptr) { timeout = *cached_timeout; } else { if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), &timeout)) { @@ -499,7 +499,7 @@ static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_TIMER_BEGIN("on_trailing_header", 0); - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); if (grpc_http_trace.enabled()) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); @@ -575,7 +575,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, /* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */ s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { if (is_continuation) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, @@ -617,7 +617,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, t->last_new_stream_id = t->incoming_stream_id; s = t->incoming_stream = grpc_chttp2_parsing_accept_stream(exec_ctx, t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted")); return init_skip_frame_parser(exec_ctx, t, 1); @@ -625,12 +625,12 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, } else { t->incoming_stream = s; } - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); s->stats.incoming.framing_bytes += 9; if (s->read_closed) { GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "skipping already closed grpc_chttp2_stream header")); - t->incoming_stream = NULL; + t->incoming_stream = nullptr; return init_skip_frame_parser(exec_ctx, t, 1); } t->parser = grpc_chttp2_header_parser_parse; @@ -639,7 +639,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, case 0: if (t->is_client && t->header_eof) { GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_INFO, "parsing Trailers-Only")); - if (s->trailing_metadata_available != NULL) { + if (s->trailing_metadata_available != nullptr) { *s->trailing_metadata_available = true; } t->hpack_parser.on_header = on_trailing_header; @@ -677,7 +677,7 @@ static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, if (t->incoming_stream_id != 0) { grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { return init_skip_frame_parser(exec_ctx, t, 0); } s->stats.incoming.framing_bytes += 9; @@ -757,7 +757,7 @@ static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, grpc_error* err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); if (err == GRPC_ERROR_NONE) { 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, nullptr)) { 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/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index c18f8781aae..cf6418a66c1 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -184,7 +184,7 @@ static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { static void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, bool is_initial) { - for (grpc_linked_mdelem* md = md_batch->list.head; md != NULL; + for (grpc_linked_mdelem* md = md_batch->list.head; md != nullptr; md = md->next) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); @@ -200,18 +200,18 @@ static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, uint32_t flags, grpc_metadata_batch* out_md, uint32_t* outflags, bool* markfilled) { if (grpc_inproc_trace.enabled()) { - log_metadata(metadata, s->t->is_client, outflags != NULL); + log_metadata(metadata, s->t->is_client, outflags != nullptr); } - if (outflags != NULL) { + if (outflags != nullptr) { *outflags = flags; } - if (markfilled != NULL) { + if (markfilled != nullptr) { *markfilled = true; } grpc_error* error = GRPC_ERROR_NONE; for (grpc_linked_mdelem* elem = metadata->list.head; - (elem != NULL) && (error == GRPC_ERROR_NONE); elem = elem->next) { + (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { grpc_linked_mdelem* nelem = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); nelem->md = grpc_mdelem_from_slices( @@ -250,7 +250,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, GRPC_CLOSURE_INIT(&s->op_closure, op_state_machine, s, grpc_schedule_on_exec_ctx); s->t = t; - s->closure_at_destroy = NULL; + s->closure_at_destroy = nullptr; s->other_side_closed = false; s->initial_md_sent = s->trailing_md_sent = s->initial_md_recvd = @@ -264,7 +264,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->deadline = GRPC_MILLIS_INF_FUTURE; s->write_buffer_deadline = GRPC_MILLIS_INF_FUTURE; - s->stream_list_prev = NULL; + s->stream_list_prev = nullptr; gpr_mu_lock(&t->mu->mu); s->listed = true; ref_stream(s, "inproc_init_stream:list"); @@ -279,7 +279,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, ref_transport(t); inproc_transport* st = t->other_side; ref_transport(st); - s->other_side = NULL; // will get filled in soon + s->other_side = nullptr; // will get filled in soon // Pass the client-side stream address to the server-side for a ref ref_stream(s, "inproc_init_stream:clt"); // ref it now on behalf of server // side to avoid destruction @@ -311,7 +311,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } if (cs->write_buffer_trailing_md_filled) { fill_in_metadata(exec_ctx, s, &cs->write_buffer_trailing_md, 0, - &s->to_read_trailing_md, NULL, + &s->to_read_trailing_md, nullptr, &s->to_read_trailing_md_filled); grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_trailing_md); cs->write_buffer_trailing_md_filled = false; @@ -335,12 +335,12 @@ static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { if (s->listed) { inproc_stream* p = s->stream_list_prev; inproc_stream* n = s->stream_list_next; - if (p != NULL) { + if (p != nullptr) { p->stream_list_next = n; } else { s->t->stream_list = n; } - if (n != NULL) { + if (n != nullptr) { n->stream_list_prev = p; } s->listed = false; @@ -354,14 +354,14 @@ static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { // This function means that we are done talking/listening to the other side static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, const char* reason) { - if (s->other_side != NULL) { + if (s->other_side != nullptr) { // First release the metadata that came from the other side's arena grpc_metadata_batch_destroy(exec_ctx, &s->to_read_initial_md); grpc_metadata_batch_destroy(exec_ctx, &s->to_read_trailing_md); unref_stream(exec_ctx, s->other_side, reason); s->other_side_closed = true; - s->other_side = NULL; + s->other_side = nullptr; } else if (!s->other_side_closed) { s->write_buffer_other_side_closed = true; } @@ -410,14 +410,14 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&fake_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, NULL, destfilled); + fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &fake_md); - if (other != NULL) { + if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(error); } @@ -451,7 +451,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, - NULL); + nullptr); grpc_metadata_batch_destroy(exec_ctx, &fake_md); err = GRPC_ERROR_NONE; } else { @@ -469,7 +469,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_initial_md_op, "fail_helper scheduling recv-initial-metadata-on-complete"); - s->recv_initial_md_op = NULL; + s->recv_initial_md_op = nullptr; } if (s->recv_message_op) { INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling message-ready %p", s, @@ -480,19 +480,19 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_message_op, "fail_helper scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if (s->send_message_op) { complete_if_batch_end_locked( exec_ctx, s, error, s->send_message_op, "fail_helper scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } if (s->send_trailing_md_op) { complete_if_batch_end_locked( exec_ctx, s, error, s->send_trailing_md_op, "fail_helper scheduling send-trailng-md-on-complete"); - s->send_trailing_md_op = NULL; + s->send_trailing_md_op = nullptr; } if (s->recv_trailing_md_op) { INPROC_LOG(GPR_DEBUG, @@ -501,7 +501,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_trailing_md_op, "fail_helper scheduling recv-trailing-metadata-on-complete"); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; } close_other_side_locked(exec_ctx, s, "fail_helper:other_side"); close_stream_locked(exec_ctx, s); @@ -554,8 +554,8 @@ static void message_transfer_locked(grpc_exec_ctx* exec_ctx, exec_ctx, receiver, GRPC_ERROR_NONE, receiver->recv_message_op, "message_transfer scheduling receiver on_complete"); - receiver->recv_message_op = NULL; - sender->send_message_op = NULL; + receiver->recv_message_op = nullptr; + sender->send_message_op = nullptr; } static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, @@ -601,7 +601,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, GRPC_ERROR_NONE, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } } // Pause a send trailing metadata if there is still an outstanding @@ -612,9 +612,9 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, (!s->send_message_op || (s->t->is_client && (s->trailing_md_recvd || s->to_read_trailing_md_filled)))) { - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; if (*destfilled || s->trailing_md_sent) { // The buffer is already in use; that's an error! @@ -627,7 +627,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, fill_in_metadata(exec_ctx, s, s->send_trailing_md_op->payload->send_trailing_metadata .send_trailing_metadata, - 0, dest, NULL, destfilled); + 0, dest, nullptr, destfilled); } s->trailing_md_sent = true; if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { @@ -635,7 +635,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, "op_state_machine %p scheduling trailing-md-on-complete", s); GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_NONE); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; needs_close = true; } } @@ -643,7 +643,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, GRPC_ERROR_NONE, s->send_trailing_md_op, "op_state_machine scheduling send-trailing-metadata-on-complete"); - s->send_trailing_md_op = NULL; + s->send_trailing_md_op = nullptr; } if (s->recv_initial_md_op) { if (s->initial_md_recvd) { @@ -665,7 +665,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, - NULL); + nullptr); s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata->deadline = s->deadline; grpc_metadata_batch_clear(exec_ctx, &s->to_read_initial_md); @@ -680,7 +680,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_initial_md_op, "op_state_machine scheduling recv-initial-metadata-on-complete"); - s->recv_initial_md_op = NULL; + s->recv_initial_md_op = nullptr; if (new_err != GRPC_ERROR_NONE) { INPROC_LOG(GPR_DEBUG, @@ -713,7 +713,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } - if (s->recv_message_op != NULL) { + if (s->recv_message_op != nullptr) { // This message needs to be wrapped up because it will never be // satisfied INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); @@ -724,7 +724,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if ((s->trailing_md_sent || s->t->is_client) && s->send_message_op) { // Nothing further will try to receive from this stream, so finish off @@ -732,16 +732,16 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } - if (s->recv_trailing_md_op != NULL) { + if (s->recv_trailing_md_op != nullptr) { // We wanted trailing metadata and we got it s->trailing_md_recvd = true; new_err = fill_in_metadata(exec_ctx, s, &s->to_read_trailing_md, 0, s->recv_trailing_md_op->payload ->recv_trailing_metadata.recv_trailing_metadata, - NULL, NULL); + nullptr, nullptr); grpc_metadata_batch_clear(exec_ctx, &s->to_read_trailing_md); s->to_read_trailing_md_filled = false; @@ -756,7 +756,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, s, new_err); GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_REF(new_err)); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; needs_close = true; } else { INPROC_LOG(GPR_DEBUG, @@ -780,7 +780,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if (s->trailing_md_recvd && (s->trailing_md_sent || s->t->is_client) && s->send_message_op) { @@ -789,7 +789,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } if (s->send_message_op || s->send_trailing_md_op || s->recv_initial_md_op || s->recv_message_op || s->recv_trailing_md_op) { @@ -827,14 +827,14 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&cancel_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, NULL, destfilled); + fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &cancel_md); - if (other != NULL) { + if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(s->cancel_self_error); } @@ -851,7 +851,7 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, s->cancel_self_error, s->recv_trailing_md_op, "cancel_stream scheduling trailing-md-on-complete"); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; } } @@ -882,7 +882,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } grpc_error* error = GRPC_ERROR_NONE; grpc_closure* on_complete = op->on_complete; - if (on_complete == NULL) { + if (on_complete == nullptr) { on_complete = &do_nothing_closure; } @@ -914,11 +914,11 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); } if (error == GRPC_ERROR_NONE && op->send_initial_metadata) { - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_initial_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_initial_md : &other->to_read_initial_md; - uint32_t* destflags = (other == NULL) ? &s->write_buffer_initial_md_flags + uint32_t* destflags = (other == nullptr) ? &s->write_buffer_initial_md_flags : &other->to_read_initial_md_flags; - bool* destfilled = (other == NULL) ? &s->write_buffer_initial_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_initial_md_filled : &other->to_read_initial_md_filled; if (*destfilled || s->initial_md_sent) { // The buffer is already in use; that's an error! @@ -934,7 +934,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } if (s->t->is_client) { grpc_millis* dl = - (other == NULL) ? &s->write_buffer_deadline : &other->deadline; + (other == nullptr) ? &s->write_buffer_deadline : &other->deadline; *dl = GPR_MIN(*dl, op->payload->send_initial_metadata .send_initial_metadata->deadline); s->initial_md_sent = true; @@ -973,11 +973,11 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, // 5. There is trailing metadata, even if nothing specifically wants // that because that can shut down the receive message as well if ((op->send_message && other && - ((other->recv_message_op != NULL) || - (other->recv_trailing_md_op != NULL))) || + ((other->recv_message_op != nullptr) || + (other->recv_trailing_md_op != nullptr))) || (op->send_trailing_metadata && !op->send_message) || (op->recv_initial_metadata && s->to_read_initial_md_filled) || - (op->recv_message && other && (other->send_message_op != NULL)) || + (op->recv_message && other && (other->send_message_op != nullptr)) || (s->to_read_trailing_md_filled || s->trailing_md_recvd)) { if (!s->op_closure_scheduled) { GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_NONE); @@ -1031,7 +1031,7 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, if (!t->is_closed) { t->is_closed = true; /* Also end all streams on this transport */ - while (t->stream_list != NULL) { + while (t->stream_list != nullptr) { // cancel_stream_locked also adjusts stream list cancel_stream_locked( exec_ctx, t->stream_list, @@ -1110,7 +1110,7 @@ static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* t) { - return NULL; + return nullptr; } /******************************************************************************* @@ -1120,9 +1120,9 @@ static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, NULL, + GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, nullptr, grpc_schedule_on_exec_ctx); - g_empty_slice = grpc_slice_from_static_buffer(NULL, 0); + g_empty_slice = grpc_slice_from_static_buffer(nullptr, 0); grpc_slice key_tmp = grpc_slice_from_static_string(":path"); g_fake_path_key = grpc_slice_intern(key_tmp); @@ -1173,8 +1173,8 @@ static void inproc_transports_create(grpc_exec_ctx* exec_ctx, "inproc_client"); st->other_side = ct; ct->other_side = st; - st->stream_list = NULL; - ct->stream_list = NULL; + st->stream_list = nullptr; + ct->stream_list = nullptr; *server_transport = (grpc_transport*)st; *client_transport = (grpc_transport*)ct; } @@ -1203,7 +1203,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, inproc_transports_create(&exec_ctx, &server_transport, server_args, &client_transport, client_args); - grpc_server_setup_transport(&exec_ctx, server, server_transport, NULL, + grpc_server_setup_transport(&exec_ctx, server, server_transport, nullptr, server_args); grpc_channel* channel = grpc_channel_create(&exec_ctx, "inproc", client_args, diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index 246634a76f0..10b84401fa0 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -252,7 +252,7 @@ static bool append_error(grpc_error** composite, grpc_error* error, * becomes a spurious read notification on a reused fd. */ -static grpc_fd* fd_freelist = NULL; +static grpc_fd* fd_freelist = nullptr; static gpr_mu fd_freelist_mu; #ifndef NDEBUG @@ -320,7 +320,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); } static void fd_global_shutdown(void) { gpr_mu_lock(&fd_freelist_mu); gpr_mu_unlock(&fd_freelist_mu); - while (fd_freelist != NULL) { + while (fd_freelist != nullptr) { grpc_fd* fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; gpr_free(fd); @@ -329,30 +329,30 @@ static void fd_global_shutdown(void) { } static grpc_fd* fd_create(int fd, const char* name) { - grpc_fd* new_fd = NULL; + grpc_fd* new_fd = nullptr; gpr_mu_lock(&fd_freelist_mu); - if (fd_freelist != NULL) { + if (fd_freelist != nullptr) { new_fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; } gpr_mu_unlock(&fd_freelist_mu); - if (new_fd == NULL) { + if (new_fd == nullptr) { new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); } gpr_mu_init(&new_fd->pollable_mu); gpr_mu_init(&new_fd->orphan_mu); - new_fd->pollable_obj = NULL; + new_fd->pollable_obj = nullptr; gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1); new_fd->fd = fd; new_fd->read_closure.Init(); new_fd->write_closure.Init(); gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); - new_fd->freelist_next = NULL; - new_fd->on_done_closure = NULL; + new_fd->freelist_next = nullptr; + new_fd->on_done_closure = nullptr; char* fd_name; gpr_asprintf(&fd_name, "%s fd=%d", name, fd); @@ -382,7 +382,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, /* If release_fd is not NULL, we should be relinquishing control of the file descriptor fd->fd (but we still own the grpc_fd structure). */ - if (release_fd != NULL) { + if (release_fd != nullptr) { *release_fd = fd->fd; } else if (!is_fd_closed) { close(fd->fd); @@ -438,7 +438,7 @@ static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, */ static grpc_error* pollable_create(pollable_type type, pollable** p) { - *p = NULL; + *p = nullptr; int epfd = epoll_create1(EPOLL_CLOEXEC); if (epfd == -1) { @@ -449,7 +449,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { if (err != GRPC_ERROR_NONE) { close(epfd); gpr_free(*p); - *p = NULL; + *p = nullptr; return err; } struct epoll_event ev; @@ -460,7 +460,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { close(epfd); grpc_wakeup_fd_destroy(&(*p)->wakeup); gpr_free(*p); - *p = NULL; + *p = nullptr; return err; } @@ -468,10 +468,10 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { gpr_ref_init(&(*p)->refs, 1); gpr_mu_init(&(*p)->mu); (*p)->epfd = epfd; - (*p)->owner_fd = NULL; - (*p)->pollset_set = NULL; + (*p)->owner_fd = nullptr; + (*p)->pollset_set = nullptr; (*p)->next = (*p)->prev = *p; - (*p)->root_worker = NULL; + (*p)->root_worker = nullptr; (*p)->event_cursor = 0; (*p)->event_count = 0; return GRPC_ERROR_NONE; @@ -495,14 +495,14 @@ static pollable* pollable_ref(pollable* p, int line, const char* reason) { static void pollable_unref(pollable* p) { #else static void pollable_unref(pollable* p, int line, const char* reason) { - if (p == NULL) return; + if (p == nullptr) return; if (grpc_trace_pollable_refcount.enabled()) { int r = (int)gpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); } #endif - if (p != NULL && gpr_unref(&p->refs)) { + if (p != nullptr && gpr_unref(&p->refs)) { close(p->epfd); grpc_wakeup_fd_destroy(&p->wakeup); gpr_free(p); @@ -563,10 +563,10 @@ static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, pollset, pollset->active_pollable, pollset->shutdown_closure, pollset->root_worker, pollset->containing_pollset_set_count); } - if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL && + if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->containing_pollset_set_count == 0) { GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); - pollset->shutdown_closure = NULL; + pollset->shutdown_closure = nullptr; } } @@ -577,7 +577,7 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, grpc_pollset_worker* specific_worker) { pollable* p = specific_worker->pollable_obj; grpc_core::mu_guard lock(&p->mu); - GPR_ASSERT(specific_worker != NULL); + GPR_ASSERT(specific_worker != nullptr); if (specific_worker->kicked) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p); @@ -626,9 +626,9 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, (void*)gpr_tls_get(&g_current_thread_pollset), (void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker); } - if (specific_worker == NULL) { + if (specific_worker == nullptr) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { - if (pollset->root_worker == NULL) { + if (pollset->root_worker == nullptr) { if (grpc_polling_trace.enabled()) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset); } @@ -671,7 +671,7 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; const char* err_desc = "pollset_kick_all"; grpc_pollset_worker* w = pollset->root_worker; - if (w != NULL) { + if (w != nullptr) { do { GRPC_STATS_INC_POLLSET_KICK(exec_ctx); append_error(&error, kick_one_worker(exec_ctx, w), err_desc); @@ -720,23 +720,23 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { gpr_mu_lock(&fd->pollable_mu); grpc_error* error = GRPC_ERROR_NONE; static const char* err_desc = "fd_get_or_become_pollable"; - if (fd->pollable_obj == NULL) { + if (fd->pollable_obj == nullptr) { if (append_error(&error, pollable_create(PO_FD, &fd->pollable_obj), err_desc)) { fd->pollable_obj->owner_fd = fd; if (!append_error(&error, pollable_add_fd(fd->pollable_obj, fd), err_desc)) { POLLABLE_UNREF(fd->pollable_obj, "fd_pollable"); - fd->pollable_obj = NULL; + fd->pollable_obj = nullptr; } } } if (error == GRPC_ERROR_NONE) { - GPR_ASSERT(fd->pollable_obj != NULL); + GPR_ASSERT(fd->pollable_obj != nullptr); *p = POLLABLE_REF(fd->pollable_obj, "pollset"); } else { - GPR_ASSERT(fd->pollable_obj == NULL); - *p = NULL; + GPR_ASSERT(fd->pollable_obj == nullptr); + *p = nullptr; } gpr_mu_unlock(&fd->pollable_mu); return error; @@ -745,7 +745,7 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { /* pollset->po.mu lock must be held by the caller before calling this */ static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(pollset->shutdown_closure == NULL); + GPR_ASSERT(pollset->shutdown_closure == nullptr); pollset->shutdown_closure = closure; GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); pollset_maybe_finish_shutdown(exec_ctx, pollset); @@ -796,7 +796,7 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, /* pollset_shutdown is guaranteed to be called before pollset_destroy. */ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); - pollset->active_pollable = NULL; + pollset->active_pollable = nullptr; } static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, @@ -836,7 +836,7 @@ static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, /* Return true if first in list */ static bool worker_insert(grpc_pollset_worker** root_worker, grpc_pollset_worker* worker, pwlinks link) { - if (*root_worker == NULL) { + if (*root_worker == nullptr) { *root_worker = worker; worker->links[link].next = worker->links[link].prev = worker; return true; @@ -857,7 +857,7 @@ static worker_remove_result worker_remove(grpc_pollset_worker** root_worker, pwlinks link) { if (worker == *root_worker) { if (worker == worker->links[link].next) { - *root_worker = NULL; + *root_worker = nullptr; return WRR_EMPTIED; } else { *root_worker = worker->links[link].next; @@ -878,7 +878,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { bool do_poll = (pollset->shutdown_closure == nullptr); - if (worker_hdl != NULL) *worker_hdl = worker; + if (worker_hdl != nullptr) *worker_hdl = worker; worker->initialized_cv = false; worker->kicked = false; worker->pollset = pollset; @@ -1051,12 +1051,12 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); grpc_fd* initial_fd = pollset->active_pollable->owner_fd; POLLABLE_UNREF(pollset->active_pollable, "pollset"); - pollset->active_pollable = NULL; + pollset->active_pollable = nullptr; if (append_error(&error, pollable_create(PO_MULTI, &pollset->active_pollable), err_desc)) { append_error(&error, pollable_add_fd(pollset->active_pollable, initial_fd), err_desc); - if (and_add_fd != NULL) { + if (and_add_fd != nullptr) { append_error(&error, pollable_add_fd(pollset->active_pollable, and_add_fd), err_desc); @@ -1122,7 +1122,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, error = pollable_create(PO_MULTI, &pollset->active_pollable); } else { error = pollset_transition_pollable_from_fd_to_multi_locked( - exec_ctx, pollset, NULL); + exec_ctx, pollset, nullptr); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1132,7 +1132,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, if (error != GRPC_ERROR_NONE) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = po_at_start; - *pollable_obj = NULL; + *pollable_obj = nullptr; } else { *pollable_obj = POLLABLE_REF(pollset->active_pollable, "pollset_set"); POLLABLE_UNREF(po_at_start, "pollset_as_multipollable"); @@ -1154,7 +1154,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) { gpr_mu_lock(&pss->mu); - while (pss->parent != NULL) { + while (pss->parent != nullptr) { gpr_mu_unlock(&pss->mu); pss = pss->parent; gpr_mu_lock(&pss->mu); @@ -1170,7 +1170,7 @@ static grpc_pollset_set* pollset_set_create(void) { } static void pollset_set_unref(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) { - if (pss == NULL) return; + if (pss == nullptr) return; if (!gpr_unref(&pss->refs)) return; pollset_set_unref(exec_ctx, pss->parent); gpr_mu_destroy(&pss->mu); @@ -1292,11 +1292,11 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, } grpc_error* error = GRPC_ERROR_NONE; static const char* err_desc = "pollset_set_add_pollset"; - pollable* pollable_obj = NULL; + pollable* pollable_obj = nullptr; gpr_mu_lock(&ps->mu); if (!GRPC_LOG_IF_ERROR(err_desc, pollset_as_multipollable_locked( exec_ctx, ps, &pollable_obj))) { - GPR_ASSERT(pollable_obj == NULL); + GPR_ASSERT(pollable_obj == nullptr); gpr_mu_unlock(&ps->mu); return; } @@ -1341,9 +1341,9 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, gpr_mu* b_mu = &b->mu; gpr_mu_lock(a_mu); gpr_mu_lock(b_mu); - if (a->parent != NULL) { + if (a->parent != nullptr) { a = a->parent; - } else if (b->parent != NULL) { + } else if (b->parent != nullptr) { b = b->parent; } else { break; // exit loop, both pollsets locked @@ -1392,8 +1392,8 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, a->pollset_count += b->pollset_count; gpr_free(b->fds); gpr_free(b->pollsets); - b->fds = NULL; - b->pollsets = NULL; + b->fds = nullptr; + b->pollsets = nullptr; b->fd_count = b->fd_capacity = b->pollset_count = b->pollset_capacity = 0; gpr_mu_unlock(&a->mu); gpr_mu_unlock(&b->mu); @@ -1446,17 +1446,17 @@ static const grpc_event_engine_vtable vtable = { const grpc_event_engine_vtable* grpc_init_epollex_linux( bool explicitly_requested) { if (!explicitly_requested) { - return NULL; + return nullptr; } if (!grpc_has_wakeup_fd()) { gpr_log(GPR_ERROR, "Skipping epollex because of no wakeup fd."); - return NULL; + return nullptr; } if (!grpc_is_epollexclusive_available()) { gpr_log(GPR_INFO, "Skipping epollex because it is not supported."); - return NULL; + return nullptr; } fd_global_init(); @@ -1464,7 +1464,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux( if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { pollset_global_shutdown(); fd_global_shutdown(); - return NULL; + return nullptr; } return &vtable; diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 9cce80cae75..40bde7ccffb 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -165,7 +165,7 @@ static void rulist_add_head(grpc_resource_user* resource_user, grpc_rulist list) { grpc_resource_quota* resource_quota = resource_user->resource_quota; grpc_resource_user** root = &resource_quota->roots[list]; - if (*root == NULL) { + if (*root == nullptr) { *root = resource_user; resource_user->links[list].next = resource_user->links[list].prev = resource_user; @@ -182,7 +182,7 @@ static void rulist_add_tail(grpc_resource_user* resource_user, grpc_rulist list) { grpc_resource_quota* resource_quota = resource_user->resource_quota; grpc_resource_user** root = &resource_quota->roots[list]; - if (*root == NULL) { + if (*root == nullptr) { *root = resource_user; resource_user->links[list].next = resource_user->links[list].prev = resource_user; @@ -196,18 +196,18 @@ static void rulist_add_tail(grpc_resource_user* resource_user, static bool rulist_empty(grpc_resource_quota* resource_quota, grpc_rulist list) { - return resource_quota->roots[list] == NULL; + return resource_quota->roots[list] == nullptr; } static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota, grpc_rulist list) { grpc_resource_user** root = &resource_quota->roots[list]; grpc_resource_user* resource_user = *root; - if (resource_user == NULL) { - return NULL; + if (resource_user == nullptr) { + return nullptr; } if (resource_user->links[list].next == resource_user) { - *root = NULL; + *root = nullptr; } else { resource_user->links[list].next->links[list].prev = resource_user->links[list].prev; @@ -215,24 +215,24 @@ static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota, resource_user->links[list].next; *root = resource_user->links[list].next; } - resource_user->links[list].next = resource_user->links[list].prev = NULL; + resource_user->links[list].next = resource_user->links[list].prev = nullptr; return resource_user; } static void rulist_remove(grpc_resource_user* resource_user, grpc_rulist list) { - if (resource_user->links[list].next == NULL) return; + if (resource_user->links[list].next == nullptr) return; grpc_resource_quota* resource_quota = resource_user->resource_quota; if (resource_quota->roots[list] == resource_user) { resource_quota->roots[list] = resource_user->links[list].next; if (resource_quota->roots[list] == resource_user) { - resource_quota->roots[list] = NULL; + resource_quota->roots[list] = nullptr; } } resource_user->links[list].next->links[list].prev = resource_user->links[list].prev; resource_user->links[list].prev->links[list].next = resource_user->links[list].next; - resource_user->links[list].next = resource_user->links[list].prev = NULL; + resource_user->links[list].next = resource_user->links[list].prev = nullptr; } /******************************************************************************* @@ -379,7 +379,7 @@ static bool rq_reclaim(grpc_exec_ctx* exec_ctx, grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE : GRPC_RULIST_RECLAIMER_BENIGN; grpc_resource_user* resource_user = rulist_pop_head(resource_quota, list); - if (resource_user == NULL) return false; + if (resource_user == nullptr) return false; if (grpc_resource_quota_trace.enabled()) { gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation", resource_quota->name, resource_user->name, @@ -391,7 +391,7 @@ static bool rq_reclaim(grpc_exec_ctx* exec_ctx, GPR_ASSERT(c); resource_quota->debug_only_last_reclaimer_resource_user = resource_user; resource_quota->debug_only_last_initiated_reclaimer = c; - resource_user->reclaimers[destructive] = NULL; + resource_user->reclaimers[destructive] = nullptr; GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_NONE); return true; } @@ -470,9 +470,9 @@ static bool ru_post_reclaimer(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, bool destructive) { grpc_closure* closure = resource_user->new_reclaimers[destructive]; - GPR_ASSERT(closure != NULL); - resource_user->new_reclaimers[destructive] = NULL; - GPR_ASSERT(resource_user->reclaimers[destructive] == NULL); + GPR_ASSERT(closure != nullptr); + resource_user->new_reclaimers[destructive] = nullptr; + GPR_ASSERT(resource_user->reclaimers[destructive] == nullptr); if (gpr_atm_acq_load(&resource_user->shutdown) > 0) { GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CANCELLED); return false; @@ -522,8 +522,8 @@ static void ru_shutdown(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { GRPC_ERROR_CANCELLED); GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); - resource_user->reclaimers[0] = NULL; - resource_user->reclaimers[1] = NULL; + resource_user->reclaimers[0] = nullptr; + resource_user->reclaimers[1] = nullptr; rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); if (resource_user->allocating) { @@ -611,7 +611,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { resource_quota->step_scheduled = false; resource_quota->reclaiming = false; gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation, 0); - if (name != NULL) { + if (name != nullptr) { resource_quota->name = gpr_strdup(name); } else { gpr_asprintf(&resource_quota->name, "anonymous_pool_%" PRIxPTR, @@ -623,7 +623,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { rq_reclamation_done, resource_quota, grpc_combiner_scheduler(resource_quota->combiner)); for (int i = 0; i < GRPC_RULIST_COUNT; i++) { - resource_quota->roots[i] = NULL; + resource_quota->roots[i] = nullptr; } return resource_quota; } @@ -696,7 +696,7 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args( } } } - return grpc_resource_quota_create(NULL); + return grpc_resource_quota_create(nullptr); } static void* rq_copy(void* rq) { @@ -746,15 +746,15 @@ grpc_resource_user* grpc_resource_user_create( grpc_closure_list_init(&resource_user->on_allocated); resource_user->allocating = false; resource_user->added_to_free_pool = false; - resource_user->reclaimers[0] = NULL; - resource_user->reclaimers[1] = NULL; - resource_user->new_reclaimers[0] = NULL; - resource_user->new_reclaimers[1] = NULL; + resource_user->reclaimers[0] = nullptr; + resource_user->reclaimers[1] = nullptr; + resource_user->new_reclaimers[0] = nullptr; + resource_user->new_reclaimers[1] = nullptr; resource_user->outstanding_allocations = 0; for (int i = 0; i < GRPC_RULIST_COUNT; i++) { - resource_user->links[i].next = resource_user->links[i].prev = NULL; + resource_user->links[i].next = resource_user->links[i].prev = nullptr; } - if (name != NULL) { + if (name != nullptr) { resource_user->name = gpr_strdup(name); } else { gpr_asprintf(&resource_user->name, "anonymous_resource_user_%" PRIxPTR, @@ -857,7 +857,7 @@ void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, bool destructive, grpc_closure* closure) { - GPR_ASSERT(resource_user->new_reclaimers[destructive] == NULL); + GPR_ASSERT(resource_user->new_reclaimers[destructive] == nullptr); resource_user->new_reclaimers[destructive] = closure; GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->post_reclaimer_closure[destructive], @@ -899,6 +899,6 @@ void grpc_resource_user_alloc_slices( grpc_slice grpc_resource_user_slice_malloc(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, size_t size) { - grpc_resource_user_alloc(exec_ctx, resource_user, size, NULL); + grpc_resource_user_alloc(exec_ctx, resource_user, size, nullptr); return ru_slice_create(resource_user, size); } diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index d40007a74b2..ff78480a1ab 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -139,7 +139,7 @@ static void run_poller(grpc_exec_ctx* exec_ctx, void* bp, GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", - grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), NULL, deadline)); + grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), nullptr, deadline)); gpr_mu_unlock(p->pollset_mu); /* last "uncovered" notification is the ref that keeps us polling, if we get * there try a cas to release it */ @@ -198,7 +198,7 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { grpc_executor_scheduler(GRPC_EXECUTOR_LONG)), GRPC_ERROR_NONE); } else { - while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == NULL) { + while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == nullptr) { // spin waiting for backup poller } } @@ -368,8 +368,8 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, } } - tcp->read_cb = NULL; - tcp->incoming_buffer = NULL; + tcp->read_cb = nullptr; + tcp->incoming_buffer = nullptr; GRPC_CLOSURE_RUN(exec_ctx, cb, error); } @@ -389,11 +389,11 @@ static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { iov[i].iov_len = GRPC_SLICE_LENGTH(tcp->incoming_buffer->slices[i]); } - msg.msg_name = NULL; + msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = iov; msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count; - msg.msg_control = NULL; + msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; @@ -504,7 +504,7 @@ static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, static void tcp_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; - GPR_ASSERT(tcp->read_cb == NULL); + GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; tcp->incoming_buffer = incoming_buffer; grpc_slice_buffer_reset_and_unref_internal(exec_ctx, incoming_buffer); @@ -552,11 +552,11 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, } GPR_ASSERT(iov_size > 0); - msg.msg_name = NULL; + msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = iov; msg.msg_iovlen = iov_size; - msg.msg_control = NULL; + msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; @@ -617,7 +617,7 @@ static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, if (error != GRPC_ERROR_NONE) { cb = tcp->write_cb; - tcp->write_cb = NULL; + tcp->write_cb = nullptr; cb->cb(exec_ctx, cb->cb_arg, error); TCP_UNREF(exec_ctx, tcp, "write"); return; @@ -630,7 +630,7 @@ static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, notify_on_write(exec_ctx, tcp); } else { cb = tcp->write_cb; - tcp->write_cb = NULL; + tcp->write_cb = nullptr; if (grpc_tcp_trace.enabled()) { const char* str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); @@ -658,7 +658,7 @@ static void tcp_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } GPR_TIMER_BEGIN("tcp_write", 0); - GPR_ASSERT(tcp->write_cb == NULL); + GPR_ASSERT(tcp->write_cb == nullptr); if (buf->length == 0) { GPR_TIMER_END("tcp_write", 0); @@ -745,8 +745,8 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE; int tcp_max_read_chunk_size = 4 * 1024 * 1024; int tcp_min_read_chunk_size = 256; - grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); - if (channel_args != NULL) { + grpc_resource_quota* resource_quota = grpc_resource_quota_create(nullptr); + if (channel_args != nullptr) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) { @@ -785,11 +785,11 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, tcp->base.vtable = &vtable; tcp->peer_string = gpr_strdup(peer_string); tcp->fd = grpc_fd_wrapped_fd(em_fd); - tcp->read_cb = NULL; - tcp->write_cb = NULL; - tcp->release_fd_cb = NULL; - tcp->release_fd = NULL; - tcp->incoming_buffer = NULL; + tcp->read_cb = nullptr; + tcp->write_cb = nullptr; + tcp->release_fd_cb = nullptr; + tcp->release_fd = nullptr; + tcp->incoming_buffer = nullptr; tcp->target_length = (double)tcp_read_chunk_size; tcp->min_read_chunk_size = tcp_min_read_chunk_size; tcp->max_read_chunk_size = tcp_max_read_chunk_size; diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index e44fcdd65ea..19c6148e434 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -37,7 +37,7 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount( grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_client_security_context* ctx = NULL; + grpc_client_security_context* ctx = nullptr; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); if (!grpc_call_is_client(call)) { @@ -46,7 +46,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, } ctx = (grpc_client_security_context*)grpc_call_context_get( call, GRPC_CONTEXT_SECURITY); - if (ctx == NULL) { + if (ctx == nullptr) { ctx = grpc_client_security_context_create(); ctx->creds = grpc_call_credentials_ref(creds); grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx, @@ -62,7 +62,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_auth_context* grpc_call_auth_context(grpc_call* call) { void* sec_ctx = grpc_call_context_get(call, GRPC_CONTEXT_SECURITY); GRPC_API_TRACE("grpc_call_auth_context(call=%p)", 1, (call)); - if (sec_ctx == NULL) return NULL; + if (sec_ctx == nullptr) return nullptr; return grpc_call_is_client(call) ? GRPC_AUTH_CONTEXT_REF( ((grpc_client_security_context*)sec_ctx)->auth_context, @@ -89,7 +89,7 @@ void grpc_client_security_context_destroy(void* ctx) { grpc_client_security_context* c = (grpc_client_security_context*)ctx; grpc_call_credentials_unref(&exec_ctx, c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); - if (c->extension.instance != NULL && c->extension.destroy != NULL) { + if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); @@ -106,7 +106,7 @@ grpc_server_security_context* grpc_server_security_context_create(void) { void grpc_server_security_context_destroy(void* ctx) { grpc_server_security_context* c = (grpc_server_security_context*)ctx; GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context"); - if (c->extension.instance != NULL && c->extension.destroy != NULL) { + if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); @@ -114,13 +114,13 @@ void grpc_server_security_context_destroy(void* ctx) { /* --- grpc_auth_context --- */ -static grpc_auth_property_iterator empty_iterator = {NULL, 0, NULL}; +static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr}; grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) { grpc_auth_context* ctx = (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context)); gpr_ref_init(&ctx->refcount, 1); - if (chained != NULL) { + if (chained != nullptr) { ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained"); ctx->peer_identity_property_name = ctx->chained->peer_identity_property_name; @@ -132,7 +132,7 @@ grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) { grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx, const char* file, int line, const char* reason) { - if (ctx == NULL) return NULL; + if (ctx == nullptr) return nullptr; if (grpc_trace_auth_context_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -150,7 +150,7 @@ grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) { #ifndef NDEBUG void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line, const char* reason) { - if (ctx == NULL) return; + if (ctx == nullptr) return; if (grpc_trace_auth_context_refcount.enabled()) { gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -164,7 +164,7 @@ void grpc_auth_context_unref(grpc_auth_context* ctx) { if (gpr_unref(&ctx->refcount)) { size_t i; GRPC_AUTH_CONTEXT_UNREF(ctx->chained, "chained"); - if (ctx->properties.array != NULL) { + if (ctx->properties.array != nullptr) { for (i = 0; i < ctx->properties.count; i++) { grpc_auth_property_reset(&ctx->properties.array[i]); } @@ -189,9 +189,9 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx, GRPC_API_TRACE( "grpc_auth_context_set_peer_identity_property_name(ctx=%p, name=%s)", 2, (ctx, name)); - if (prop == NULL) { + if (prop == nullptr) { gpr_log(GPR_ERROR, "Property name %s not found in auth context.", - name != NULL ? name : "NULL"); + name != nullptr ? name : "NULL"); return 0; } ctx->peer_identity_property_name = prop->name; @@ -200,14 +200,14 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx, int grpc_auth_context_peer_is_authenticated(const grpc_auth_context* ctx) { GRPC_API_TRACE("grpc_auth_context_peer_is_authenticated(ctx=%p)", 1, (ctx)); - return ctx->peer_identity_property_name == NULL ? 0 : 1; + return ctx->peer_identity_property_name == nullptr ? 0 : 1; } grpc_auth_property_iterator grpc_auth_context_property_iterator( const grpc_auth_context* ctx) { grpc_auth_property_iterator it = empty_iterator; GRPC_API_TRACE("grpc_auth_context_property_iterator(ctx=%p)", 1, (ctx)); - if (ctx == NULL) return it; + if (ctx == nullptr) return it; it.ctx = ctx; return it; } @@ -215,18 +215,18 @@ grpc_auth_property_iterator grpc_auth_context_property_iterator( const grpc_auth_property* grpc_auth_property_iterator_next( grpc_auth_property_iterator* it) { GRPC_API_TRACE("grpc_auth_property_iterator_next(it=%p)", 1, (it)); - if (it == NULL || it->ctx == NULL) return NULL; + if (it == nullptr || it->ctx == nullptr) return nullptr; while (it->index == it->ctx->properties.count) { - if (it->ctx->chained == NULL) return NULL; + if (it->ctx->chained == nullptr) return nullptr; it->ctx = it->ctx->chained; it->index = 0; } - if (it->name == NULL) { + if (it->name == nullptr) { return &it->ctx->properties.array[it->index++]; } else { while (it->index < it->ctx->properties.count) { const grpc_auth_property* prop = &it->ctx->properties.array[it->index++]; - GPR_ASSERT(prop->name != NULL); + GPR_ASSERT(prop->name != nullptr); if (strcmp(it->name, prop->name) == 0) { return prop; } @@ -241,7 +241,7 @@ grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( grpc_auth_property_iterator it = empty_iterator; GRPC_API_TRACE("grpc_auth_context_find_properties_by_name(ctx=%p, name=%s)", 2, (ctx, name)); - if (ctx == NULL || name == NULL) return empty_iterator; + if (ctx == nullptr || name == nullptr) return empty_iterator; it.ctx = ctx; it.name = name; return it; @@ -250,7 +250,7 @@ grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( grpc_auth_property_iterator grpc_auth_context_peer_identity( const grpc_auth_context* ctx) { GRPC_API_TRACE("grpc_auth_context_peer_identity(ctx=%p)", 1, (ctx)); - if (ctx == NULL) return empty_iterator; + if (ctx == nullptr) return empty_iterator; return grpc_auth_context_find_properties_by_name( ctx, ctx->peer_identity_property_name); } @@ -324,11 +324,11 @@ grpc_arg grpc_auth_context_to_arg(grpc_auth_context* p) { } grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return NULL; + if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_AUTH_CONTEXT_ARG); - return NULL; + return nullptr; } return (grpc_auth_context*)arg->value.pointer.p; } @@ -336,10 +336,10 @@ grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { grpc_auth_context* grpc_find_auth_context_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_auth_context* p = grpc_auth_context_from_arg(&args->args[i]); - if (p != NULL) return p; + if (p != nullptr) return p; } - return NULL; + return nullptr; } diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index 5c508fabea5..c56e459aebd 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -93,10 +93,10 @@ const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, if (peer == nullptr) return nullptr; for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* property = &peer->properties[i]; - if (name == NULL && property->name == NULL) { + if (name == nullptr && property->name == nullptr) { return property; } - if (name != NULL && property->name != NULL && + if (name != nullptr && property->name != nullptr && strcmp(property->name, name) == 0) { return property; } @@ -271,7 +271,7 @@ grpc_security_connector* grpc_security_connector_find_in_args( for (i = 0; i < args->num_args; i++) { grpc_security_connector* sc = grpc_security_connector_from_arg(&args->args[i]); - if (sc != NULL) return sc; + if (sc != nullptr) return sc; } return nullptr; } @@ -333,7 +333,7 @@ static bool fake_check_target(const char* target_type, const char* target, gpr_string_split(set_str, ",", &set, &set_size); bool found = false; for (size_t i = 0; i < set_size; ++i) { - if (set[i] != NULL && strcmp(target, set[i]) == 0) found = true; + if (set[i] != nullptr && strcmp(target, set[i]) == 0) found = true; } for (size_t i = 0; i < set_size; ++i) { gpr_free(set[i]); @@ -613,7 +613,7 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, } static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { - GPR_ASSERT(num_alpn_protocols != NULL); + GPR_ASSERT(num_alpn_protocols != nullptr); *num_alpn_protocols = grpc_chttp2_num_alpn_versions(); const char** alpn_protocol_strings = (const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols)); @@ -752,10 +752,10 @@ grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) { GRPC_SSL_TRANSPORT_SECURITY_TYPE); for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* prop = &peer->properties[i]; - if (prop->name == NULL) continue; + if (prop->name == nullptr) continue; if (strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) { /* If there is no subject alt name, have the CN as the identity. */ - if (peer_identity_property_name == NULL) { + if (peer_identity_property_name == nullptr) { peer_identity_property_name = GRPC_X509_CN_PROPERTY_NAME; } grpc_auth_context_add_property(ctx, GRPC_X509_CN_PROPERTY_NAME, @@ -869,7 +869,7 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( memset(&peer, 0, sizeof(peer)); it = grpc_auth_context_property_iterator(auth_context); - while (grpc_auth_property_iterator_next(&it) != NULL) max_num_props++; + while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++; if (max_num_props > 0) { peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props * @@ -948,7 +948,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) { /* Try overridden roots if needed. */ grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL; - if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != NULL) { + if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != nullptr) { char* pem_root_certs = nullptr; ovrd_res = ssl_roots_override_cb(&pem_root_certs); if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) { @@ -985,7 +985,7 @@ const char* grpc_get_default_ssl_roots(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_default_pem_root_certs); return GRPC_SLICE_IS_EMPTY(default_pem_root_certs) - ? NULL + ? nullptr : (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs); } @@ -1039,7 +1039,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create( config->pem_key_cert_pair->private_key != nullptr && config->pem_key_cert_pair->cert_chain != nullptr; result = tsi_create_ssl_client_handshaker_factory( - has_key_cert_pair ? config->pem_key_cert_pair : NULL, pem_root_certs, + has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs, ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols, &c->client_handshaker_factory); if (result != TSI_OK) { diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 52aaf723b3c..4aec3247976 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -1277,7 +1277,7 @@ static grpc_error* consolidate_batch_errors(batch_control* bctl) { "Call batch failed", bctl->errors, n); for (size_t i = 0; i < n; i++) { GRPC_ERROR_UNREF(bctl->errors[i]); - bctl->errors[i] = NULL; + bctl->errors[i] = nullptr; } return error; } @@ -1452,9 +1452,9 @@ static void process_data_after_md(grpc_exec_ctx* exec_ctx, if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && (call->incoming_compression_algorithm > GRPC_COMPRESS_NONE)) { *call->receiving_buffer = grpc_raw_compressed_byte_buffer_create( - NULL, 0, call->incoming_compression_algorithm); + nullptr, 0, call->incoming_compression_algorithm); } else { - *call->receiving_buffer = grpc_raw_byte_buffer_create(NULL, 0); + *call->receiving_buffer = grpc_raw_byte_buffer_create(nullptr, 0); } GRPC_CLOSURE_INIT(&call->receiving_slice_ready, receiving_slice_ready, bctl, grpc_schedule_on_exec_ctx); @@ -1686,7 +1686,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); grpc_cq_end_op( exec_ctx, call->cq, notify_tag, GRPC_ERROR_NONE, - free_no_op_completion, NULL, + free_no_op_completion, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); } else { GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)notify_tag, GRPC_ERROR_NONE); @@ -1709,7 +1709,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, /* rewrite batch ops into a transport op */ for (i = 0; i < nops; i++) { op = &ops[i]; - if (op->reserved != NULL) { + if (op->reserved != nullptr) { error = GRPC_CALL_ERROR; goto done_with_error; } @@ -1814,7 +1814,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, error = GRPC_CALL_ERROR_INVALID_FLAGS; goto done_with_error; } - if (op->data.send_message.send_message == NULL) { + if (op->data.send_message.send_message == nullptr) { error = GRPC_CALL_ERROR_INVALID_MESSAGE; goto done_with_error; } @@ -1890,7 +1890,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, override_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error from server send status"); } - if (op->data.send_status_from_server.status_details != NULL) { + if (op->data.send_status_from_server.status_details != nullptr) { call->send_extra_metadata[1].md = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal( @@ -1909,7 +1909,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, if (!prepare_application_metadata( exec_ctx, call, (int)op->data.send_status_from_server.trailing_metadata_count, - op->data.send_status_from_server.trailing_metadata, 1, 1, NULL, + op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { GRPC_MDELEM_UNREF(exec_ctx, call->send_extra_metadata[n].md); diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index e6f3b0429ea..e7e5dbd1f15 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -47,7 +47,7 @@ void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, const char* name) { gpr_atm_no_barrier_store(&tracker->current_state_atm, init_state); tracker->current_error = GRPC_ERROR_NONE; - tracker->watchers = NULL; + tracker->watchers = nullptr; tracker->name = gpr_strdup(name); } @@ -93,7 +93,7 @@ grpc_connectivity_state grpc_connectivity_state_get( gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, grpc_connectivity_state_name(cur)); } - if (error != NULL) { + if (error != nullptr) { *error = GRPC_ERROR_REF(tracker->current_error); } return cur; @@ -101,7 +101,7 @@ grpc_connectivity_state grpc_connectivity_state_get( bool grpc_connectivity_state_has_watchers( grpc_connectivity_state_tracker* connectivity_state) { - return connectivity_state->watchers != NULL; + return connectivity_state->watchers != nullptr; } bool grpc_connectivity_state_notify_on_state_change( @@ -111,7 +111,7 @@ bool grpc_connectivity_state_notify_on_state_change( (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); if (grpc_connectivity_state_trace.enabled()) { - if (current == NULL) { + if (current == nullptr) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, tracker->name, notify); } else { @@ -120,17 +120,17 @@ bool grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state_name(cur), notify); } } - if (current == NULL) { + if (current == nullptr) { grpc_connectivity_state_watcher* w = tracker->watchers; - if (w != NULL && w->notify == notify) { + if (w != nullptr && w->notify == notify) { GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); tracker->watchers = w->next; gpr_free(w); return false; } - while (w != NULL) { + while (w != nullptr) { grpc_connectivity_state_watcher* rm_candidate = w->next; - if (rm_candidate != NULL && rm_candidate->notify == notify) { + if (rm_candidate != nullptr && rm_candidate->notify == notify) { GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); w->next = w->next->next; gpr_free(rm_candidate); @@ -188,7 +188,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, } GPR_ASSERT(cur != GRPC_CHANNEL_SHUTDOWN); gpr_atm_no_barrier_store(&tracker->current_state_atm, state); - while ((w = tracker->watchers) != NULL) { + while ((w = tracker->watchers) != nullptr) { *w->current = state; tracker->watchers = w->next; if (grpc_connectivity_state_trace.enabled()) { From 467e8369a896397d40abf7c3e9141c1e7440a2e4 Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Tue, 14 Nov 2017 14:59:37 -0800 Subject: [PATCH 19/27] clang fmt --- .../client_channel/lb_policy/grpclb/grpclb.cc | 8 ++--- .../lb_policy/pick_first/pick_first.cc | 3 +- .../lb_policy/subchannel_list.cc | 3 +- .../ext/transport/inproc/inproc_transport.cc | 33 +++++++++++-------- src/core/lib/iomgr/tcp_posix.cc | 3 +- src/core/lib/surface/call.cc | 4 +-- 6 files changed, 31 insertions(+), 23 deletions(-) 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 005df3c6d1f..9b0cf585118 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 @@ -1178,8 +1178,8 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, bool pick_done = false; if (glb_policy->rr_policy != nullptr) { const grpc_connectivity_state rr_connectivity_state = - grpc_lb_policy_check_connectivity_locked(exec_ctx, - glb_policy->rr_policy, nullptr); + grpc_lb_policy_check_connectivity_locked( + exec_ctx, glb_policy->rr_policy, nullptr); // The glb_policy->rr_policy may have transitioned to SHUTDOWN but the // callback registered to capture this event // (glb_rr_connectivity_changed_locked) may not have been invoked yet. We @@ -1525,8 +1525,8 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->flags = 0; op->reserved = nullptr; op++; - call_error = grpc_call_start_batch_and_execute(exec_ctx, glb_policy->lb_call, - ops, (size_t)(op - ops), nullptr); + call_error = grpc_call_start_batch_and_execute( + exec_ctx, glb_policy->lb_call, ops, (size_t)(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); op = ops; 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 0f0d245f82f..54866f2a5db 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 @@ -154,7 +154,8 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, static void start_picking_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p) { p->started_picking = true; - if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) { + if (p->subchannel_list != nullptr && + p->subchannel_list->num_subchannels > 0) { p->subchannel_list->checking_subchannel = 0; grpc_lb_subchannel_list_ref_for_connectivity_watch( p->subchannel_list, "connectivity_watch+start_picking"); 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 7d39cc009fd..b6fce4d2075 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 @@ -240,7 +240,8 @@ static void subchannel_data_cancel_connectivity_watch( (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } - grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, nullptr, + grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, + nullptr, &sd->connectivity_changed_closure); } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index cf6418a66c1..25790608116 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -410,10 +410,11 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&fake_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md - : &other->to_read_trailing_md; + grpc_metadata_batch* dest = (other == nullptr) + ? &s->write_buffer_trailing_md + : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled - : &other->to_read_trailing_md_filled; + : &other->to_read_trailing_md_filled; fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &fake_md); @@ -612,10 +613,11 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, (!s->send_message_op || (s->t->is_client && (s->trailing_md_recvd || s->to_read_trailing_md_filled)))) { - grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md - : &other->to_read_trailing_md; + grpc_metadata_batch* dest = (other == nullptr) + ? &s->write_buffer_trailing_md + : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled - : &other->to_read_trailing_md_filled; + : &other->to_read_trailing_md_filled; if (*destfilled || s->trailing_md_sent) { // The buffer is already in use; that's an error! INPROC_LOG(GPR_DEBUG, "Extra trailing metadata %p", s); @@ -827,10 +829,11 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&cancel_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md - : &other->to_read_trailing_md; + grpc_metadata_batch* dest = (other == nullptr) + ? &s->write_buffer_trailing_md + : &other->to_read_trailing_md; bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled - : &other->to_read_trailing_md_filled; + : &other->to_read_trailing_md_filled; fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &cancel_md); @@ -914,12 +917,14 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); } if (error == GRPC_ERROR_NONE && op->send_initial_metadata) { - grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_initial_md - : &other->to_read_initial_md; - uint32_t* destflags = (other == nullptr) ? &s->write_buffer_initial_md_flags - : &other->to_read_initial_md_flags; + grpc_metadata_batch* dest = (other == nullptr) + ? &s->write_buffer_initial_md + : &other->to_read_initial_md; + uint32_t* destflags = (other == nullptr) + ? &s->write_buffer_initial_md_flags + : &other->to_read_initial_md_flags; bool* destfilled = (other == nullptr) ? &s->write_buffer_initial_md_filled - : &other->to_read_initial_md_filled; + : &other->to_read_initial_md_filled; if (*destfilled || s->initial_md_sent) { // The buffer is already in use; that's an error! INPROC_LOG(GPR_DEBUG, "Extra initial metadata %p", s); diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index ff78480a1ab..6d9e044fa2e 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -198,7 +198,8 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { grpc_executor_scheduler(GRPC_EXECUTOR_LONG)), GRPC_ERROR_NONE); } else { - while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == nullptr) { + while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == + nullptr) { // spin waiting for backup poller } } diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 4aec3247976..a83c95c8dc3 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -1909,8 +1909,8 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, if (!prepare_application_metadata( exec_ctx, call, (int)op->data.send_status_from_server.trailing_metadata_count, - op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, - 0)) { + op->data.send_status_from_server.trailing_metadata, 1, 1, + nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { GRPC_MDELEM_UNREF(exec_ctx, call->send_extra_metadata[n].md); } From 90ffc3a6f74ee6f7db925a054b6f3973bd0d9fc5 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 14 Nov 2017 16:25:25 -0800 Subject: [PATCH 20/27] Add tracer peer to keep set_enabled private() --- CMakeLists.txt | 2 + Makefile | 2 + build.yaml | 2 + grpc.gyp | 2 + src/core/lib/debug/trace.h | 13 +++--- test/core/iomgr/timer_list_test.cc | 9 ++-- .../core/transport/connectivity_state_test.cc | 3 +- test/core/util/BUILD | 2 + test/core/util/tracer_peer.cc | 41 +++++++++++++++++++ test/core/util/tracer_peer.h | 29 +++++++++++++ .../generated/sources_and_headers.json | 3 ++ 11 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 test/core/util/tracer_peer.cc create mode 100644 test/core/util/tracer_peer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7eb0eb79c8e..b72554af14d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1620,6 +1620,7 @@ add_library(grpc_test_util test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/tracer_peer.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc @@ -1886,6 +1887,7 @@ add_library(grpc_test_util_unsecure test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc + test/core/util/tracer_peer.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc diff --git a/Makefile b/Makefile index 69a60006cb6..378032108ba 100644 --- a/Makefile +++ b/Makefile @@ -3603,6 +3603,7 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/tracer_peer.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ @@ -3859,6 +3860,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ + test/core/util/tracer_peer.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ diff --git a/build.yaml b/build.yaml index 910b00ebe2b..b7b5b93f7bf 100644 --- a/build.yaml +++ b/build.yaml @@ -714,6 +714,7 @@ filegroups: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/slice_splitter.h + - test/core/util/tracer_peer.h - test/core/util/trickle_endpoint.h src: - src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -730,6 +731,7 @@ filegroups: - test/core/util/port.cc - test/core/util/port_server_client.cc - test/core/util/slice_splitter.cc + - test/core/util/tracer_peer.cc - test/core/util/trickle_endpoint.cc deps: - gpr_test_util diff --git a/grpc.gyp b/grpc.gyp index 7075aa9afd0..c9a75079325 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -515,6 +515,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/tracer_peer.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', @@ -723,6 +724,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', + 'test/core/util/tracer_peer.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index cc9d9d2b2d4..5e5143e502c 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -45,6 +45,8 @@ void grpc_tracer_shutdown(void); namespace grpc_core { class TraceFlag { + friend class TraceFlagPeer; + public: TraceFlag(bool default_enabled, const char* name); ~TraceFlag() {} @@ -61,8 +63,9 @@ class TraceFlag { #endif } - // Only to be used for testing purposes. Tracers should usually be set using - // the static Set function + private: + static void LogAllTracers(); + void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER gpr_atm_no_barrier_store(&value_, enabled); @@ -71,9 +74,6 @@ class TraceFlag { #endif } - private: - static void LogAllTracers(); - static TraceFlag* root_tracer_; TraceFlag* next_tracer_; const char* const name_; @@ -91,6 +91,9 @@ class DebugOnlyTraceFlag { public: DebugOnlyTraceFlag(bool default_enabled, const char* name) {} bool enabled() { return false; } + + private: + void set_enabled(bool enabled) {} }; #endif diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 89768946891..6aec1ec13de 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -28,6 +28,7 @@ #include #include "src/core/lib/debug/trace.h" #include "test/core/util/test_config.h" +#include "test/core/util/tracer_peer.h" #define MAX_CB 30 @@ -48,8 +49,8 @@ static void add_test(void) { gpr_log(GPR_INFO, "add_test"); grpc_timer_list_init(&exec_ctx); - grpc_timer_trace.set_enabled(1); - grpc_timer_check_trace.set_enabled(1); + grpc_tracer_peer_enable_flag(&grpc_timer_trace); + grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_millis start = grpc_exec_ctx_now(&exec_ctx); @@ -117,8 +118,8 @@ void destruction_test(void) { exec_ctx.now_is_valid = true; exec_ctx.now = 0; grpc_timer_list_init(&exec_ctx); - grpc_timer_trace.set_enabled(1); - grpc_timer_check_trace.set_enabled(1); + grpc_tracer_peer_enable_flag(&grpc_timer_trace); + grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index f42937ee14a..1eab6d7ea2f 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -23,6 +23,7 @@ #include #include "test/core/util/test_config.h" +#include "test/core/util/tracer_peer.h" #define THE_ARG ((void*)(size_t)0xcafebabe) @@ -136,7 +137,7 @@ static void test_subscribe_with_failure_then_destroy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_connectivity_state_trace.set_enabled(1); + grpc_tracer_peer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 24379234351..684986aa3e0 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -57,6 +57,7 @@ grpc_cc_library( "reconnect_server.cc", "slice_splitter.cc", "test_tcp_server.cc", + "tracer_peer.cc", "trickle_endpoint.cc", ], hdrs = [ @@ -69,6 +70,7 @@ grpc_cc_library( "reconnect_server.h", "slice_splitter.h", "test_tcp_server.h", + "tracer_peer.h", "trickle_endpoint.h", ], language = "C++", diff --git a/test/core/util/tracer_peer.cc b/test/core/util/tracer_peer.cc new file mode 100644 index 00000000000..6c18430f894 --- /dev/null +++ b/test/core/util/tracer_peer.cc @@ -0,0 +1,41 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/util/test_config.h" + +#include "src/core/lib/debug/trace.h" + +namespace grpc_core { + +// This class is a friend of TraceFlag, and can be used to manually turn on +// certain tracers for tests. +class TraceFlagPeer { + public: + TraceFlagPeer(TraceFlag* flag) : flag_(flag) {} + void enable() { flag_->set_enabled(1); } + void disable() { flag_->set_enabled(0); } + + private: + TraceFlag* flag_; +}; +} // namespace grpc_core + +void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag) { + grpc_core::TraceFlagPeer peer(flag); + peer.enable(); +} diff --git a/test/core/util/tracer_peer.h b/test/core/util/tracer_peer.h new file mode 100644 index 00000000000..e8a5f6c31aa --- /dev/null +++ b/test/core/util/tracer_peer.h @@ -0,0 +1,29 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_TEST_CORE_UTIL_TRACER_PEER_H +#define GRPC_TEST_CORE_UTIL_TRACER_PEER_H + +namespace grpc_core { +class TraceFlag; +} + +// enables the TraceFlag passed to it. Used for testing purposes. +void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag); + +#endif /* GRPC_TEST_CORE_UTIL_TRACER_PEER_H */ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fce01bf8ff3..63ba4f22820 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8880,6 +8880,7 @@ "test/core/util/port.h", "test/core/util/port_server_client.h", "test/core/util/slice_splitter.h", + "test/core/util/tracer_peer.h", "test/core/util/trickle_endpoint.h" ], "is_filegroup": true, @@ -8914,6 +8915,8 @@ "test/core/util/port_server_client.h", "test/core/util/slice_splitter.cc", "test/core/util/slice_splitter.h", + "test/core/util/tracer_peer.cc", + "test/core/util/tracer_peer.h", "test/core/util/trickle_endpoint.cc", "test/core/util/trickle_endpoint.h" ], From 49fe9871bfa8bb0d5548ff2738d33b0256c82f23 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 14 Nov 2017 16:44:38 -0800 Subject: [PATCH 21/27] pull global tracer list from TraceFlag class --- src/core/lib/debug/trace.cc | 16 +++++++++------- src/core/lib/debug/trace.h | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 5df2229aae3..f7cf49530f4 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -29,17 +29,19 @@ int grpc_tracer_set_enabled(const char* name, int enabled); namespace grpc_core { -TraceFlag* TraceFlag::root_tracer_ = nullptr; +// there is only ever one global list of tracers for the entire program. +static TraceFlag* g_root_tracer = nullptr; +// Flags register themselves on the list during construction TraceFlag::TraceFlag(bool default_enabled, const char* name) - : next_tracer_(root_tracer_), name_(name), value_(default_enabled) { - root_tracer_ = this; + : next_tracer_(g_root_tracer), name_(name), value_(default_enabled) { + g_root_tracer = this; } void TraceFlag::LogAllTracers() { gpr_log(GPR_DEBUG, "available tracers:"); TraceFlag* t; - for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { + for (t = g_root_tracer; t != nullptr; t = t->next_tracer_) { gpr_log(GPR_DEBUG, "\t%s", t->name_); } } @@ -47,20 +49,20 @@ void TraceFlag::LogAllTracers() { bool TraceFlag::Set(const char* name, bool enabled) { TraceFlag* t; if (0 == strcmp(name, "all")) { - for (t = root_tracer_; t; t = t->next_tracer_) { + for (t = g_root_tracer; t; t = t->next_tracer_) { t->set_enabled(enabled); } } else if (0 == strcmp(name, "list_tracers")) { LogAllTracers(); } else if (0 == strcmp(name, "refcount")) { - for (t = root_tracer_; t; t = t->next_tracer_) { + for (t = g_root_tracer; t; t = t->next_tracer_) { if (strstr(t->name_, "refcount") != nullptr) { t->set_enabled(enabled); } } } else { bool found = false; - for (t = root_tracer_; t; t = t->next_tracer_) { + for (t = g_root_tracer; t; t = t->next_tracer_) { if (0 == strcmp(name, t->name_)) { t->set_enabled(enabled); found = true; diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 5e5143e502c..9bda744f380 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -46,15 +46,16 @@ namespace grpc_core { class TraceFlag { friend class TraceFlagPeer; + friend class TracerList; public: TraceFlag(bool default_enabled, const char* name); ~TraceFlag() {} - static bool Set(const char* tracer, bool enabled); - const char* name() const { return name_; } + static bool Set(const char* name, bool enabled); + bool enabled() { #ifdef GRPC_THREADSAFE_TRACER return gpr_atm_no_barrier_load(&value_) != 0; @@ -74,7 +75,6 @@ class TraceFlag { #endif } - static TraceFlag* root_tracer_; TraceFlag* next_tracer_; const char* const name_; #ifdef GRPC_THREADSAFE_TRACER From dabd7c0ad9e76dbed10b57cb16195e643d1bf511 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Wed, 15 Nov 2017 08:25:30 -0800 Subject: [PATCH 22/27] Fix window compile --- src/core/lib/surface/api_trace.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/core/lib/surface/api_trace.h b/src/core/lib/surface/api_trace.h index b475dceface..a4e11ce1544 100644 --- a/src/core/lib/surface/api_trace.h +++ b/src/core/lib/surface/api_trace.h @@ -24,10 +24,6 @@ extern grpc_core::TraceFlag grpc_api_trace; -#ifdef __cplusplus -extern "C" { -#endif - /* Provide unwrapping macros because we're in C89 and variadic macros weren't introduced until C99... */ #define GRPC_API_TRACE_UNWRAP0() @@ -51,8 +47,4 @@ extern "C" { gpr_log(GPR_INFO, fmt GRPC_API_TRACE_UNWRAP##nargs args); \ } -#ifdef __cplusplus -} -#endif - #endif /* GRPC_CORE_LIB_SURFACE_API_TRACE_H */ From 5b554fb199c0c1e7494b0097991eb7048e219920 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Wed, 15 Nov 2017 15:01:41 -0800 Subject: [PATCH 23/27] More fix for Windows artifact --- src/core/lib/surface/lame_client.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 7114a9f5452..d1cf4d78e98 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -25,7 +25,6 @@ #include "src/core/lib/support/atomic.h" -extern "C" { #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" @@ -33,7 +32,6 @@ extern "C" { #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/lame_client.h" #include "src/core/lib/transport/static_metadata.h" -} namespace grpc_core { From 9006013267a00f214390e8a0cfc6311d8e999f17 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 16 Nov 2017 08:44:17 -0800 Subject: [PATCH 24/27] Reviewer feedback: singleton TraceFlagList --- src/core/lib/debug/trace.cc | 52 ++++++++++++++++++++++--------------- src/core/lib/debug/trace.h | 20 ++++++++++---- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index f7cf49530f4..04558fd91eb 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -29,40 +29,31 @@ int grpc_tracer_set_enabled(const char* name, int enabled); namespace grpc_core { -// there is only ever one global list of tracers for the entire program. -static TraceFlag* g_root_tracer = nullptr; +TraceFlagList* TraceFlagList::instance_ = nullptr; -// Flags register themselves on the list during construction -TraceFlag::TraceFlag(bool default_enabled, const char* name) - : next_tracer_(g_root_tracer), name_(name), value_(default_enabled) { - g_root_tracer = this; -} - -void TraceFlag::LogAllTracers() { - gpr_log(GPR_DEBUG, "available tracers:"); - TraceFlag* t; - for (t = g_root_tracer; t != nullptr; t = t->next_tracer_) { - gpr_log(GPR_DEBUG, "\t%s", t->name_); - } +TraceFlagList* TraceFlagList::Get() { + if (instance_ == nullptr) + instance_ = static_cast(gpr_malloc(sizeof(TraceFlagList))); + return instance_; } -bool TraceFlag::Set(const char* name, bool enabled) { +bool TraceFlagList::Set(const char* name, bool enabled) { TraceFlag* t; if (0 == strcmp(name, "all")) { - for (t = g_root_tracer; t; t = t->next_tracer_) { + for (t = root_tracer_; t; t = t->next_tracer_) { t->set_enabled(enabled); } } else if (0 == strcmp(name, "list_tracers")) { LogAllTracers(); } else if (0 == strcmp(name, "refcount")) { - for (t = g_root_tracer; t; t = t->next_tracer_) { + for (t = root_tracer_; t; t = t->next_tracer_) { if (strstr(t->name_, "refcount") != nullptr) { t->set_enabled(enabled); } } } else { bool found = false; - for (t = g_root_tracer; t; t = t->next_tracer_) { + for (t = root_tracer_; t; t = t->next_tracer_) { if (0 == strcmp(name, t->name_)) { t->set_enabled(enabled); found = true; @@ -76,6 +67,25 @@ bool TraceFlag::Set(const char* name, bool enabled) { return true; } +void TraceFlagList::Add(TraceFlag* flag) { + flag->next_tracer_ = root_tracer_; + root_tracer_ = flag; +} + +void TraceFlagList::LogAllTracers() { + gpr_log(GPR_DEBUG, "available tracers:"); + TraceFlag* t; + for (t = root_tracer_; t != nullptr; t = t->next_tracer_) { + gpr_log(GPR_DEBUG, "\t%s", t->name_); + } +} + +// Flags register themselves on the list during construction +TraceFlag::TraceFlag(bool default_enabled, const char* name) + : name_(name), value_(default_enabled) { + TraceFlagList::Get()->Add(this); +} + } // namespace grpc_core static void add(const char* beg, const char* end, char*** ss, size_t* ns) { @@ -111,9 +121,9 @@ static void parse(const char* s) { for (i = 0; i < nstrings; i++) { if (strings[i][0] == '-') { - grpc_core::TraceFlag::Set(strings[i] + 1, false); + grpc_core::TraceFlagList::Get()->Set(strings[i] + 1, false); } else { - grpc_core::TraceFlag::Set(strings[i], true); + grpc_core::TraceFlagList::Get()->Set(strings[i], true); } } @@ -134,5 +144,5 @@ void grpc_tracer_init(const char* env_var) { void grpc_tracer_shutdown(void) {} int grpc_tracer_set_enabled(const char* name, int enabled) { - return grpc_core::TraceFlag::Set(name, enabled != 0); + return grpc_core::TraceFlagList::Get()->Set(name, enabled != 0); } diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 9bda744f380..3371a7c20d1 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -44,9 +44,23 @@ void grpc_tracer_shutdown(void); namespace grpc_core { +class TraceFlag; +class TraceFlagList { + public: + static TraceFlagList* Get(); + bool Set(const char* name, bool enabled); + void Add(TraceFlag* flag); + + private: + static TraceFlagList* instance_; + void LogAllTracers(); + TraceFlagList() : root_tracer_(nullptr) {} + TraceFlag* root_tracer_; +}; + class TraceFlag { friend class TraceFlagPeer; - friend class TracerList; + friend class TraceFlagList; public: TraceFlag(bool default_enabled, const char* name); @@ -54,8 +68,6 @@ class TraceFlag { const char* name() const { return name_; } - static bool Set(const char* name, bool enabled); - bool enabled() { #ifdef GRPC_THREADSAFE_TRACER return gpr_atm_no_barrier_load(&value_) != 0; @@ -65,8 +77,6 @@ class TraceFlag { } private: - static void LogAllTracers(); - void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER gpr_atm_no_barrier_store(&value_, enabled); From b2aa06ae990e82b5c7f573f282b7bcfef7093d54 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 16 Nov 2017 09:02:58 -0800 Subject: [PATCH 25/27] Reviewer feedback: friend func not clasS --- src/core/lib/debug/trace.h | 6 +++++- test/core/iomgr/timer_list_test.cc | 8 ++++---- .../core/transport/connectivity_state_test.cc | 3 ++- test/core/util/tracer_peer.cc | 20 +++++-------------- test/core/util/tracer_peer.h | 5 ++++- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 3371a7c20d1..8e3a39d173c 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -58,8 +58,12 @@ class TraceFlagList { TraceFlag* root_tracer_; }; +namespace testing { +void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag); +} + class TraceFlag { - friend class TraceFlagPeer; + friend void grpc_core::testing::grpc_tracer_peer_enable_flag(TraceFlag* flag); friend class TraceFlagList; public: diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 6aec1ec13de..73be93511b9 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -49,8 +49,8 @@ static void add_test(void) { gpr_log(GPR_INFO, "add_test"); grpc_timer_list_init(&exec_ctx); - grpc_tracer_peer_enable_flag(&grpc_timer_trace); - grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); + grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_trace); + grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_millis start = grpc_exec_ctx_now(&exec_ctx); @@ -118,8 +118,8 @@ void destruction_test(void) { exec_ctx.now_is_valid = true; exec_ctx.now = 0; grpc_timer_list_init(&exec_ctx); - grpc_tracer_peer_enable_flag(&grpc_timer_trace); - grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); + grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_trace); + grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 1eab6d7ea2f..e4d27950ecb 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -137,7 +137,8 @@ static void test_subscribe_with_failure_then_destroy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_tracer_peer_enable_flag(&grpc_connectivity_state_trace); + grpc_core::testing::grpc_tracer_peer_enable_flag( + &grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); diff --git a/test/core/util/tracer_peer.cc b/test/core/util/tracer_peer.cc index 6c18430f894..acb770515f4 100644 --- a/test/core/util/tracer_peer.cc +++ b/test/core/util/tracer_peer.cc @@ -21,21 +21,11 @@ #include "src/core/lib/debug/trace.h" namespace grpc_core { - -// This class is a friend of TraceFlag, and can be used to manually turn on -// certain tracers for tests. -class TraceFlagPeer { - public: - TraceFlagPeer(TraceFlag* flag) : flag_(flag) {} - void enable() { flag_->set_enabled(1); } - void disable() { flag_->set_enabled(0); } - - private: - TraceFlag* flag_; -}; -} // namespace grpc_core +namespace testing { void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag) { - grpc_core::TraceFlagPeer peer(flag); - peer.enable(); + flag->set_enabled(1); } + +} // namespace testing +} // namespace grpc_core diff --git a/test/core/util/tracer_peer.h b/test/core/util/tracer_peer.h index e8a5f6c31aa..0b6c6dd685f 100644 --- a/test/core/util/tracer_peer.h +++ b/test/core/util/tracer_peer.h @@ -21,9 +21,12 @@ namespace grpc_core { class TraceFlag; -} +namespace testing { // enables the TraceFlag passed to it. Used for testing purposes. void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag); +} // namespace testing +} // namespace grpc_core + #endif /* GRPC_TEST_CORE_UTIL_TRACER_PEER_H */ From c4dd9cfe1893081b6783213f96d2b72b7b02d165 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 17 Nov 2017 13:39:01 -0800 Subject: [PATCH 26/27] reviewer feedback --- src/core/lib/debug/trace.cc | 16 +++++----------- src/core/lib/debug/trace.h | 19 ++++++++----------- test/core/iomgr/timer_list_test.cc | 8 ++++---- .../core/transport/connectivity_state_test.cc | 3 +-- test/core/util/tracer_peer.cc | 2 +- test/core/util/tracer_peer.h | 2 +- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index 04558fd91eb..4c63983bdce 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -29,13 +29,7 @@ int grpc_tracer_set_enabled(const char* name, int enabled); namespace grpc_core { -TraceFlagList* TraceFlagList::instance_ = nullptr; - -TraceFlagList* TraceFlagList::Get() { - if (instance_ == nullptr) - instance_ = static_cast(gpr_malloc(sizeof(TraceFlagList))); - return instance_; -} +TraceFlag* TraceFlagList::root_tracer_ = nullptr; bool TraceFlagList::Set(const char* name, bool enabled) { TraceFlag* t; @@ -83,7 +77,7 @@ void TraceFlagList::LogAllTracers() { // Flags register themselves on the list during construction TraceFlag::TraceFlag(bool default_enabled, const char* name) : name_(name), value_(default_enabled) { - TraceFlagList::Get()->Add(this); + TraceFlagList::Add(this); } } // namespace grpc_core @@ -121,9 +115,9 @@ static void parse(const char* s) { for (i = 0; i < nstrings; i++) { if (strings[i][0] == '-') { - grpc_core::TraceFlagList::Get()->Set(strings[i] + 1, false); + grpc_core::TraceFlagList::Set(strings[i] + 1, false); } else { - grpc_core::TraceFlagList::Get()->Set(strings[i], true); + grpc_core::TraceFlagList::Set(strings[i], true); } } @@ -144,5 +138,5 @@ void grpc_tracer_init(const char* env_var) { void grpc_tracer_shutdown(void) {} int grpc_tracer_set_enabled(const char* name, int enabled) { - return grpc_core::TraceFlagList::Get()->Set(name, enabled != 0); + return grpc_core::TraceFlagList::Set(name, enabled != 0); } diff --git a/src/core/lib/debug/trace.h b/src/core/lib/debug/trace.h index 8e3a39d173c..b58c16f3ca4 100644 --- a/src/core/lib/debug/trace.h +++ b/src/core/lib/debug/trace.h @@ -47,25 +47,19 @@ namespace grpc_core { class TraceFlag; class TraceFlagList { public: - static TraceFlagList* Get(); - bool Set(const char* name, bool enabled); - void Add(TraceFlag* flag); + static bool Set(const char* name, bool enabled); + static void Add(TraceFlag* flag); private: - static TraceFlagList* instance_; - void LogAllTracers(); - TraceFlagList() : root_tracer_(nullptr) {} - TraceFlag* root_tracer_; + static void LogAllTracers(); + static TraceFlag* root_tracer_; }; namespace testing { -void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag); +void grpc_tracer_enable_flag(grpc_core::TraceFlag* flag); } class TraceFlag { - friend void grpc_core::testing::grpc_tracer_peer_enable_flag(TraceFlag* flag); - friend class TraceFlagList; - public: TraceFlag(bool default_enabled, const char* name); ~TraceFlag() {} @@ -81,6 +75,9 @@ class TraceFlag { } private: + friend void grpc_core::testing::grpc_tracer_enable_flag(TraceFlag* flag); + friend class TraceFlagList; + void set_enabled(bool enabled) { #ifdef GRPC_THREADSAFE_TRACER gpr_atm_no_barrier_store(&value_, enabled); diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 73be93511b9..5730a306ec1 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -49,8 +49,8 @@ static void add_test(void) { gpr_log(GPR_INFO, "add_test"); grpc_timer_list_init(&exec_ctx); - grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_trace); - grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_millis start = grpc_exec_ctx_now(&exec_ctx); @@ -118,8 +118,8 @@ void destruction_test(void) { exec_ctx.now_is_valid = true; exec_ctx.now = 0; grpc_timer_list_init(&exec_ctx); - grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_trace); - grpc_core::testing::grpc_tracer_peer_enable_flag(&grpc_timer_check_trace); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_trace); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_timer_check_trace); memset(cb_called, 0, sizeof(cb_called)); grpc_timer_init( diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index e4d27950ecb..f33bfd2c947 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -137,8 +137,7 @@ static void test_subscribe_with_failure_then_destroy(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); - grpc_core::testing::grpc_tracer_peer_enable_flag( - &grpc_connectivity_state_trace); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); test_connectivity_state_name(); test_check(); test_subscribe_then_unsubscribe(); diff --git a/test/core/util/tracer_peer.cc b/test/core/util/tracer_peer.cc index acb770515f4..34a132daa78 100644 --- a/test/core/util/tracer_peer.cc +++ b/test/core/util/tracer_peer.cc @@ -23,7 +23,7 @@ namespace grpc_core { namespace testing { -void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag) { +void grpc_tracer_enable_flag(grpc_core::TraceFlag* flag) { flag->set_enabled(1); } diff --git a/test/core/util/tracer_peer.h b/test/core/util/tracer_peer.h index 0b6c6dd685f..6dd04f65491 100644 --- a/test/core/util/tracer_peer.h +++ b/test/core/util/tracer_peer.h @@ -24,7 +24,7 @@ class TraceFlag; namespace testing { // enables the TraceFlag passed to it. Used for testing purposes. -void grpc_tracer_peer_enable_flag(grpc_core::TraceFlag* flag); +void grpc_tracer_enable_flag(grpc_core::TraceFlag* flag); } // namespace testing } // namespace grpc_core From aa3b19741f345faa3eb3d9bdcfa9d7064e5c439c Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 17 Nov 2017 15:56:27 -0800 Subject: [PATCH 27/27] Rename tracer_peer to tracer_util --- CMakeLists.txt | 4 ++-- Makefile | 4 ++-- build.yaml | 4 ++-- grpc.gyp | 4 ++-- test/core/iomgr/timer_list_test.cc | 2 +- test/core/transport/connectivity_state_test.cc | 2 +- test/core/util/BUILD | 4 ++-- test/core/util/{tracer_peer.cc => tracer_util.cc} | 0 test/core/util/{tracer_peer.h => tracer_util.h} | 6 +++--- tools/run_tests/generated/sources_and_headers.json | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) rename test/core/util/{tracer_peer.cc => tracer_util.cc} (100%) rename test/core/util/{tracer_peer.h => tracer_util.h} (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b72554af14d..b31c14b8409 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1620,7 +1620,7 @@ add_library(grpc_test_util test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc - test/core/util/tracer_peer.cc + test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc @@ -1887,7 +1887,7 @@ add_library(grpc_test_util_unsecure test/core/util/port.cc test/core/util/port_server_client.cc test/core/util/slice_splitter.cc - test/core/util/tracer_peer.cc + test/core/util/tracer_util.cc test/core/util/trickle_endpoint.cc src/core/lib/backoff/backoff.cc src/core/lib/channel/channel_args.cc diff --git a/Makefile b/Makefile index 378032108ba..4c585e1ad8b 100644 --- a/Makefile +++ b/Makefile @@ -3603,7 +3603,7 @@ LIBGRPC_TEST_UTIL_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ - test/core/util/tracer_peer.cc \ + test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ @@ -3860,7 +3860,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ test/core/util/port.cc \ test/core/util/port_server_client.cc \ test/core/util/slice_splitter.cc \ - test/core/util/tracer_peer.cc \ + test/core/util/tracer_util.cc \ test/core/util/trickle_endpoint.cc \ src/core/lib/backoff/backoff.cc \ src/core/lib/channel/channel_args.cc \ diff --git a/build.yaml b/build.yaml index b7b5b93f7bf..8c8d526cb8c 100644 --- a/build.yaml +++ b/build.yaml @@ -714,7 +714,7 @@ filegroups: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/slice_splitter.h - - test/core/util/tracer_peer.h + - test/core/util/tracer_util.h - test/core/util/trickle_endpoint.h src: - src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -731,7 +731,7 @@ filegroups: - test/core/util/port.cc - test/core/util/port_server_client.cc - test/core/util/slice_splitter.cc - - test/core/util/tracer_peer.cc + - test/core/util/tracer_util.cc - test/core/util/trickle_endpoint.cc deps: - gpr_test_util diff --git a/grpc.gyp b/grpc.gyp index c9a75079325..b8137364571 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -515,7 +515,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', - 'test/core/util/tracer_peer.cc', + 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', @@ -724,7 +724,7 @@ 'test/core/util/port.cc', 'test/core/util/port_server_client.cc', 'test/core/util/slice_splitter.cc', - 'test/core/util/tracer_peer.cc', + 'test/core/util/tracer_util.cc', 'test/core/util/trickle_endpoint.cc', 'src/core/lib/backoff/backoff.cc', 'src/core/lib/channel/channel_args.cc', diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index 5730a306ec1..d74ea4fc96d 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -28,7 +28,7 @@ #include #include "src/core/lib/debug/trace.h" #include "test/core/util/test_config.h" -#include "test/core/util/tracer_peer.h" +#include "test/core/util/tracer_util.h" #define MAX_CB 30 diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index f33bfd2c947..11046e126e9 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -23,7 +23,7 @@ #include #include "test/core/util/test_config.h" -#include "test/core/util/tracer_peer.h" +#include "test/core/util/tracer_util.h" #define THE_ARG ((void*)(size_t)0xcafebabe) diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 684986aa3e0..6443553466f 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -57,7 +57,7 @@ grpc_cc_library( "reconnect_server.cc", "slice_splitter.cc", "test_tcp_server.cc", - "tracer_peer.cc", + "tracer_util.cc", "trickle_endpoint.cc", ], hdrs = [ @@ -70,7 +70,7 @@ grpc_cc_library( "reconnect_server.h", "slice_splitter.h", "test_tcp_server.h", - "tracer_peer.h", + "tracer_util.h", "trickle_endpoint.h", ], language = "C++", diff --git a/test/core/util/tracer_peer.cc b/test/core/util/tracer_util.cc similarity index 100% rename from test/core/util/tracer_peer.cc rename to test/core/util/tracer_util.cc diff --git a/test/core/util/tracer_peer.h b/test/core/util/tracer_util.h similarity index 86% rename from test/core/util/tracer_peer.h rename to test/core/util/tracer_util.h index 6dd04f65491..0b432ffa46a 100644 --- a/test/core/util/tracer_peer.h +++ b/test/core/util/tracer_util.h @@ -16,8 +16,8 @@ * */ -#ifndef GRPC_TEST_CORE_UTIL_TRACER_PEER_H -#define GRPC_TEST_CORE_UTIL_TRACER_PEER_H +#ifndef GRPC_TEST_CORE_UTIL_TRACER_UTIL_H +#define GRPC_TEST_CORE_UTIL_TRACER_UTIL_H namespace grpc_core { class TraceFlag; @@ -29,4 +29,4 @@ void grpc_tracer_enable_flag(grpc_core::TraceFlag* flag); } // namespace testing } // namespace grpc_core -#endif /* GRPC_TEST_CORE_UTIL_TRACER_PEER_H */ +#endif /* GRPC_TEST_CORE_UTIL_TRACER_UTIL_H */ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 63ba4f22820..c1927a3f179 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -8880,7 +8880,7 @@ "test/core/util/port.h", "test/core/util/port_server_client.h", "test/core/util/slice_splitter.h", - "test/core/util/tracer_peer.h", + "test/core/util/tracer_util.h", "test/core/util/trickle_endpoint.h" ], "is_filegroup": true, @@ -8915,8 +8915,8 @@ "test/core/util/port_server_client.h", "test/core/util/slice_splitter.cc", "test/core/util/slice_splitter.h", - "test/core/util/tracer_peer.cc", - "test/core/util/tracer_peer.h", + "test/core/util/tracer_util.cc", + "test/core/util/tracer_util.h", "test/core/util/trickle_endpoint.cc", "test/core/util/trickle_endpoint.h" ],