From 0079382cfd3ebce8310d8cfa5c653a7a1a3f515b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sun, 4 Sep 2022 00:01:47 -0700 Subject: [PATCH] [cq] Track cq type to determine api usage (#30833) * [cq] Track cq type to determine api usage * Automated change: Fix sanity tests * fix Co-authored-by: ctiller --- src/core/lib/debug/stats_data.cc | 9 +++++- src/core/lib/debug/stats_data.h | 9 ++++++ src/core/lib/debug/stats_data.yaml | 7 +++++ src/core/lib/debug/stats_data_bq_schema.sql | 5 +++- src/core/lib/surface/completion_queue.cc | 13 ++++++++ .../lib/surface/completion_queue_factory.cc | 5 ++++ .../performance/massage_qps_stats.py | 7 +++++ .../performance/scenario_result_schema.json | 30 +++++++++++++++++++ 8 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/core/lib/debug/stats_data.cc b/src/core/lib/debug/stats_data.cc index addaa84d315..6b46a1ff1cf 100644 --- a/src/core/lib/debug/stats_data.cc +++ b/src/core/lib/debug/stats_data.cc @@ -35,7 +35,8 @@ const char* grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { "tcp_read_alloc_8k", "tcp_read_alloc_64k", "http2_settings_writes", "http2_pings_sent", "http2_writes_begun", "http2_transport_stalls", - "http2_stream_stalls", + "http2_stream_stalls", "cq_pluck_creates", + "cq_next_creates", "cq_callback_creates", }; const char* grpc_stats_counter_doc[GRPC_STATS_COUNTER_COUNT] = { "Number of client side calls created by this process", @@ -57,6 +58,12 @@ const char* grpc_stats_counter_doc[GRPC_STATS_COUNTER_COUNT] = { "control window", "Number of times sending was completely stalled by the stream flow control " "window", + "Number of completion queues created for cq_pluck (indicates sync api " + "usage)", + "Number of completion queues created for cq_next (indicates cq async api " + "usage)", + "Number of completion queues created for cq_callback (indicates callback " + "api usage)", }; const char* grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { "call_initial_size", "tcp_write_size", "tcp_write_iov_size", diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index df47419ae2e..f47af826147 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -39,6 +39,9 @@ typedef enum { GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN, GRPC_STATS_COUNTER_HTTP2_TRANSPORT_STALLS, GRPC_STATS_COUNTER_HTTP2_STREAM_STALLS, + GRPC_STATS_COUNTER_CQ_PLUCK_CREATES, + GRPC_STATS_COUNTER_CQ_NEXT_CREATES, + GRPC_STATS_COUNTER_CQ_CALLBACK_CREATES, GRPC_STATS_COUNTER_COUNT } grpc_stats_counters; extern const char* grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; @@ -102,6 +105,12 @@ typedef enum { GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_TRANSPORT_STALLS) #define GRPC_STATS_INC_HTTP2_STREAM_STALLS() \ GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_HTTP2_STREAM_STALLS) +#define GRPC_STATS_INC_CQ_PLUCK_CREATES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_PLUCK_CREATES) +#define GRPC_STATS_INC_CQ_NEXT_CREATES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_NEXT_CREATES) +#define GRPC_STATS_INC_CQ_CALLBACK_CREATES() \ + GRPC_STATS_INC_COUNTER(GRPC_STATS_COUNTER_CQ_CALLBACK_CREATES) #define GRPC_STATS_INC_CALL_INITIAL_SIZE(value) \ grpc_stats_inc_call_initial_size((int)(value)) void grpc_stats_inc_call_initial_size(int x); diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index eee5a686bed..fc3ad9ca555 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -78,3 +78,10 @@ doc: Number of times sending was completely stalled by the transport flow control window - counter: http2_stream_stalls doc: Number of times sending was completely stalled by the stream flow control window +# completion queues +- counter: cq_pluck_creates + doc: Number of completion queues created for cq_pluck (indicates sync api usage) +- counter: cq_next_creates + doc: Number of completion queues created for cq_next (indicates cq async api usage) +- counter: cq_callback_creates + doc: Number of completion queues created for cq_callback (indicates callback api usage) diff --git a/src/core/lib/debug/stats_data_bq_schema.sql b/src/core/lib/debug/stats_data_bq_schema.sql index 643abfa180d..5f4637138d6 100644 --- a/src/core/lib/debug/stats_data_bq_schema.sql +++ b/src/core/lib/debug/stats_data_bq_schema.sql @@ -12,4 +12,7 @@ http2_settings_writes_per_iteration:FLOAT, http2_pings_sent_per_iteration:FLOAT, http2_writes_begun_per_iteration:FLOAT, http2_transport_stalls_per_iteration:FLOAT, -http2_stream_stalls_per_iteration:FLOAT +http2_stream_stalls_per_iteration:FLOAT, +cq_pluck_creates_per_iteration:FLOAT, +cq_next_creates_per_iteration:FLOAT, +cq_callback_creates_per_iteration:FLOAT diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index a8a8352352b..b114bc53178 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -40,6 +40,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gpr/tls.h" #include "src/core/lib/gprpp/atomic_utils.h" @@ -509,6 +510,18 @@ grpc_completion_queue* grpc_completion_queue_create_internal( "polling_type=%d)", 2, (completion_type, polling_type)); + switch (completion_type) { + case GRPC_CQ_NEXT: + GRPC_STATS_INC_CQ_NEXT_CREATES(); + break; + case GRPC_CQ_PLUCK: + GRPC_STATS_INC_CQ_PLUCK_CREATES(); + break; + case GRPC_CQ_CALLBACK: + GRPC_STATS_INC_CQ_CALLBACK_CREATES(); + break; + } + const cq_vtable* vtable = &g_cq_vtable[completion_type]; const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; diff --git a/src/core/lib/surface/completion_queue_factory.cc b/src/core/lib/surface/completion_queue_factory.cc index 8206d97e143..29542b478bc 100644 --- a/src/core/lib/surface/completion_queue_factory.cc +++ b/src/core/lib/surface/completion_queue_factory.cc @@ -23,6 +23,7 @@ #include #include +#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/surface/completion_queue.h" /* @@ -60,6 +61,7 @@ const grpc_completion_queue_factory* grpc_completion_queue_factory_lookup( */ grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) { + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(!reserved); grpc_completion_queue_attributes attr = {1, GRPC_CQ_NEXT, GRPC_CQ_DEFAULT_POLLING, nullptr}; @@ -67,6 +69,7 @@ grpc_completion_queue* grpc_completion_queue_create_for_next(void* reserved) { } grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) { + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(!reserved); grpc_completion_queue_attributes attr = {1, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, nullptr}; @@ -75,6 +78,7 @@ grpc_completion_queue* grpc_completion_queue_create_for_pluck(void* reserved) { grpc_completion_queue* grpc_completion_queue_create_for_callback( grpc_completion_queue_functor* shutdown_callback, void* reserved) { + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(!reserved); grpc_completion_queue_attributes attr = { 2, GRPC_CQ_CALLBACK, GRPC_CQ_DEFAULT_POLLING, shutdown_callback}; @@ -84,6 +88,7 @@ grpc_completion_queue* grpc_completion_queue_create_for_callback( grpc_completion_queue* grpc_completion_queue_create( const grpc_completion_queue_factory* factory, const grpc_completion_queue_attributes* attr, void* reserved) { + grpc_core::ExecCtx exec_ctx; GPR_ASSERT(!reserved); return factory->vtable->create(factory, attr); } diff --git a/tools/run_tests/performance/massage_qps_stats.py b/tools/run_tests/performance/massage_qps_stats.py index 9a91e778140..7a9f5bea81f 100644 --- a/tools/run_tests/performance/massage_qps_stats.py +++ b/tools/run_tests/performance/massage_qps_stats.py @@ -65,6 +65,13 @@ def massage_qps_stats(scenario_result): stats[ "core_http2_stream_stalls"] = massage_qps_stats_helpers.counter( core_stats, "http2_stream_stalls") + stats["core_cq_pluck_creates"] = massage_qps_stats_helpers.counter( + core_stats, "cq_pluck_creates") + stats["core_cq_next_creates"] = massage_qps_stats_helpers.counter( + core_stats, "cq_next_creates") + stats[ + "core_cq_callback_creates"] = massage_qps_stats_helpers.counter( + core_stats, "cq_callback_creates") h = massage_qps_stats_helpers.histogram(core_stats, "call_initial_size") stats["core_call_initial_size"] = ",".join( diff --git a/tools/run_tests/performance/scenario_result_schema.json b/tools/run_tests/performance/scenario_result_schema.json index 58023f3ae94..b654da9c97e 100644 --- a/tools/run_tests/performance/scenario_result_schema.json +++ b/tools/run_tests/performance/scenario_result_schema.json @@ -185,6 +185,21 @@ "name": "core_http2_stream_stalls", "type": "INTEGER" }, + { + "mode": "NULLABLE", + "name": "core_cq_pluck_creates", + "type": "INTEGER" + }, + { + "mode": "NULLABLE", + "name": "core_cq_next_creates", + "type": "INTEGER" + }, + { + "mode": "NULLABLE", + "name": "core_cq_callback_creates", + "type": "INTEGER" + }, { "mode": "NULLABLE", "name": "core_call_initial_size", @@ -462,6 +477,21 @@ "name": "core_http2_stream_stalls", "type": "INTEGER" }, + { + "mode": "NULLABLE", + "name": "core_cq_pluck_creates", + "type": "INTEGER" + }, + { + "mode": "NULLABLE", + "name": "core_cq_next_creates", + "type": "INTEGER" + }, + { + "mode": "NULLABLE", + "name": "core_cq_callback_creates", + "type": "INTEGER" + }, { "mode": "NULLABLE", "name": "core_call_initial_size",