From 280866817ffdec59d0446df3c99c2544837da3ad Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 18 Jul 2017 14:22:19 -0700 Subject: Add a simple stats framework to gRPC C core --- test/core/end2end/tests/simple_request.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index 7a81133dfa..82ab0a1cfe 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -27,6 +27,7 @@ #include #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/support/string.h" #include "test/core/end2end/cq_verifier.h" @@ -102,6 +103,10 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_slice details; int was_cancelled = 2; char *peer; + grpc_stats_data before; + grpc_stats_data after; + + grpc_stats_collect(&before); gpr_timespec deadline = five_seconds_from_now(); c = grpc_channel_create_call( @@ -208,6 +213,23 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_unref(s); cq_verifier_destroy(cqv); + + grpc_stats_collect(&after); + + char *stats = grpc_stats_data_as_json(&after); + gpr_log(GPR_DEBUG, "%s", stats); + gpr_free(stats); + + int expected_calls = 1; + if (config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) { + expected_calls *= 2; + } + GPR_ASSERT(after.counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] - + before.counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] == + expected_calls); + GPR_ASSERT(after.counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] - + before.counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] == + expected_calls); } static void test_invoke_simple_request(grpc_end2end_test_config config) { -- cgit v1.2.3 From b89304652b162453df2ad21ab45123735a106392 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 19 Jul 2017 16:24:19 -0700 Subject: Build simplification --- CMakeLists.txt | 20 ++++++++-------- Makefile | 20 ++++++++-------- binding.gyp | 4 ++-- build.yaml | 14 ++++------- config.m4 | 4 ++-- config.w32 | 4 ++-- gRPC-Core.podspec | 12 +++++----- grpc.gemspec | 8 +++---- package.xml | 8 +++---- src/python/grpcio/grpc_core_dependencies.py | 4 ++-- test/cpp/microbenchmarks/helpers.cc | 7 ++++++ test/cpp/microbenchmarks/helpers.h | 3 +++ tools/run_tests/generated/sources_and_headers.json | 27 +++++----------------- vsprojects/vcxproj/grpc/grpc.vcxproj | 12 +++++----- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 24 +++++++++---------- .../vcxproj/grpc_test_util/grpc_test_util.vcxproj | 12 +++++----- .../grpc_test_util/grpc_test_util.vcxproj.filters | 24 +++++++++---------- .../vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 12 +++++----- .../grpc_unsecure/grpc_unsecure.vcxproj.filters | 24 +++++++++---------- 19 files changed, 116 insertions(+), 127 deletions(-) (limited to 'test') diff --git a/CMakeLists.txt b/CMakeLists.txt index db629e8499..d50bd440a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -957,6 +957,8 @@ add_library(grpc src/core/lib/compression/compression.c src/core/lib/compression/message_compress.c src/core/lib/compression/stream_compression.c + src/core/lib/debug/stats.c + src/core/lib/debug/stats_data.c src/core/lib/http/format_request.c src/core/lib/http/httpcli.c src/core/lib/http/parser.c @@ -1073,8 +1075,6 @@ add_library(grpc src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c src/core/lib/debug/trace.c - src/core/lib/debug/stats.c - src/core/lib/debug/stats_data.c src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c src/core/ext/transport/chttp2/transport/bin_decoder.c src/core/ext/transport/chttp2/transport/bin_encoder.c @@ -1302,6 +1302,8 @@ add_library(grpc_cronet src/core/lib/compression/compression.c src/core/lib/compression/message_compress.c src/core/lib/compression/stream_compression.c + src/core/lib/debug/stats.c + src/core/lib/debug/stats_data.c src/core/lib/http/format_request.c src/core/lib/http/httpcli.c src/core/lib/http/parser.c @@ -1418,8 +1420,6 @@ add_library(grpc_cronet src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c src/core/lib/debug/trace.c - src/core/lib/debug/stats.c - src/core/lib/debug/stats_data.c src/core/ext/transport/cronet/client/secure/cronet_channel_create.c src/core/ext/transport/cronet/transport/cronet_api_dummy.c src/core/ext/transport/cronet/transport/cronet_transport.c @@ -1625,6 +1625,8 @@ add_library(grpc_test_util src/core/lib/compression/compression.c src/core/lib/compression/message_compress.c src/core/lib/compression/stream_compression.c + src/core/lib/debug/stats.c + src/core/lib/debug/stats_data.c src/core/lib/http/format_request.c src/core/lib/http/httpcli.c src/core/lib/http/parser.c @@ -1741,8 +1743,6 @@ add_library(grpc_test_util src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c src/core/lib/debug/trace.c - src/core/lib/debug/stats.c - src/core/lib/debug/stats_data.c ) if(WIN32 AND MSVC) @@ -1890,6 +1890,8 @@ add_library(grpc_unsecure src/core/lib/compression/compression.c src/core/lib/compression/message_compress.c src/core/lib/compression/stream_compression.c + src/core/lib/debug/stats.c + src/core/lib/debug/stats_data.c src/core/lib/http/format_request.c src/core/lib/http/httpcli.c src/core/lib/http/parser.c @@ -2006,8 +2008,6 @@ add_library(grpc_unsecure src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c src/core/lib/debug/trace.c - src/core/lib/debug/stats.c - src/core/lib/debug/stats_data.c src/core/ext/transport/chttp2/server/insecure/server_chttp2.c src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c src/core/ext/transport/chttp2/transport/bin_decoder.c @@ -2551,6 +2551,8 @@ add_library(grpc++_cronet src/core/lib/compression/compression.c src/core/lib/compression/message_compress.c src/core/lib/compression/stream_compression.c + src/core/lib/debug/stats.c + src/core/lib/debug/stats_data.c src/core/lib/http/format_request.c src/core/lib/http/httpcli.c src/core/lib/http/parser.c @@ -2667,8 +2669,6 @@ add_library(grpc++_cronet src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c src/core/lib/debug/trace.c - src/core/lib/debug/stats.c - src/core/lib/debug/stats_data.c src/core/ext/transport/chttp2/alpn/alpn.c src/core/ext/filters/http/client/http_client_filter.c src/core/ext/filters/http/http_filters_plugin.c diff --git a/Makefile b/Makefile index d942f94e4a..9b005ef9e2 100644 --- a/Makefile +++ b/Makefile @@ -2901,6 +2901,8 @@ LIBGRPC_SRC = \ src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -3017,8 +3019,6 @@ LIBGRPC_SRC = \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c \ src/core/ext/transport/chttp2/transport/bin_decoder.c \ src/core/ext/transport/chttp2/transport/bin_encoder.c \ @@ -3244,6 +3244,8 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -3360,8 +3362,6 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ src/core/ext/transport/cronet/client/secure/cronet_channel_create.c \ src/core/ext/transport/cronet/transport/cronet_api_dummy.c \ src/core/ext/transport/cronet/transport/cronet_transport.c \ @@ -3564,6 +3564,8 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -3680,8 +3682,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ PUBLIC_HEADERS_C += \ include/grpc/byte_buffer.h \ @@ -3801,6 +3801,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -3917,8 +3919,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2.c \ src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c \ src/core/ext/transport/chttp2/transport/bin_decoder.c \ @@ -4446,6 +4446,8 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -4562,8 +4564,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ src/core/ext/transport/chttp2/alpn/alpn.c \ src/core/ext/filters/http/client/http_client_filter.c \ src/core/ext/filters/http/http_filters_plugin.c \ diff --git a/binding.gyp b/binding.gyp index f091850be1..b514d7aa60 100644 --- a/binding.gyp +++ b/binding.gyp @@ -646,6 +646,8 @@ 'src/core/lib/compression/compression.c', 'src/core/lib/compression/message_compress.c', 'src/core/lib/compression/stream_compression.c', + 'src/core/lib/debug/stats.c', + 'src/core/lib/debug/stats_data.c', 'src/core/lib/http/format_request.c', 'src/core/lib/http/httpcli.c', 'src/core/lib/http/parser.c', @@ -762,8 +764,6 @@ 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', 'src/core/lib/debug/trace.c', - 'src/core/lib/debug/stats.c', - 'src/core/lib/debug/stats_data.c', 'src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c', 'src/core/ext/transport/chttp2/transport/bin_decoder.c', 'src/core/ext/transport/chttp2/transport/bin_encoder.c', diff --git a/build.yaml b/build.yaml index 0811606e40..ea2eb1d42b 100644 --- a/build.yaml +++ b/build.yaml @@ -192,6 +192,8 @@ filegroups: - src/core/lib/compression/algorithm_metadata.h - src/core/lib/compression/message_compress.h - src/core/lib/compression/stream_compression.h + - src/core/lib/debug/stats.h + - src/core/lib/debug/stats_data.h - src/core/lib/http/format_request.h - src/core/lib/http/httpcli.h - src/core/lib/http/parser.h @@ -302,6 +304,8 @@ filegroups: - src/core/lib/compression/compression.c - src/core/lib/compression/message_compress.c - src/core/lib/compression/stream_compression.c + - src/core/lib/debug/stats.c + - src/core/lib/debug/stats_data.c - src/core/lib/http/format_request.c - src/core/lib/http/httpcli.c - src/core/lib/http/parser.c @@ -422,7 +426,6 @@ filegroups: uses: - grpc_codegen - grpc_trace - - grpc_stats - name: grpc_client_channel headers: - src/core/ext/filters/client_channel/client_channel.h @@ -680,15 +683,6 @@ filegroups: - src/core/ext/filters/workarounds/workaround_utils.c uses: - grpc_base -- name: grpc_stats - headers: - - src/core/lib/debug/stats.h - - src/core/lib/debug/stats_data.h - src: - - src/core/lib/debug/stats.c - - src/core/lib/debug/stats_data.c - deps: - - gpr - name: grpc_test_util_base build: test headers: diff --git a/config.m4 b/config.m4 index 9e43a78be5..0f1253bdc1 100644 --- a/config.m4 +++ b/config.m4 @@ -96,6 +96,8 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/compression/compression.c \ src/core/lib/compression/message_compress.c \ src/core/lib/compression/stream_compression.c \ + src/core/lib/debug/stats.c \ + src/core/lib/debug/stats_data.c \ src/core/lib/http/format_request.c \ src/core/lib/http/httpcli.c \ src/core/lib/http/parser.c \ @@ -212,8 +214,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ src/core/lib/debug/trace.c \ - src/core/lib/debug/stats.c \ - src/core/lib/debug/stats_data.c \ src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c \ src/core/ext/transport/chttp2/transport/bin_decoder.c \ src/core/ext/transport/chttp2/transport/bin_encoder.c \ diff --git a/config.w32 b/config.w32 index 2dd3b4d3de..86578ab057 100644 --- a/config.w32 +++ b/config.w32 @@ -73,6 +73,8 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\compression\\compression.c " + "src\\core\\lib\\compression\\message_compress.c " + "src\\core\\lib\\compression\\stream_compression.c " + + "src\\core\\lib\\debug\\stats.c " + + "src\\core\\lib\\debug\\stats_data.c " + "src\\core\\lib\\http\\format_request.c " + "src\\core\\lib\\http\\httpcli.c " + "src\\core\\lib\\http\\parser.c " + @@ -189,8 +191,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\transport\\transport.c " + "src\\core\\lib\\transport\\transport_op_string.c " + "src\\core\\lib\\debug\\trace.c " + - "src\\core\\lib\\debug\\stats.c " + - "src\\core\\lib\\debug\\stats_data.c " + "src\\core\\ext\\transport\\chttp2\\server\\secure\\server_secure_chttp2.c " + "src\\core\\ext\\transport\\chttp2\\transport\\bin_decoder.c " + "src\\core\\ext\\transport\\chttp2\\transport\\bin_encoder.c " + diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 4135c6522e..0c3d1f914d 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -255,6 +255,8 @@ Pod::Spec.new do |s| 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/message_compress.h', 'src/core/lib/compression/stream_compression.h', + 'src/core/lib/debug/stats.h', + 'src/core/lib/debug/stats_data.h', 'src/core/lib/http/format_request.h', 'src/core/lib/http/httpcli.h', 'src/core/lib/http/parser.h', @@ -355,8 +357,6 @@ Pod::Spec.new do |s| 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', 'src/core/lib/debug/trace.h', - 'src/core/lib/debug/stats.h', - 'src/core/lib/debug/stats_data.h', 'src/core/ext/transport/chttp2/transport/bin_decoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h', @@ -472,6 +472,8 @@ Pod::Spec.new do |s| 'src/core/lib/compression/compression.c', 'src/core/lib/compression/message_compress.c', 'src/core/lib/compression/stream_compression.c', + 'src/core/lib/debug/stats.c', + 'src/core/lib/debug/stats_data.c', 'src/core/lib/http/format_request.c', 'src/core/lib/http/httpcli.c', 'src/core/lib/http/parser.c', @@ -588,8 +590,6 @@ Pod::Spec.new do |s| 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', 'src/core/lib/debug/trace.c', - 'src/core/lib/debug/stats.c', - 'src/core/lib/debug/stats_data.c', 'src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c', 'src/core/ext/transport/chttp2/transport/bin_decoder.c', 'src/core/ext/transport/chttp2/transport/bin_encoder.c', @@ -743,6 +743,8 @@ Pod::Spec.new do |s| 'src/core/lib/compression/algorithm_metadata.h', 'src/core/lib/compression/message_compress.h', 'src/core/lib/compression/stream_compression.h', + 'src/core/lib/debug/stats.h', + 'src/core/lib/debug/stats_data.h', 'src/core/lib/http/format_request.h', 'src/core/lib/http/httpcli.h', 'src/core/lib/http/parser.h', @@ -843,8 +845,6 @@ Pod::Spec.new do |s| 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', 'src/core/lib/debug/trace.h', - 'src/core/lib/debug/stats.h', - 'src/core/lib/debug/stats_data.h', 'src/core/ext/transport/chttp2/transport/bin_decoder.h', 'src/core/ext/transport/chttp2/transport/bin_encoder.h', 'src/core/ext/transport/chttp2/transport/chttp2_transport.h', diff --git a/grpc.gemspec b/grpc.gemspec index 9c4badb5a6..21d02219cb 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -187,6 +187,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/compression/algorithm_metadata.h ) s.files += %w( src/core/lib/compression/message_compress.h ) s.files += %w( src/core/lib/compression/stream_compression.h ) + s.files += %w( src/core/lib/debug/stats.h ) + s.files += %w( src/core/lib/debug/stats_data.h ) s.files += %w( src/core/lib/http/format_request.h ) s.files += %w( src/core/lib/http/httpcli.h ) s.files += %w( src/core/lib/http/parser.h ) @@ -287,8 +289,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/transport.h ) s.files += %w( src/core/lib/transport/transport_impl.h ) s.files += %w( src/core/lib/debug/trace.h ) - s.files += %w( src/core/lib/debug/stats.h ) - s.files += %w( src/core/lib/debug/stats_data.h ) s.files += %w( src/core/ext/transport/chttp2/transport/bin_decoder.h ) s.files += %w( src/core/ext/transport/chttp2/transport/bin_encoder.h ) s.files += %w( src/core/ext/transport/chttp2/transport/chttp2_transport.h ) @@ -408,6 +408,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/compression/compression.c ) s.files += %w( src/core/lib/compression/message_compress.c ) s.files += %w( src/core/lib/compression/stream_compression.c ) + s.files += %w( src/core/lib/debug/stats.c ) + s.files += %w( src/core/lib/debug/stats_data.c ) s.files += %w( src/core/lib/http/format_request.c ) s.files += %w( src/core/lib/http/httpcli.c ) s.files += %w( src/core/lib/http/parser.c ) @@ -524,8 +526,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/transport.c ) s.files += %w( src/core/lib/transport/transport_op_string.c ) s.files += %w( src/core/lib/debug/trace.c ) - s.files += %w( src/core/lib/debug/stats.c ) - s.files += %w( src/core/lib/debug/stats_data.c ) s.files += %w( src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c ) s.files += %w( src/core/ext/transport/chttp2/transport/bin_decoder.c ) s.files += %w( src/core/ext/transport/chttp2/transport/bin_encoder.c ) diff --git a/package.xml b/package.xml index ded7ffc52b..b9b9f21572 100644 --- a/package.xml +++ b/package.xml @@ -201,6 +201,8 @@ + + @@ -301,8 +303,6 @@ - - @@ -422,6 +422,8 @@ + + @@ -538,8 +540,6 @@ - - diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 1f3a8c8a63..41b7e7dc74 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -72,6 +72,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/compression/compression.c', 'src/core/lib/compression/message_compress.c', 'src/core/lib/compression/stream_compression.c', + 'src/core/lib/debug/stats.c', + 'src/core/lib/debug/stats_data.c', 'src/core/lib/http/format_request.c', 'src/core/lib/http/httpcli.c', 'src/core/lib/http/parser.c', @@ -188,8 +190,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', 'src/core/lib/debug/trace.c', - 'src/core/lib/debug/stats.c', - 'src/core/lib/debug/stats_data.c', 'src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c', 'src/core/ext/transport/chttp2/transport/bin_decoder.c', 'src/core/ext/transport/chttp2/transport/bin_encoder.c', diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 0c10d6c4ce..415d27445f 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -29,6 +29,13 @@ void TrackCounters::Finish(benchmark::State &state) { } void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { + grpc_stats_data stats_end; + grpc_stats_collect(&stats_end); + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + out << " " << grpc_stats_counter_name[i] << "/iter:" + << ((double)(stats_end.counters[i] - stats_begin_.counters[i]) / + (double)state.iterations()); + } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); out << " locks/iter:" << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) - diff --git a/test/cpp/microbenchmarks/helpers.h b/test/cpp/microbenchmarks/helpers.h index c81d95a4ea..07dd611709 100644 --- a/test/cpp/microbenchmarks/helpers.h +++ b/test/cpp/microbenchmarks/helpers.h @@ -23,6 +23,7 @@ extern "C" { #include +#include "src/core/lib/debug/stats.h" #include "test/core/util/memory_counters.h" } @@ -62,10 +63,12 @@ extern "C" gpr_atm gpr_now_call_count; class TrackCounters { public: + TrackCounters() { grpc_stats_collect(&stats_begin_); } virtual void Finish(benchmark::State& state); virtual void AddToLabel(std::ostream& out, benchmark::State& state); private: + grpc_stats_data stats_begin_; #ifdef GPR_LOW_LEVEL_COUNTERS const size_t mu_locks_at_start_ = gpr_atm_no_barrier_load(&gpr_mu_locks); const size_t atm_cas_at_start_ = diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index bdad9e9d01..b0dbc0da89 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7691,7 +7691,6 @@ "deps": [ "gpr", "grpc_codegen", - "grpc_stats", "grpc_trace" ], "headers": [ @@ -7717,6 +7716,8 @@ "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/message_compress.h", "src/core/lib/compression/stream_compression.h", + "src/core/lib/debug/stats.h", + "src/core/lib/debug/stats_data.h", "src/core/lib/http/format_request.h", "src/core/lib/http/httpcli.h", "src/core/lib/http/parser.h", @@ -7853,6 +7854,10 @@ "src/core/lib/compression/message_compress.h", "src/core/lib/compression/stream_compression.c", "src/core/lib/compression/stream_compression.h", + "src/core/lib/debug/stats.c", + "src/core/lib/debug/stats.h", + "src/core/lib/debug/stats_data.c", + "src/core/lib/debug/stats_data.h", "src/core/lib/http/format_request.c", "src/core/lib/http/format_request.h", "src/core/lib/http/httpcli.c", @@ -8552,26 +8557,6 @@ "third_party": false, "type": "filegroup" }, - { - "deps": [ - "gpr" - ], - "headers": [ - "src/core/lib/debug/stats.h", - "src/core/lib/debug/stats_data.h" - ], - "is_filegroup": true, - "language": "c", - "name": "grpc_stats", - "src": [ - "src/core/lib/debug/stats.c", - "src/core/lib/debug/stats.h", - "src/core/lib/debug/stats_data.c", - "src/core/lib/debug/stats_data.h" - ], - "third_party": false, - "type": "filegroup" - }, { "deps": [ "gpr_test_util", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 6ffb0ac084..6376fd5ad2 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -312,6 +312,8 @@ + + @@ -412,8 +414,6 @@ - - @@ -546,6 +546,10 @@ + + + + @@ -778,10 +782,6 @@ - - - - diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index ea58322a65..9335e1deb8 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -34,6 +34,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -382,12 +388,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - src\core\ext\transport\chttp2\server\secure @@ -899,6 +899,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -1199,12 +1205,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - src\core\ext\transport\chttp2\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 4ba0ef78cf..08abb31a00 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -207,6 +207,8 @@ + + @@ -307,8 +309,6 @@ - - @@ -371,6 +371,10 @@ + + + + @@ -603,10 +607,6 @@ - - - - diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index fa2a6e3545..b4a934986e 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -91,6 +91,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -439,12 +445,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - @@ -623,6 +623,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -923,12 +929,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 7684ed42e2..2ba8917fdd 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -302,6 +302,8 @@ + + @@ -402,8 +404,6 @@ - - @@ -512,6 +512,10 @@ + + + + @@ -744,10 +748,6 @@ - - - - diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 93f68e5698..53cce0aa0f 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -37,6 +37,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -385,12 +391,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - src\core\ext\transport\chttp2\server\insecure @@ -806,6 +806,12 @@ src\core\lib\compression + + src\core\lib\debug + + + src\core\lib\debug + src\core\lib\http @@ -1106,12 +1112,6 @@ src\core\lib\debug - - src\core\lib\debug - - - src\core\lib\debug - src\core\ext\transport\chttp2\transport -- cgit v1.2.3 From b4bb1cdce48abb7492b33cd2dced14689da67e2b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Jul 2017 14:18:17 -0700 Subject: Add counters, fix race --- src/core/lib/debug/stats_data.c | 3 ++- src/core/lib/debug/stats_data.h | 12 ++++++++++++ src/core/lib/debug/stats_data.yaml | 4 ++++ src/core/lib/iomgr/ev_epoll1_linux.c | 2 ++ src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c | 3 +++ src/core/lib/iomgr/ev_epoll_thread_pool_linux.c | 2 ++ src/core/lib/iomgr/ev_epollex_linux.c | 2 ++ src/core/lib/iomgr/ev_epollsig_linux.c | 2 ++ src/core/lib/iomgr/ev_poll_posix.c | 2 ++ src/core/lib/iomgr/iocp_windows.c | 2 ++ src/core/lib/iomgr/tcp_posix.c | 10 +++++++--- test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 2 ++ 12 files changed, 42 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index e3ffb5aa34..2203358a7e 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -20,5 +20,6 @@ #include "src/core/lib/debug/stats_data.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { - "client_calls_created", "server_calls_created", + "client_calls_created", "server_calls_created", "syscall_write", + "syscall_read", "syscall_poll", "syscall_wait", }; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 212620daa2..c9c2f65c30 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -24,12 +24,24 @@ typedef enum { GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, GRPC_STATS_COUNTER_SERVER_CALLS_CREATED, + GRPC_STATS_COUNTER_SYSCALL_WRITE, + GRPC_STATS_COUNTER_SYSCALL_READ, + GRPC_STATS_COUNTER_SYSCALL_POLL, + GRPC_STATS_COUNTER_SYSCALL_WAIT, GRPC_STATS_COUNTER_COUNT } grpc_stats_counters; #define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) #define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) +#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) +#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 3347d9c8ae..8afe48f5cd 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -3,3 +3,7 @@ - counter: client_calls_created - counter: server_calls_created +- counter: syscall_write +- counter: syscall_read +- counter: syscall_poll +- counter: syscall_wait diff --git a/src/core/lib/iomgr/ev_epoll1_linux.c b/src/core/lib/iomgr/ev_epoll1_linux.c index 66ba601adb..532d2887ed 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.c +++ b/src/core/lib/iomgr/ev_epoll1_linux.c @@ -39,6 +39,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/lockfree_event.h" @@ -474,6 +475,7 @@ static grpc_error *pollset_epoll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, } int r; do { + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = epoll_wait(g_epfd, events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { diff --git a/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c b/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c index 27b4892d1d..5f293a74eb 100644 --- a/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +++ b/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c @@ -40,6 +40,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" @@ -1307,6 +1308,7 @@ static bool acquire_polling_lease(grpc_pollset_worker *worker, } else { struct timespec sigwait_timeout = millis_to_timespec(timeout_ms); GRPC_SCHEDULING_START_BLOCKING_REGION; + GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx); ret = sigtimedwait(&g_wakeup_sig_set, NULL, &sigwait_timeout); GRPC_SCHEDULING_END_BLOCKING_REGION; } @@ -1392,6 +1394,7 @@ static void pollset_do_epoll_pwait(grpc_exec_ctx *exec_ctx, int epoll_fd, int timeout_ms = poll_deadline_to_millis_timeout(deadline, now); GRPC_SCHEDULING_START_BLOCKING_REGION; + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms, sig_mask); GRPC_SCHEDULING_END_BLOCKING_REGION; diff --git a/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c b/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c index 49be72c03e..a307c4e709 100644 --- a/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +++ b/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c @@ -41,6 +41,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/lockfree_event.h" @@ -776,6 +777,7 @@ static void do_epoll_wait(grpc_exec_ctx *exec_ctx, int epoll_fd, epoll_set *eps, GRPC_SCHEDULING_START_BLOCKING_REGION; acquire_epoll_lease(eps); + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); ep_rv = epoll_wait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms); release_epoll_lease(eps); GRPC_SCHEDULING_END_BLOCKING_REGION; diff --git a/src/core/lib/iomgr/ev_epollex_linux.c b/src/core/lib/iomgr/ev_epollex_linux.c index 5690431759..3560e5de30 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.c +++ b/src/core/lib/iomgr/ev_epollex_linux.c @@ -37,6 +37,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/is_epollexclusive_available.h" @@ -814,6 +815,7 @@ static grpc_error *pollset_epoll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, } int r; do { + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = epoll_wait(p->epfd, pollset->events, MAX_EPOLL_EVENTS, timeout); } while (r < 0 && errno == EINTR); if (timeout != 0) { diff --git a/src/core/lib/iomgr/ev_epollsig_linux.c b/src/core/lib/iomgr/ev_epollsig_linux.c index 0d969dccce..d278d34092 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.c +++ b/src/core/lib/iomgr/ev_epollsig_linux.c @@ -39,6 +39,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/lockfree_event.h" @@ -1237,6 +1238,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx *exec_ctx, g_current_thread_polling_island = pi; GRPC_SCHEDULING_START_BLOCKING_REGION; + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); ep_rv = epoll_pwait(epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, timeout_ms, sig_mask); GRPC_SCHEDULING_END_BLOCKING_REGION; diff --git a/src/core/lib/iomgr/ev_poll_posix.c b/src/core/lib/iomgr/ev_poll_posix.c index 1f8d7eef26..e1d758ec00 100644 --- a/src/core/lib/iomgr/ev_poll_posix.c +++ b/src/core/lib/iomgr/ev_poll_posix.c @@ -36,6 +36,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/wakeup_fd_cv.h" @@ -958,6 +959,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, /* TODO(vpai): Consider first doing a 0 timeout poll here to avoid even going into the blocking annotation if possible */ GRPC_SCHEDULING_START_BLOCKING_REGION; + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); r = grpc_poll_function(pfds, pfd_count, timeout); GRPC_SCHEDULING_END_BLOCKING_REGION; diff --git a/src/core/lib/iomgr/iocp_windows.c b/src/core/lib/iomgr/iocp_windows.c index e343f8a794..c082179c0b 100644 --- a/src/core/lib/iomgr/iocp_windows.c +++ b/src/core/lib/iomgr/iocp_windows.c @@ -27,6 +27,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/socket_windows.h" @@ -65,6 +66,7 @@ grpc_iocp_work_status grpc_iocp_work(grpc_exec_ctx *exec_ctx, LPOVERLAPPED overlapped; grpc_winsocket *socket; grpc_winsocket_callback_info *info; + GRPC_STATS_INC_SYSCALL_POLL(exec_ctx); success = GetQueuedCompletionStatus( g_iocp, &bytes, &completion_key, &overlapped, deadline_to_millis_timeout(deadline, gpr_now(deadline.clock_type))); diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index b6dcd15cb0..668f6bb447 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -40,6 +40,7 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/debug/stats.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/profiling/timers.h" @@ -258,6 +259,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { GPR_TIMER_BEGIN("recvmsg", 0); do { + GRPC_STATS_INC_SYSCALL_READ(exec_ctx); read_bytes = recvmsg(tcp->fd, &msg, 0); } while (read_bytes < 0 && errno == EINTR); GPR_TIMER_END("recvmsg", read_bytes >= 0); @@ -361,7 +363,8 @@ static void tcp_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, /* returns true if done, false if pending; if returning true, *error is set */ #define MAX_WRITE_IOVEC 1000 -static bool tcp_flush(grpc_tcp *tcp, grpc_error **error) { +static bool tcp_flush(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, + grpc_error **error) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; msg_iovlen_type iov_size; @@ -403,6 +406,7 @@ static bool tcp_flush(grpc_tcp *tcp, grpc_error **error) { GPR_TIMER_BEGIN("sendmsg", 1); do { /* TODO(klempner): Cork if this is a partial write */ + GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx); sent_length = sendmsg(tcp->fd, &msg, SENDMSG_FLAGS); } while (sent_length < 0 && errno == EINTR); GPR_TIMER_END("sendmsg", 0); @@ -459,7 +463,7 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */, return; } - if (!tcp_flush(tcp, &error)) { + if (!tcp_flush(exec_ctx, tcp, &error)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) { gpr_log(GPR_DEBUG, "write: delayed"); } @@ -510,7 +514,7 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, tcp->outgoing_slice_idx = 0; tcp->outgoing_byte_idx = 0; - if (!tcp_flush(tcp, &error)) { + if (!tcp_flush(exec_ctx, tcp, &error)) { TCP_REF(tcp, "write"); tcp->write_cb = cb; if (GRPC_TRACER_ON(grpc_tcp_trace)) { diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index f79db15a47..645af009bb 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -38,6 +38,8 @@ struct grpc_pollset { namespace grpc { namespace testing { +auto& force_library_initialization = Library::get(); + static void* g_tag = (void*)(intptr_t)10; // Some random number static grpc_completion_queue* g_cq; static grpc_event_engine_vtable g_vtable; -- cgit v1.2.3 From 567e0f1eb62f361f845d5aba7f7b502e98d5b9d6 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Tue, 29 Aug 2017 09:21:22 -0700 Subject: Have write ops take ownership over slices --- include/grpc++/impl/codegen/call.h | 12 ++++++++---- include/grpc++/impl/codegen/core_codegen.h | 1 + include/grpc++/impl/codegen/core_codegen_interface.h | 1 + src/core/lib/transport/byte_stream.c | 1 + src/cpp/common/core_codegen.cc | 4 ++++ test/core/end2end/tests/resource_quota_server.c | 11 ++++++----- 6 files changed, 21 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 0cb11b4cca..3c30ccdb1e 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -272,7 +272,7 @@ class CallOpSendInitialMetadata { class CallOpSendMessage { public: - CallOpSendMessage() : send_buf_(nullptr), own_buf_(false) {} + CallOpSendMessage() : send_buf_(nullptr) {} /// Send \a message using \a options for the write. The \a options are cleared /// after use. @@ -295,20 +295,24 @@ class CallOpSendMessage { write_options_.Clear(); } void FinishOp(bool* status) { - if (own_buf_) g_core_codegen_interface->grpc_byte_buffer_destroy(send_buf_); + g_core_codegen_interface->grpc_byte_buffer_destroy(send_buf_); send_buf_ = nullptr; } private: grpc_byte_buffer* send_buf_; WriteOptions write_options_; - bool own_buf_; }; template Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { write_options_ = options; - return SerializationTraits::Serialize(message, &send_buf_, &own_buf_); + bool own_buf; + Status result = SerializationTraits::Serialize(message, &send_buf_, &own_buf); + if (!own_buf) { + send_buf_ = g_core_codegen_interface->grpc_byte_buffer_copy(send_buf_); + } + return result; } template diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index 2b15a01845..5f96c8345b 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -68,6 +68,7 @@ class CoreCodegen final : public CoreCodegenInterface { void grpc_call_unref(grpc_call* call) override; virtual void* grpc_call_arena_alloc(grpc_call* call, size_t length) override; + grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) override; void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override; int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h index b4c771ac93..7556016f27 100644 --- a/include/grpc++/impl/codegen/core_codegen_interface.h +++ b/include/grpc++/impl/codegen/core_codegen_interface.h @@ -74,6 +74,7 @@ class CoreCodegenInterface { virtual void gpr_cv_signal(gpr_cv* cv) = 0; virtual void gpr_cv_broadcast(gpr_cv* cv) = 0; + virtual grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) = 0; virtual void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) = 0; virtual int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader, diff --git a/src/core/lib/transport/byte_stream.c b/src/core/lib/transport/byte_stream.c index fb03a10315..08f61629a9 100644 --- a/src/core/lib/transport/byte_stream.c +++ b/src/core/lib/transport/byte_stream.c @@ -85,6 +85,7 @@ static void slice_buffer_stream_shutdown(grpc_exec_ctx *exec_ctx, static void slice_buffer_stream_destroy(grpc_exec_ctx *exec_ctx, grpc_byte_stream *byte_stream) { grpc_slice_buffer_stream *stream = (grpc_slice_buffer_stream *)byte_stream; + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, stream->backing_buffer); GRPC_ERROR_UNREF(stream->shutdown_error); } diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index c7c6b6b13b..e81509904f 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -89,6 +89,10 @@ int CoreCodegen::gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, void CoreCodegen::gpr_cv_signal(gpr_cv* cv) { ::gpr_cv_signal(cv); } void CoreCodegen::gpr_cv_broadcast(gpr_cv* cv) { ::gpr_cv_broadcast(cv); } +grpc_byte_buffer* CoreCodegen::grpc_byte_buffer_copy(grpc_byte_buffer *bb) { + return ::grpc_byte_buffer_copy(bb); +} + void CoreCodegen::grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { ::grpc_byte_buffer_destroy(bb); } diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c index 010e20c4c2..34a6a80a31 100644 --- a/test/core/end2end/tests/resource_quota_server.c +++ b/test/core/end2end/tests/resource_quota_server.c @@ -143,6 +143,8 @@ void resource_quota_server(grpc_end2end_test_config config) { malloc(sizeof(grpc_call_details) * NUM_CALLS); grpc_status_code *status = malloc(sizeof(grpc_status_code) * NUM_CALLS); grpc_slice *details = malloc(sizeof(grpc_slice) * NUM_CALLS); + grpc_byte_buffer **request_payload = + malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS); grpc_byte_buffer **request_payload_recv = malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS); int *was_cancelled = malloc(sizeof(int) * NUM_CALLS); @@ -156,9 +158,6 @@ void resource_quota_server(grpc_end2end_test_config config) { int deadline_exceeded = 0; int unavailable = 0; - grpc_byte_buffer *request_payload = - grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_op ops[6]; grpc_op *op; @@ -167,6 +166,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_init(&trailing_metadata_recv[i]); grpc_metadata_array_init(&request_metadata_recv[i]); grpc_call_details_init(&call_details[i]); + request_payload[i] = grpc_raw_byte_buffer_create(&request_payload_slice, 1); request_payload_recv[i] = NULL; was_cancelled[i] = 0; } @@ -195,7 +195,7 @@ void resource_quota_server(grpc_end2end_test_config config) { op->reserved = NULL; op++; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message.send_message = request_payload; + op->data.send_message.send_message = request_payload[i]; op->flags = 0; op->reserved = NULL; op++; @@ -261,6 +261,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_destroy(&trailing_metadata_recv[call_id]); grpc_call_unref(client_calls[call_id]); grpc_slice_unref(details[call_id]); + grpc_byte_buffer_destroy(request_payload[call_id]); pending_client_calls--; } else if (ev_tag < SERVER_RECV_BASE_TAG) { @@ -351,7 +352,6 @@ void resource_quota_server(grpc_end2end_test_config config) { NUM_CALLS, cancelled_calls_on_server, cancelled_calls_on_client, deadline_exceeded, unavailable); - grpc_byte_buffer_destroy(request_payload); grpc_slice_unref(request_payload_slice); grpc_resource_quota_unref(resource_quota); @@ -366,6 +366,7 @@ void resource_quota_server(grpc_end2end_test_config config) { free(call_details); free(status); free(details); + free(request_payload); free(request_payload_recv); free(was_cancelled); } -- cgit v1.2.3 From 951971881165fad65f99f7b0ca821eea0ce25d23 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Tue, 29 Aug 2017 11:31:00 -0700 Subject: Documentation change + e2e test fix --- src/core/lib/transport/byte_stream.h | 4 +++- test/core/end2end/tests/cancel_after_round_trip.c | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/src/core/lib/transport/byte_stream.h b/src/core/lib/transport/byte_stream.h index 1e1e8310b8..be2a35213e 100644 --- a/src/core/lib/transport/byte_stream.h +++ b/src/core/lib/transport/byte_stream.h @@ -81,7 +81,9 @@ void grpc_byte_stream_destroy(grpc_exec_ctx *exec_ctx, // grpc_slice_buffer_stream // -// A grpc_byte_stream that wraps a slice buffer. +// A grpc_byte_stream that wraps a slice buffer. The stream takes +// ownership of the slices in the buffer, and on destruction will +// reset the contents of the buffer. typedef struct grpc_slice_buffer_stream { grpc_byte_stream base; diff --git a/test/core/end2end/tests/cancel_after_round_trip.c b/test/core/end2end/tests/cancel_after_round_trip.c index 0fc8b95ef7..ad24b4e538 100644 --- a/test/core/end2end/tests/cancel_after_round_trip.c +++ b/test/core/end2end/tests/cancel_after_round_trip.c @@ -114,7 +114,9 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_slice_from_copied_string("hello you"); grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - grpc_byte_buffer *response_payload = + grpc_byte_buffer *response_payload1 = + grpc_raw_byte_buffer_create(&response_payload_slice, 1); + grpc_byte_buffer *response_payload2 = grpc_raw_byte_buffer_create(&response_payload_slice, 1); int was_cancelled = 2; @@ -199,7 +201,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->reserved = NULL; op++; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message.send_message = response_payload; + op->data.send_message.send_message = response_payload1; op->flags = 0; op->reserved = NULL; op++; @@ -242,7 +244,7 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, op->reserved = NULL; op++; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message.send_message = response_payload; + op->data.send_message.send_message = response_payload2; op->flags = 0; op->reserved = NULL; op++; @@ -262,7 +264,8 @@ static void test_cancel_after_round_trip(grpc_end2end_test_config config, grpc_call_details_destroy(&call_details); grpc_byte_buffer_destroy(request_payload); - grpc_byte_buffer_destroy(response_payload); + grpc_byte_buffer_destroy(response_payload1); + grpc_byte_buffer_destroy(response_payload2); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); grpc_slice_unref(details); -- cgit v1.2.3 From a0116f36ec3980f39d16b173ed61cc48f47ccbcf Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Aug 2017 09:40:08 -0700 Subject: Fix crash --- test/core/iomgr/ev_epollsig_linux_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/core/iomgr/ev_epollsig_linux_test.c b/test/core/iomgr/ev_epollsig_linux_test.c index c702065d4d..cca07bf002 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.c +++ b/test/core/iomgr/ev_epollsig_linux_test.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -308,9 +309,8 @@ static void test_threading(void) { int main(int argc, char **argv) { const char *poll_strategy = NULL; grpc_test_init(argc, argv); + grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_iomgr_init(&exec_ctx); - grpc_iomgr_start(&exec_ctx); poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epollsig") == 0) { @@ -323,8 +323,8 @@ int main(int argc, char **argv) { poll_strategy); } - grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); return 0; } #else /* defined(GRPC_LINUX_EPOLL) */ -- cgit v1.2.3 From 413e95b8ed8eda45b28d2f81835d5777097b8259 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Aug 2017 09:41:41 -0700 Subject: Fix crash --- test/core/iomgr/fd_posix_test.c | 6 +++--- test/core/iomgr/resolve_address_posix_test.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 85d5d9c07f..5791d17af6 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -530,8 +531,7 @@ int main(int argc, char **argv) { grpc_closure destroyed; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); - grpc_iomgr_init(&exec_ctx); - grpc_iomgr_start(&exec_ctx); + grpc_init(); g_pollset = gpr_zalloc(grpc_pollset_size()); grpc_pollset_init(g_pollset, &g_mu); test_grpc_fd(); @@ -541,8 +541,8 @@ int main(int argc, char **argv) { grpc_pollset_shutdown(&exec_ctx, g_pollset, &destroyed); grpc_exec_ctx_flush(&exec_ctx); gpr_free(g_pollset); - grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); return 0; } diff --git a/test/core/iomgr/resolve_address_posix_test.c b/test/core/iomgr/resolve_address_posix_test.c index 9cc09ed5d3..e4be99f03c 100644 --- a/test/core/iomgr/resolve_address_posix_test.c +++ b/test/core/iomgr/resolve_address_posix_test.c @@ -21,12 +21,14 @@ #include #include +#include #include #include #include #include #include #include + #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/iomgr.h" #include "test/core/util/test_config.h" @@ -159,13 +161,12 @@ static void test_unix_socket_path_name_too_long(void) { int main(int argc, char **argv) { grpc_test_init(argc, argv); + grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_iomgr_init(&exec_ctx); - grpc_iomgr_start(&exec_ctx); test_unix_socket(); test_unix_socket_path_name_too_long(); grpc_executor_shutdown(&exec_ctx); - grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); return 0; } -- cgit v1.2.3 From bcf6ca8d498c7f729aa164067b34d8f465b56084 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Aug 2017 12:56:57 -0700 Subject: Fix crash --- test/core/iomgr/resolve_address_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c index cb156ee61e..7f5c4073d8 100644 --- a/test/core/iomgr/resolve_address_test.c +++ b/test/core/iomgr/resolve_address_test.c @@ -17,6 +17,7 @@ */ #include "src/core/lib/iomgr/resolve_address.h" +#include #include #include #include @@ -250,9 +251,8 @@ static void test_unparseable_hostports(void) { int main(int argc, char **argv) { grpc_test_init(argc, argv); + grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_iomgr_init(&exec_ctx); - grpc_iomgr_start(&exec_ctx); test_localhost(); test_default_port(); test_non_numeric_default_port(); @@ -262,7 +262,7 @@ int main(int argc, char **argv) { test_invalid_ip_addresses(); test_unparseable_hostports(); grpc_executor_shutdown(&exec_ctx); - grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); return 0; } -- cgit v1.2.3