diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index ddf4d76321c..6f2719b6b4b 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -964,7 +964,8 @@ void ConnectionDestroy(void* arg, grpc_error_handle /*error*/) { bool Subchannel::PublishTransportLocked() { // Construct channel stack. - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = + grpc_channel_stack_builder_create("subchannel"); grpc_channel_stack_builder_set_channel_arguments( builder, connecting_result_.channel_args); grpc_channel_stack_builder_set_transport(builder, diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index a7f890e26d7..711c0a00a6f 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -29,6 +29,7 @@ #include "src/core/lib/gpr/alloc.h" grpc_core::TraceFlag grpc_trace_channel(false, "channel"); +grpc_core::TraceFlag grpc_trace_channel_stack(false, "channel_stack"); /* Memory layouts. @@ -105,6 +106,13 @@ grpc_error_handle grpc_channel_stack_init( const grpc_channel_filter** filters, size_t filter_count, const grpc_channel_args* channel_args, grpc_transport* optional_transport, const char* name, grpc_channel_stack* stack) { + if (grpc_trace_channel_stack.enabled()) { + gpr_log(GPR_INFO, "CHANNEL_STACK: init %s", name); + for (size_t i = 0; i < filter_count; i++) { + gpr_log(GPR_INFO, "CHANNEL_STACK: filter %s", filters[i]->name); + } + } + size_t call_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)) + GPR_ROUND_UP_TO_ALIGNMENT_SIZE(filter_count * sizeof(grpc_call_element)); diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 72985b807fe..207ef19af4f 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -51,7 +51,8 @@ struct grpc_channel_stack_builder_iterator { filter_node* node; }; -grpc_channel_stack_builder* grpc_channel_stack_builder_create(void) { +grpc_channel_stack_builder* grpc_channel_stack_builder_create( + const char* name) { grpc_channel_stack_builder* b = grpc_core::Zalloc(); b->begin.filter = nullptr; @@ -60,6 +61,7 @@ grpc_channel_stack_builder* grpc_channel_stack_builder_create(void) { b->begin.prev = &b->end; b->end.next = &b->begin; b->end.prev = &b->begin; + b->name = name; return b; } @@ -143,12 +145,6 @@ grpc_channel_stack_builder_iterator* grpc_channel_stack_builder_iterator_find( bool grpc_channel_stack_builder_move_prev( grpc_channel_stack_builder_iterator* iterator); -void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder* builder, - const char* name) { - GPR_ASSERT(builder->name == nullptr); - builder->name = name; -} - void grpc_channel_stack_builder_set_channel_arguments( grpc_channel_stack_builder* builder, const grpc_channel_args* args) { if (builder->args != nullptr) { diff --git a/src/core/lib/channel/channel_stack_builder.h b/src/core/lib/channel/channel_stack_builder.h index 5518329cd74..cf2a700d969 100644 --- a/src/core/lib/channel/channel_stack_builder.h +++ b/src/core/lib/channel/channel_stack_builder.h @@ -32,12 +32,9 @@ typedef struct grpc_channel_stack_builder grpc_channel_stack_builder; typedef struct grpc_channel_stack_builder_iterator grpc_channel_stack_builder_iterator; -/// Create a new channel stack builder -grpc_channel_stack_builder* grpc_channel_stack_builder_create(void); - -/// Assign a name to the channel stack: \a name must be statically allocated -void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder* builder, - const char* name); +/// Create a new channel stack builder. +/// \a name must be statically allocated. +grpc_channel_stack_builder* grpc_channel_stack_builder_create(const char* name); /// Set the target uri void grpc_channel_stack_builder_set_target(grpc_channel_stack_builder* b, diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index a2e58634dee..5586032b0dc 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -46,6 +46,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" +#include "src/core/lib/surface/channel_stack_type.h" /** Cache grpc-status: X mdelems for X = 0..NUM_CACHED_STATUS_ELEMS. * Avoids needing to take a metadata context lock for sending status @@ -243,7 +244,8 @@ grpc_channel* grpc_channel_create(const char* target, // grpc_shutdown() when the channel is actually destroyed, thus // ensuring that shutdown is deferred until that point. grpc_init(); - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create( + grpc_channel_stack_type_string(channel_stack_type)); const grpc_core::UniquePtr default_authority = get_default_authority(input_args); grpc_channel_args* args = diff --git a/test/core/channel/minimal_stack_is_minimal_test.cc b/test/core/channel/minimal_stack_is_minimal_test.cc index 4eda818bfa8..147af858781 100644 --- a/test/core/channel/minimal_stack_is_minimal_test.cc +++ b/test/core/channel/minimal_stack_is_minimal_test.cc @@ -126,7 +126,8 @@ static int check_stack(const char* file, int line, const char* transport_name, grpc_channel_args* init_args, unsigned channel_stack_type, ...) { // create phony channel stack - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = + grpc_channel_stack_builder_create("test"); grpc_transport_vtable fake_transport_vtable; memset(&fake_transport_vtable, 0, sizeof(grpc_transport_vtable)); fake_transport_vtable.name = transport_name; diff --git a/test/core/xds/xds_channel_stack_modifier_test.cc b/test/core/xds/xds_channel_stack_modifier_test.cc index 7e804140901..d1fd905a067 100644 --- a/test/core/xds/xds_channel_stack_modifier_test.cc +++ b/test/core/xds/xds_channel_stack_modifier_test.cc @@ -79,7 +79,8 @@ TEST(XdsChannelStackModifierTest, XdsHttpFiltersInsertion) { grpc_arg arg = channel_stack_modifier->MakeChannelArg(); // Create a phony grpc_channel_stack_builder object grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = + grpc_channel_stack_builder_create("test"); grpc_channel_stack_builder_set_channel_arguments(builder, args); grpc_channel_args_destroy(args); grpc_transport_vtable fake_transport_vtable; @@ -123,7 +124,8 @@ TEST(XdsChannelStackModifierTest, XdsHttpFiltersInsertionAfterCensus) { grpc_arg arg = channel_stack_modifier->MakeChannelArg(); // Create a phony grpc_channel_stack_builder object grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); + grpc_channel_stack_builder* builder = + grpc_channel_stack_builder_create("test"); grpc_channel_stack_builder_set_channel_arguments(builder, args); grpc_channel_args_destroy(args); grpc_transport_vtable fake_transport_vtable; diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 9882fe0f70e..bf1de891f45 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -707,8 +707,8 @@ class IsolatedCallFixture : public TrackCounters { const grpc_channel_args* args = grpc_core::CoreConfiguration::Get() .channel_args_preconditioning() .PreconditionChannelArgs(nullptr); - grpc_channel_stack_builder* builder = grpc_channel_stack_builder_create(); - grpc_channel_stack_builder_set_name(builder, "phony"); + grpc_channel_stack_builder* builder = + grpc_channel_stack_builder_create("phony"); grpc_channel_stack_builder_set_target(builder, "phony_target"); grpc_channel_stack_builder_set_channel_arguments(builder, args); GPR_ASSERT(grpc_channel_stack_builder_append_filter(