From cdbdedbf23203c5edae587fb42168eb3e2cdd3f3 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 18 May 2015 17:28:52 -0700 Subject: Refactored benchmark reporting mechanism. It now allows pluggging in "reporter" instances to process the benchmark results arbitrarily. This would allow, for example, to send results to a leaderboard and/or other systems for tracking performance metrics. --- test/cpp/qps/qps_driver.cc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'test/cpp/qps/qps_driver.cc') diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc index fc8e04201c..3aa215b448 100644 --- a/test/cpp/qps/qps_driver.cc +++ b/test/cpp/qps/qps_driver.cc @@ -31,6 +31,8 @@ * */ +#include + #include #include @@ -67,10 +69,17 @@ using grpc::testing::ClientType; using grpc::testing::ServerType; using grpc::testing::RpcType; using grpc::testing::ResourceUsage; +using grpc::testing::ReportersRegistry; +using grpc::testing::GprLogReporter; +using grpc::testing::ReportData; +using grpc::testing::ReportType; int main(int argc, char** argv) { grpc::testing::InitTest(&argc, &argv, true); + ReportersRegistry reporters_registry; + reporters_registry.Register(new GprLogReporter("LogReporter")); + RpcType rpc_type; GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type)); @@ -103,14 +112,13 @@ int main(int argc, char** argv) { FLAGS_server_threads < FLAGS_client_channels * FLAGS_outstanding_rpcs_per_channel)); - auto result = RunScenario(client_config, FLAGS_num_clients, - server_config, FLAGS_num_servers, - FLAGS_warmup_seconds, FLAGS_benchmark_seconds, - FLAGS_local_workers); + const auto result = RunScenario( + client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, + FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers); - ReportQPSPerCore(result, server_config); - ReportLatency(result); - ReportTimes(result); + std::set types; + types.insert(grpc::testing::ReportType::REPORT_ALL); + reporters_registry.Report({client_config, server_config, result}, types); return 0; } -- cgit v1.2.3 From 3cc9ec92d90cf24603ee556da2d8b188428e2615 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 18 May 2015 22:33:02 -0700 Subject: Removed registry for benchmark reports & introduced benchmark_config.{h,cc} in the spirit of test_config.{h,cc}. The purpose of benchmark_config is to allow for different behaviors to be decided at compile-time. --- Makefile | 85 ++++++++++++++++++++------ build.json | 16 ++++- test/cpp/qps/async_streaming_ping_pong_test.cc | 17 +++--- test/cpp/qps/async_unary_ping_pong_test.cc | 16 ++--- test/cpp/qps/qps_driver.cc | 30 ++++++--- test/cpp/qps/qps_test.cc | 16 ++--- test/cpp/qps/report.cc | 20 ------ test/cpp/qps/report.h | 24 -------- test/cpp/qps/sync_streaming_ping_pong_test.cc | 18 +++--- test/cpp/qps/sync_unary_ping_pong_test.cc | 13 +++- 10 files changed, 149 insertions(+), 106 deletions(-) (limited to 'test/cpp/qps/qps_driver.cc') diff --git a/Makefile b/Makefile index a17dc63e60..6017455a4a 100644 --- a/Makefile +++ b/Makefile @@ -1153,7 +1153,7 @@ privatelibs: privatelibs_c privatelibs_cxx privatelibs_c: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fake_security.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fullstack_uds_posix.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_simple_ssl_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_simple_ssl_with_oauth2_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_socket_pair.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_socket_pair_one_byte_at_a_time.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_socket_pair_with_grpc_trace.a $(LIBDIR)/$(CONFIG)/libend2end_test_bad_hostname.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept_and_writes_closed.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_invoke.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_before_invoke.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_in_a_vacuum.a $(LIBDIR)/$(CONFIG)/libend2end_test_census_simple_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_disappearing_server.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_inflight_calls.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_tags.a $(LIBDIR)/$(CONFIG)/libend2end_test_empty_batch.a $(LIBDIR)/$(CONFIG)/libend2end_test_graceful_server_shutdown.a $(LIBDIR)/$(CONFIG)/libend2end_test_invoke_large_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_max_concurrent_streams.a $(LIBDIR)/$(CONFIG)/libend2end_test_max_message_length.a $(LIBDIR)/$(CONFIG)/libend2end_test_no_op.a $(LIBDIR)/$(CONFIG)/libend2end_test_ping_pong_streaming.a $(LIBDIR)/$(CONFIG)/libend2end_test_registered_call.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_binary_metadata_and_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_metadata_and_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_payload_and_call_creds.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_trailing_metadata_and_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_large_metadata.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_server_finishes_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_delayed_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_request_with_high_initial_sequence_number.a $(LIBDIR)/$(CONFIG)/libend2end_certs.a -privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a +privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a buildtests: buildtests_c buildtests_cxx @@ -3198,6 +3198,53 @@ endif endif +LIBGRPC++_BENCHMARK_CONFIG_SRC = \ + test/cpp/util/benchmark_config.cc \ + + +LIBGRPC++_BENCHMARK_CONFIG_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_BENCHMARK_CONFIG_SRC)))) + +ifeq ($(NO_SECURE),true) + +# You can't build secure libraries if you don't have OpenSSL with ALPN. + +$(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a: openssl_dep_error + + +else + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(PROTOBUF_DEP) $(LIBGRPC++_BENCHMARK_CONFIG_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a + $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBGRPC++_BENCHMARK_CONFIG_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a +endif + + + + +endif + +endif + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(LIBGRPC++_BENCHMARK_CONFIG_OBJS:.o=.dep) +endif +endif + + LIBGRPC++_TEST_CONFIG_SRC = \ test/cpp/util/test_config.cc \ @@ -7069,16 +7116,16 @@ $(BINDIR)/$(CONFIG)/async_streaming_ping_pong_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/async_streaming_ping_pong_test: $(PROTOBUF_DEP) $(ASYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/async_streaming_ping_pong_test: $(PROTOBUF_DEP) $(ASYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_streaming_ping_pong_test + $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_streaming_ping_pong_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/async_streaming_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/async_streaming_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_async_streaming_ping_pong_test: $(ASYNC_STREAMING_PING_PONG_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) @@ -7109,16 +7156,16 @@ $(BINDIR)/$(CONFIG)/async_unary_ping_pong_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/async_unary_ping_pong_test: $(PROTOBUF_DEP) $(ASYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/async_unary_ping_pong_test: $(PROTOBUF_DEP) $(ASYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_unary_ping_pong_test + $(Q) $(LDXX) $(LDFLAGS) $(ASYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/async_unary_ping_pong_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/async_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/async_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_async_unary_ping_pong_test: $(ASYNC_UNARY_PING_PONG_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) @@ -7827,16 +7874,16 @@ $(BINDIR)/$(CONFIG)/qps_driver: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/qps_driver: $(PROTOBUF_DEP) $(QPS_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/qps_driver: $(PROTOBUF_DEP) $(QPS_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(QPS_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_driver + $(Q) $(LDXX) $(LDFLAGS) $(QPS_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_driver endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_driver.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_driver.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a deps_qps_driver: $(QPS_DRIVER_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) @@ -7867,16 +7914,16 @@ $(BINDIR)/$(CONFIG)/qps_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/qps_test: $(PROTOBUF_DEP) $(QPS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/qps_test: $(PROTOBUF_DEP) $(QPS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(QPS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_test + $(Q) $(LDXX) $(LDFLAGS) $(QPS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_qps_test: $(QPS_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) @@ -7987,16 +8034,16 @@ $(BINDIR)/$(CONFIG)/sync_streaming_ping_pong_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/sync_streaming_ping_pong_test: $(PROTOBUF_DEP) $(SYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/sync_streaming_ping_pong_test: $(PROTOBUF_DEP) $(SYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(SYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/sync_streaming_ping_pong_test + $(Q) $(LDXX) $(LDFLAGS) $(SYNC_STREAMING_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/sync_streaming_ping_pong_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/sync_streaming_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/sync_streaming_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_sync_streaming_ping_pong_test: $(SYNC_STREAMING_PING_PONG_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) @@ -8027,16 +8074,16 @@ $(BINDIR)/$(CONFIG)/sync_unary_ping_pong_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/sync_unary_ping_pong_test: $(PROTOBUF_DEP) $(SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/sync_unary_ping_pong_test: $(PROTOBUF_DEP) $(SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/sync_unary_ping_pong_test + $(Q) $(LDXX) $(LDFLAGS) $(SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/sync_unary_ping_pong_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/sync_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/sync_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_benchmark_config.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_sync_unary_ping_pong_test: $(SYNC_UNARY_PING_PONG_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) diff --git a/build.json b/build.json index 8a7e65b99a..4952b890a9 100644 --- a/build.json +++ b/build.json @@ -525,6 +525,14 @@ "secure": "check", "vs_project_guid": "{C187A093-A0FE-489D-A40A-6E33DE0F9FEB}" }, + { + "name": "grpc++_benchmark_config", + "build": "private", + "language": "c++", + "src": [ + "test/cpp/util/benchmark_config.cc" + ] + }, { "name": "grpc++_test_config", "build": "private", @@ -1820,6 +1828,7 @@ "deps": [ "qps", "grpc++_test_util", + "grpc++_benchmark_config", "grpc_test_util", "grpc++", "grpc", @@ -1837,6 +1846,7 @@ "deps": [ "qps", "grpc++_test_util", + "grpc++_benchmark_config", "grpc_test_util", "grpc++", "grpc", @@ -2144,7 +2154,8 @@ "grpc", "gpr_test_util", "gpr", - "grpc++_test_config" + "grpc++_test_config", + "grpc++_benchmark_config" ] }, { @@ -2157,6 +2168,7 @@ "deps": [ "qps", "grpc++_test_util", + "grpc++_benchmark_config", "grpc_test_util", "grpc++", "grpc", @@ -2212,6 +2224,7 @@ "deps": [ "qps", "grpc++_test_util", + "grpc++_benchmark_config", "grpc_test_util", "grpc++", "grpc", @@ -2229,6 +2242,7 @@ "deps": [ "qps", "grpc++_test_util", + "grpc++_benchmark_config", "grpc_test_util", "grpc++", "grpc", diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc index 3106f26d66..c7367d876d 100644 --- a/test/cpp/qps/async_streaming_ping_pong_test.cc +++ b/test/cpp/qps/async_streaming_ping_pong_test.cc @@ -39,6 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/util/benchmark_config.h" namespace grpc { namespace testing { @@ -46,12 +47,10 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunAsyncStreamingPingPong() { +static void RunAsyncStreamingPingPong( + const std::vector >& reporters) { gpr_log(GPR_INFO, "Running Async Streaming Ping Pong"); - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); - ClientConfig client_config; client_config.set_client_type(ASYNC_CLIENT); client_config.set_enable_ssl(false); @@ -72,15 +71,19 @@ static void RunAsyncStreamingPingPong() { std::set types; types.insert(grpc::testing::ReportType::REPORT_QPS); types.insert(grpc::testing::ReportType::REPORT_LATENCY); - reporters_registry.Report({client_config, server_config, result}, types); + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } } } // namespace testing } // namespace grpc int main(int argc, char** argv) { - signal(SIGPIPE, SIG_IGN); - grpc::testing::RunAsyncStreamingPingPong(); + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); + signal(SIGPIPE, SIG_IGN); + grpc::testing::RunAsyncStreamingPingPong(reporters); return 0; } diff --git a/test/cpp/qps/async_unary_ping_pong_test.cc b/test/cpp/qps/async_unary_ping_pong_test.cc index a51badd9c1..50e824bf0e 100644 --- a/test/cpp/qps/async_unary_ping_pong_test.cc +++ b/test/cpp/qps/async_unary_ping_pong_test.cc @@ -39,6 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/util/benchmark_config.h" namespace grpc { namespace testing { @@ -46,12 +47,10 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunAsyncUnaryPingPong() { +static void RunAsyncUnaryPingPong( + const std::vector >& reporters) { gpr_log(GPR_INFO, "Running Async Unary Ping Pong"); - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); - ClientConfig client_config; client_config.set_client_type(ASYNC_CLIENT); client_config.set_enable_ssl(false); @@ -72,15 +71,18 @@ static void RunAsyncUnaryPingPong() { std::set types; types.insert(grpc::testing::ReportType::REPORT_QPS); types.insert(grpc::testing::ReportType::REPORT_LATENCY); - reporters_registry.Report({client_config, server_config, result}, types); + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } } - } // namespace testing } // namespace grpc int main(int argc, char** argv) { + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunAsyncUnaryPingPong(); + grpc::testing::RunAsyncUnaryPingPong(reporters); return 0; } diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc index 3aa215b448..b06b88d8a0 100644 --- a/test/cpp/qps/qps_driver.cc +++ b/test/cpp/qps/qps_driver.cc @@ -31,6 +31,7 @@ * */ +#include #include #include @@ -38,7 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" -#include "test/cpp/util/test_config.h" +#include "test/cpp/util/benchmark_config.h" DEFINE_int32(num_clients, 1, "Number of client binaries"); DEFINE_int32(num_servers, 1, "Number of server binaries"); @@ -69,17 +70,13 @@ using grpc::testing::ClientType; using grpc::testing::ServerType; using grpc::testing::RpcType; using grpc::testing::ResourceUsage; -using grpc::testing::ReportersRegistry; -using grpc::testing::GprLogReporter; -using grpc::testing::ReportData; using grpc::testing::ReportType; -int main(int argc, char** argv) { - grpc::testing::InitTest(&argc, &argv, true); - - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); +namespace grpc { +namespace testing { +static void QpsDriver( + const std::vector >& reporters) { RpcType rpc_type; GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type)); @@ -118,7 +115,20 @@ int main(int argc, char** argv) { std::set types; types.insert(grpc::testing::ReportType::REPORT_ALL); - reporters_registry.Report({client_config, server_config, result}, types); + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } +} + +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); + + signal(SIGPIPE, SIG_IGN); + grpc::testing::QpsDriver(reporters); return 0; } diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc index 2f72519397..869ec19179 100644 --- a/test/cpp/qps/qps_test.cc +++ b/test/cpp/qps/qps_test.cc @@ -39,6 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/util/benchmark_config.h" namespace grpc { namespace testing { @@ -46,12 +47,9 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunQPS() { +static void RunQPS(const std::vector >& reporters) { gpr_log(GPR_INFO, "Running QPS test"); - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); - ClientConfig client_config; client_config.set_client_type(ASYNC_CLIENT); client_config.set_enable_ssl(false); @@ -72,16 +70,20 @@ static void RunQPS() { std::set types; types.insert(grpc::testing::ReportType::REPORT_QPS_PER_CORE); types.insert(grpc::testing::ReportType::REPORT_LATENCY); - reporters_registry.Report({client_config, server_config, result}, types); - + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } } } // namespace testing } // namespace grpc int main(int argc, char** argv) { + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); + signal(SIGPIPE, SIG_IGN); - grpc::testing::RunQPS(); + grpc::testing::RunQPS(reporters); return 0; } diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 72b3a3643d..55726fbd00 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -39,26 +39,6 @@ namespace grpc { namespace testing { -// ReporterRegistry implementation. -void ReportersRegistry::Register(const Reporter* reporter) { - reporters_.emplace_back(reporter); -} - -std::vector ReportersRegistry::GetNamesRegistered() const { - std::vector names; - for (const auto& reporter : reporters_) { - names.push_back(reporter->name()); - } - return names; -} - -void ReportersRegistry::Report(const ReportData& data, - const std::set& types) const { - for (const auto& reporter : reporters_) { - reporter->Report(data, types); - } -} - // Reporter implementation. void Reporter::Report(const ReportData& data, const std::set& types) const { diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index e62b9deb32..64e92b1e89 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -71,30 +71,6 @@ enum ReportType { class Reporter; -/** A registry of Reporter instances. - * - * Instances registered will be taken into account by the Report() method. - */ -class ReportersRegistry { - public: - /** Adds the \c reporter to the registry. - * \attention Takes ownership of \c reporter. */ - void Register(const Reporter* reporter); - - /** Returns the names of the registered \c Reporter instances. */ - std::vector GetNamesRegistered() const; - - /** Triggers the reporting for all registered \c Reporter instances. - * - * \param data Configuration and results for the scenario being reported. - * \param types A collection of report types to include in the report. */ - void Report(const ReportData& data, - const std::set& types) const; - - private: - std::vector > reporters_; -}; - /** Interface for all reporters. */ class Reporter { public: diff --git a/test/cpp/qps/sync_streaming_ping_pong_test.cc b/test/cpp/qps/sync_streaming_ping_pong_test.cc index ddc1573bfd..b17a3f6e48 100644 --- a/test/cpp/qps/sync_streaming_ping_pong_test.cc +++ b/test/cpp/qps/sync_streaming_ping_pong_test.cc @@ -39,6 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/util/benchmark_config.h" namespace grpc { namespace testing { @@ -46,12 +47,10 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunSynchronousStreamingPingPong() { +static void RunSynchronousStreamingPingPong( + const std::vector >& reporters) { gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong"); - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); - ClientConfig client_config; client_config.set_client_type(SYNCHRONOUS_CLIENT); client_config.set_enable_ssl(false); @@ -71,16 +70,19 @@ static void RunSynchronousStreamingPingPong() { std::set types; types.insert(grpc::testing::ReportType::REPORT_QPS); types.insert(grpc::testing::ReportType::REPORT_LATENCY); - reporters_registry.Report({client_config, server_config, result}, types); - + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } } - } // namespace testing } // namespace grpc int main(int argc, char** argv) { + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); + signal(SIGPIPE, SIG_IGN); - grpc::testing::RunSynchronousStreamingPingPong(); + grpc::testing::RunSynchronousStreamingPingPong(reporters); return 0; } diff --git a/test/cpp/qps/sync_unary_ping_pong_test.cc b/test/cpp/qps/sync_unary_ping_pong_test.cc index a1bd1f1705..ff4038a386 100644 --- a/test/cpp/qps/sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/sync_unary_ping_pong_test.cc @@ -39,6 +39,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/util/benchmark_config.h" namespace grpc { namespace testing { @@ -46,7 +47,8 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunSynchronousUnaryPingPong() { +static void RunSynchronousUnaryPingPong( + const std::vector >& reporters) { gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); ReportersRegistry reporters_registry; @@ -71,15 +73,20 @@ static void RunSynchronousUnaryPingPong() { std::set types; types.insert(grpc::testing::ReportType::REPORT_QPS); types.insert(grpc::testing::ReportType::REPORT_LATENCY); - reporters_registry.Report({client_config, server_config, result}, types); + for (const auto& reporter : reporters) { + reporter->Report({client_config, server_config, result}, types); + } } } // namespace testing } // namespace grpc int main(int argc, char** argv) { + grpc::testing::InitBenchmark(&argc, &argv, true); + const auto& reporters = grpc::testing::InitBenchmarkReporters(); + signal(SIGPIPE, SIG_IGN); - grpc::testing::RunSynchronousUnaryPingPong(); + grpc::testing::RunSynchronousUnaryPingPong(reporters); return 0; } -- cgit v1.2.3 From 226beffea1fe772e172b6eb3125b096d0d11b2b2 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Tue, 19 May 2015 16:55:08 -0700 Subject: Simplified code based on comments and fixed build.json --- Makefile | 3 +-- build.json | 2 +- test/cpp/qps/async_streaming_ping_pong_test.cc | 6 ++--- test/cpp/qps/async_unary_ping_pong_test.cc | 6 ++--- test/cpp/qps/qps_driver.cc | 8 +++---- test/cpp/qps/qps_test.cc | 6 ++--- test/cpp/qps/report.cc | 26 -------------------- test/cpp/qps/report.h | 33 -------------------------- test/cpp/qps/sync_streaming_ping_pong_test.cc | 6 ++--- test/cpp/qps/sync_unary_ping_pong_test.cc | 9 ++----- test/cpp/util/benchmark_config.cc | 2 +- 11 files changed, 17 insertions(+), 90 deletions(-) (limited to 'test/cpp/qps/qps_driver.cc') diff --git a/Makefile b/Makefile index 6017455a4a..f2473f3518 100644 --- a/Makefile +++ b/Makefile @@ -3199,6 +3199,7 @@ endif LIBGRPC++_BENCHMARK_CONFIG_SRC = \ + test/cpp/qps/report.cc \ test/cpp/util/benchmark_config.cc \ @@ -3756,7 +3757,6 @@ LIBQPS_SRC = \ test/cpp/qps/client_sync.cc \ test/cpp/qps/driver.cc \ test/cpp/qps/qps_worker.cc \ - test/cpp/qps/report.cc \ test/cpp/qps/server_async.cc \ test/cpp/qps/server_sync.cc \ test/cpp/qps/timer.cc \ @@ -3807,7 +3807,6 @@ $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_async.o: $(GENDIR)/test/cpp/qps/qpstest. $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_sync.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/driver.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_worker.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/qps/report.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/server_async.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/server_sync.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/timer.o: $(GENDIR)/test/cpp/qps/qpstest.pb.cc $(GENDIR)/test/cpp/qps/qpstest.grpc.pb.cc diff --git a/build.json b/build.json index 4952b890a9..a3595f1357 100644 --- a/build.json +++ b/build.json @@ -530,6 +530,7 @@ "build": "private", "language": "c++", "src": [ + "test/cpp/qps/report.cc", "test/cpp/util/benchmark_config.cc" ] }, @@ -701,7 +702,6 @@ "test/cpp/qps/client_sync.cc", "test/cpp/qps/driver.cc", "test/cpp/qps/qps_worker.cc", - "test/cpp/qps/report.cc", "test/cpp/qps/server_async.cc", "test/cpp/qps/server_sync.cc", "test/cpp/qps/timer.cc" diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc index c7367d876d..8cb0949bb4 100644 --- a/test/cpp/qps/async_streaming_ping_pong_test.cc +++ b/test/cpp/qps/async_streaming_ping_pong_test.cc @@ -68,11 +68,9 @@ static void RunAsyncStreamingPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_QPS); - types.insert(grpc::testing::ReportType::REPORT_LATENCY); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPS(result); + reporter->ReportLatency(result); } } diff --git a/test/cpp/qps/async_unary_ping_pong_test.cc b/test/cpp/qps/async_unary_ping_pong_test.cc index 50e824bf0e..997cbced30 100644 --- a/test/cpp/qps/async_unary_ping_pong_test.cc +++ b/test/cpp/qps/async_unary_ping_pong_test.cc @@ -68,11 +68,9 @@ static void RunAsyncUnaryPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_QPS); - types.insert(grpc::testing::ReportType::REPORT_LATENCY); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPS(result); + reporter->ReportLatency(result); } } } // namespace testing diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc index b06b88d8a0..1f17424fad 100644 --- a/test/cpp/qps/qps_driver.cc +++ b/test/cpp/qps/qps_driver.cc @@ -70,7 +70,6 @@ using grpc::testing::ClientType; using grpc::testing::ServerType; using grpc::testing::RpcType; using grpc::testing::ResourceUsage; -using grpc::testing::ReportType; namespace grpc { namespace testing { @@ -113,10 +112,11 @@ static void QpsDriver( client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_ALL); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPS(result); + reporter->ReportQPSPerCore(result, server_config); + reporter->ReportLatency(result); + reporter->ReportTimes(result); } } diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc index 869ec19179..92940795a7 100644 --- a/test/cpp/qps/qps_test.cc +++ b/test/cpp/qps/qps_test.cc @@ -67,11 +67,9 @@ static void RunQPS(const std::vector >& reporters) { const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_QPS_PER_CORE); - types.insert(grpc::testing::ReportType::REPORT_LATENCY); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPSPerCore(result, server_config); + reporter->ReportLatency(result); } } diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 55726fbd00..9c4bb0d954 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -39,32 +39,6 @@ namespace grpc { namespace testing { -// Reporter implementation. -void Reporter::Report(const ReportData& data, - const std::set& types) const { - for (ReportType rtype : types) { - bool all = false; - switch (rtype) { - case REPORT_ALL: - all = true; - case REPORT_QPS: - ReportQPS(data.scenario_result); - if (!all) break; - case REPORT_QPS_PER_CORE: - ReportQPSPerCore(data.scenario_result, data.server_config); - if (!all) break; - case REPORT_LATENCY: - ReportLatency(data.scenario_result); - if (!all) break; - case REPORT_TIMES: - ReportTimes(data.scenario_result); - if (!all) break; - } - if (all) break; - } -} - -// GprLogReporter implementation. void GprLogReporter::ReportQPS(const ScenarioResult& result) const { gpr_log(GPR_INFO, "QPS: %.1f", result.latencies.Count() / diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index b28506cba3..32b948c34f 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -45,32 +45,6 @@ namespace grpc { namespace testing { -/** General set of data required for report generation. */ -struct ReportData { - const ClientConfig& client_config; - const ServerConfig& server_config; - const ScenarioResult& scenario_result; -}; - -/** Specifies the type of performance report we are interested in. - * - * \note The special type \c REPORT_ALL is equivalent to specifying all the - * other fields. */ -enum ReportType { - /** Equivalent to the combination of all other fields. */ - REPORT_ALL, - /** Report only QPS information. */ - REPORT_QPS, - /** Report only QPS per core information. */ - REPORT_QPS_PER_CORE, - /** Report latency info for the 50, 90, 95, 99 and 99.9th percentiles. */ - REPORT_LATENCY, - /** Report user and system time. */ - REPORT_TIMES -}; - -class Reporter; - /** Interface for all reporters. */ class Reporter { public: @@ -82,10 +56,6 @@ class Reporter { * Names are constants, set at construction time. */ string name() const { return name_; } - /** Template method responsible for the generation of the requested types. */ - void Report(const ReportData& data, const std::set& types) const; - - protected: /** Reports QPS for the given \a result. */ virtual void ReportQPS(const ScenarioResult& result) const = 0; @@ -103,9 +73,6 @@ class Reporter { const string name_; }; - -// Reporters. - /** Reporter to gpr_log(GPR_INFO). */ class GprLogReporter : public Reporter { public: diff --git a/test/cpp/qps/sync_streaming_ping_pong_test.cc b/test/cpp/qps/sync_streaming_ping_pong_test.cc index b17a3f6e48..6da107aa73 100644 --- a/test/cpp/qps/sync_streaming_ping_pong_test.cc +++ b/test/cpp/qps/sync_streaming_ping_pong_test.cc @@ -67,11 +67,9 @@ static void RunSynchronousStreamingPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_QPS); - types.insert(grpc::testing::ReportType::REPORT_LATENCY); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPS(result); + reporter->ReportLatency(result); } } } // namespace testing diff --git a/test/cpp/qps/sync_unary_ping_pong_test.cc b/test/cpp/qps/sync_unary_ping_pong_test.cc index ff4038a386..eb930def2a 100644 --- a/test/cpp/qps/sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/sync_unary_ping_pong_test.cc @@ -51,9 +51,6 @@ static void RunSynchronousUnaryPingPong( const std::vector >& reporters) { gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); - ReportersRegistry reporters_registry; - reporters_registry.Register(new GprLogReporter("LogReporter")); - ClientConfig client_config; client_config.set_client_type(SYNCHRONOUS_CLIENT); client_config.set_enable_ssl(false); @@ -70,11 +67,9 @@ static void RunSynchronousUnaryPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - std::set types; - types.insert(grpc::testing::ReportType::REPORT_QPS); - types.insert(grpc::testing::ReportType::REPORT_LATENCY); for (const auto& reporter : reporters) { - reporter->Report({client_config, server_config, result}, types); + reporter->ReportQPS(result); + reporter->ReportLatency(result); } } diff --git a/test/cpp/util/benchmark_config.cc b/test/cpp/util/benchmark_config.cc index 1f019c9715..914afa91ca 100644 --- a/test/cpp/util/benchmark_config.cc +++ b/test/cpp/util/benchmark_config.cc @@ -34,7 +34,7 @@ #include #include "test/cpp/util/benchmark_config.h" -DEFINE_bool(enable_log_reporter, false, +DEFINE_bool(enable_log_reporter, true, "Enable reporting of benchmark results through GprLog"); // In some distros, gflags is in the namespace google, and in some others, -- cgit v1.2.3 From a6b559a76ae3d96f8df4abe07173c8b56fbfc032 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 20 May 2015 22:08:24 -0700 Subject: Improvements to reporting mechanism based on comments. Turned the reporter into a composite, much cleaner arch. --- test/cpp/qps/async_streaming_ping_pong_test.cc | 12 ++++------- test/cpp/qps/async_unary_ping_pong_test.cc | 12 ++++------- test/cpp/qps/qps_driver.cc | 16 ++++++-------- test/cpp/qps/qps_test.cc | 11 ++++------ test/cpp/qps/report.cc | 30 ++++++++++++++++++++++++++ test/cpp/qps/report.h | 20 +++++++++++++++++ test/cpp/qps/sync_streaming_ping_pong_test.cc | 12 ++++------- test/cpp/qps/sync_unary_ping_pong_test.cc | 12 ++++------- test/cpp/util/benchmark_config.cc | 14 ++++++++---- test/cpp/util/benchmark_config.h | 8 ++++++- 10 files changed, 93 insertions(+), 54 deletions(-) (limited to 'test/cpp/qps/qps_driver.cc') diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc index 8cb0949bb4..dc972443ff 100644 --- a/test/cpp/qps/async_streaming_ping_pong_test.cc +++ b/test/cpp/qps/async_streaming_ping_pong_test.cc @@ -47,8 +47,7 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunAsyncStreamingPingPong( - const std::vector >& reporters) { +static void RunAsyncStreamingPingPong() { gpr_log(GPR_INFO, "Running Async Streaming Ping Pong"); ClientConfig client_config; @@ -68,10 +67,8 @@ static void RunAsyncStreamingPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - for (const auto& reporter : reporters) { - reporter->ReportQPS(result); - reporter->ReportLatency(result); - } + GetReporter()->ReportQPS(result); + GetReporter()->ReportLatency(result); } } // namespace testing @@ -79,9 +76,8 @@ static void RunAsyncStreamingPingPong( int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunAsyncStreamingPingPong(reporters); + grpc::testing::RunAsyncStreamingPingPong(); return 0; } diff --git a/test/cpp/qps/async_unary_ping_pong_test.cc b/test/cpp/qps/async_unary_ping_pong_test.cc index 997cbced30..05bc08a320 100644 --- a/test/cpp/qps/async_unary_ping_pong_test.cc +++ b/test/cpp/qps/async_unary_ping_pong_test.cc @@ -47,8 +47,7 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunAsyncUnaryPingPong( - const std::vector >& reporters) { +static void RunAsyncUnaryPingPong() { gpr_log(GPR_INFO, "Running Async Unary Ping Pong"); ClientConfig client_config; @@ -68,19 +67,16 @@ static void RunAsyncUnaryPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - for (const auto& reporter : reporters) { - reporter->ReportQPS(result); - reporter->ReportLatency(result); - } + GetReporter()->ReportQPS(result); + GetReporter()->ReportLatency(result); } } // namespace testing } // namespace grpc int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunAsyncUnaryPingPong(reporters); + grpc::testing::RunAsyncUnaryPingPong(); return 0; } diff --git a/test/cpp/qps/qps_driver.cc b/test/cpp/qps/qps_driver.cc index 1f17424fad..2e491eeb05 100644 --- a/test/cpp/qps/qps_driver.cc +++ b/test/cpp/qps/qps_driver.cc @@ -74,8 +74,7 @@ using grpc::testing::ResourceUsage; namespace grpc { namespace testing { -static void QpsDriver( - const std::vector >& reporters) { +static void QpsDriver() { RpcType rpc_type; GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type)); @@ -112,12 +111,10 @@ static void QpsDriver( client_config, FLAGS_num_clients, server_config, FLAGS_num_servers, FLAGS_warmup_seconds, FLAGS_benchmark_seconds, FLAGS_local_workers); - for (const auto& reporter : reporters) { - reporter->ReportQPS(result); - reporter->ReportQPSPerCore(result, server_config); - reporter->ReportLatency(result); - reporter->ReportTimes(result); - } + GetReporter()->ReportQPS(result); + GetReporter()->ReportQPSPerCore(result, server_config); + GetReporter()->ReportLatency(result); + GetReporter()->ReportTimes(result); } } // namespace testing @@ -125,10 +122,9 @@ static void QpsDriver( int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::QpsDriver(reporters); + grpc::testing::QpsDriver(); return 0; } diff --git a/test/cpp/qps/qps_test.cc b/test/cpp/qps/qps_test.cc index 92940795a7..03c9c2c423 100644 --- a/test/cpp/qps/qps_test.cc +++ b/test/cpp/qps/qps_test.cc @@ -47,7 +47,7 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunQPS(const std::vector >& reporters) { +static void RunQPS() { gpr_log(GPR_INFO, "Running QPS test"); ClientConfig client_config; @@ -67,10 +67,8 @@ static void RunQPS(const std::vector >& reporters) { const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - for (const auto& reporter : reporters) { - reporter->ReportQPSPerCore(result, server_config); - reporter->ReportLatency(result); - } + GetReporter()->ReportQPSPerCore(result, server_config); + GetReporter()->ReportLatency(result); } } // namespace testing @@ -78,10 +76,9 @@ static void RunQPS(const std::vector >& reporters) { int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunQPS(reporters); + grpc::testing::RunQPS(); return 0; } diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 9c4bb0d954..e116175e3b 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -39,6 +39,36 @@ namespace grpc { namespace testing { +void CompositeReporter::add(std::unique_ptr reporter) { + reporters_.emplace_back(std::move(reporter)); +} + +void CompositeReporter::ReportQPS(const ScenarioResult& result) const { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportQPS(result); + } +} + +void CompositeReporter::ReportQPSPerCore(const ScenarioResult& result, + const ServerConfig& config) const { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportQPSPerCore(result, config); + } +} + +void CompositeReporter::ReportLatency(const ScenarioResult& result) const { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportLatency(result); + } +} + +void CompositeReporter::ReportTimes(const ScenarioResult& result) const { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportTimes(result); + } +} + + void GprLogReporter::ReportQPS(const ScenarioResult& result) const { gpr_log(GPR_INFO, "QPS: %.1f", result.latencies.Count() / diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index 32b948c34f..3712f67a47 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -51,6 +51,8 @@ class Reporter { /** Construct a reporter with the given \a name. */ Reporter(const string& name) : name_(name) {} + virtual ~Reporter() {} + /** Returns this reporter's name. * * Names are constants, set at construction time. */ @@ -73,6 +75,24 @@ class Reporter { const string name_; }; +/** A composite for all reporters to be considered. */ +class CompositeReporter : public Reporter { + public: + CompositeReporter() : Reporter("CompositeReporter") {} + + /** Adds a \a reporter to the composite. */ + void add(std::unique_ptr reporter); + + void ReportQPS(const ScenarioResult& result) const GRPC_OVERRIDE; + void ReportQPSPerCore(const ScenarioResult& result, + const ServerConfig& config) const GRPC_OVERRIDE; + void ReportLatency(const ScenarioResult& result) const GRPC_OVERRIDE; + void ReportTimes(const ScenarioResult& result) const GRPC_OVERRIDE; + + private: + std::vector > reporters_; +}; + /** Reporter to gpr_log(GPR_INFO). */ class GprLogReporter : public Reporter { public: diff --git a/test/cpp/qps/sync_streaming_ping_pong_test.cc b/test/cpp/qps/sync_streaming_ping_pong_test.cc index 6da107aa73..776fbdde1c 100644 --- a/test/cpp/qps/sync_streaming_ping_pong_test.cc +++ b/test/cpp/qps/sync_streaming_ping_pong_test.cc @@ -47,8 +47,7 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunSynchronousStreamingPingPong( - const std::vector >& reporters) { +static void RunSynchronousStreamingPingPong() { gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong"); ClientConfig client_config; @@ -67,20 +66,17 @@ static void RunSynchronousStreamingPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - for (const auto& reporter : reporters) { - reporter->ReportQPS(result); - reporter->ReportLatency(result); - } + GetReporter()->ReportQPS(result); + GetReporter()->ReportLatency(result); } } // namespace testing } // namespace grpc int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunSynchronousStreamingPingPong(reporters); + grpc::testing::RunSynchronousStreamingPingPong(); return 0; } diff --git a/test/cpp/qps/sync_unary_ping_pong_test.cc b/test/cpp/qps/sync_unary_ping_pong_test.cc index eb930def2a..e79b820ce3 100644 --- a/test/cpp/qps/sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/sync_unary_ping_pong_test.cc @@ -47,8 +47,7 @@ namespace testing { static const int WARMUP = 5; static const int BENCHMARK = 10; -static void RunSynchronousUnaryPingPong( - const std::vector >& reporters) { +static void RunSynchronousUnaryPingPong() { gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); ClientConfig client_config; @@ -67,10 +66,8 @@ static void RunSynchronousUnaryPingPong( const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); - for (const auto& reporter : reporters) { - reporter->ReportQPS(result); - reporter->ReportLatency(result); - } + GetReporter()->ReportQPS(result); + GetReporter()->ReportLatency(result); } } // namespace testing @@ -78,10 +75,9 @@ static void RunSynchronousUnaryPingPong( int main(int argc, char** argv) { grpc::testing::InitBenchmark(&argc, &argv, true); - const auto& reporters = grpc::testing::InitBenchmarkReporters(); signal(SIGPIPE, SIG_IGN); - grpc::testing::RunSynchronousUnaryPingPong(reporters); + grpc::testing::RunSynchronousUnaryPingPong(); return 0; } diff --git a/test/cpp/util/benchmark_config.cc b/test/cpp/util/benchmark_config.cc index 914afa91ca..1b15ddcbcc 100644 --- a/test/cpp/util/benchmark_config.cc +++ b/test/cpp/util/benchmark_config.cc @@ -51,12 +51,18 @@ void InitBenchmark(int* argc, char*** argv, bool remove_flags) { ParseCommandLineFlags(argc, argv, remove_flags); } -std::vector > InitBenchmarkReporters() { - std::vector > reporters; +static std::shared_ptr InitBenchmarkReporters() { + auto* composite_reporter = new CompositeReporter; if (FLAGS_enable_log_reporter) { - reporters.emplace_back(new GprLogReporter("LogReporter")); + composite_reporter->add( + std::unique_ptr(new GprLogReporter("LogReporter"))); } - return reporters; + return std::shared_ptr(composite_reporter); +} + +const std::shared_ptr& GetReporter() { + static std::shared_ptr reporter(InitBenchmarkReporters()); + return reporter; } } // namespace testing diff --git a/test/cpp/util/benchmark_config.h b/test/cpp/util/benchmark_config.h index efbcad88f0..3a3a6d61ae 100644 --- a/test/cpp/util/benchmark_config.h +++ b/test/cpp/util/benchmark_config.h @@ -43,7 +43,13 @@ namespace grpc { namespace testing { void InitBenchmark(int* argc, char*** argv, bool remove_flags); -std::vector > InitBenchmarkReporters(); + +/** Returns the benchmark Reporter instance. + * + * The returned instane will take care of generating reports for all the actual + * reporters configured via the "enable_*_reporter" command line flags (see + * benchmark_config.cc). */ +const std::shared_ptr& GetReporter(); } // namespace testing } // namespace grpc -- cgit v1.2.3