Improvements to reporting mechanism based on comments.
Turned the reporter into a composite, much cleaner arch.
diff --git a/test/cpp/qps/async_streaming_ping_pong_test.cc b/test/cpp/qps/async_streaming_ping_pong_test.cc
index 8cb0949..dc97244 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 @@
static const int WARMUP = 5;
static const int BENCHMARK = 10;
-static void RunAsyncStreamingPingPong(
- const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void RunAsyncStreamingPingPong() {
gpr_log(GPR_INFO, "Running Async Streaming Ping Pong");
ClientConfig client_config;
@@ -68,10 +67,8 @@
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 @@
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 997cbce..05bc08a 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 @@
static const int WARMUP = 5;
static const int BENCHMARK = 10;
-static void RunAsyncUnaryPingPong(
- const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void RunAsyncUnaryPingPong() {
gpr_log(GPR_INFO, "Running Async Unary Ping Pong");
ClientConfig client_config;
@@ -68,19 +67,16 @@
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 1f17424..2e491ee 100644
--- a/test/cpp/qps/qps_driver.cc
+++ b/test/cpp/qps/qps_driver.cc
@@ -74,8 +74,7 @@
namespace grpc {
namespace testing {
-static void QpsDriver(
- const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void QpsDriver() {
RpcType rpc_type;
GPR_ASSERT(RpcType_Parse(FLAGS_rpc_type, &rpc_type));
@@ -112,12 +111,10 @@
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 @@
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 9294079..03c9c2c 100644
--- a/test/cpp/qps/qps_test.cc
+++ b/test/cpp/qps/qps_test.cc
@@ -47,7 +47,7 @@
static const int WARMUP = 5;
static const int BENCHMARK = 10;
-static void RunQPS(const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void RunQPS() {
gpr_log(GPR_INFO, "Running QPS test");
ClientConfig client_config;
@@ -67,10 +67,8 @@
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 @@
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 9c4bb0d..e116175 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> 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 32b948c..3712f67 100644
--- a/test/cpp/qps/report.h
+++ b/test/cpp/qps/report.h
@@ -51,6 +51,8 @@
/** 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 @@
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> 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<std::unique_ptr<Reporter> > 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 6da107a..776fbdd 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 @@
static const int WARMUP = 5;
static const int BENCHMARK = 10;
-static void RunSynchronousStreamingPingPong(
- const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void RunSynchronousStreamingPingPong() {
gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong");
ClientConfig client_config;
@@ -67,20 +66,17 @@
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 eb930de..e79b820 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 @@
static const int WARMUP = 5;
static const int BENCHMARK = 10;
-static void RunSynchronousUnaryPingPong(
- const std::vector<std::unique_ptr<Reporter> >& reporters) {
+static void RunSynchronousUnaryPingPong() {
gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong");
ClientConfig client_config;
@@ -67,10 +66,8 @@
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 @@
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 914afa9..1b15ddc 100644
--- a/test/cpp/util/benchmark_config.cc
+++ b/test/cpp/util/benchmark_config.cc
@@ -51,12 +51,18 @@
ParseCommandLineFlags(argc, argv, remove_flags);
}
-std::vector<std::unique_ptr<Reporter> > InitBenchmarkReporters() {
- std::vector<std::unique_ptr<Reporter> > reporters;
+static std::shared_ptr<Reporter> InitBenchmarkReporters() {
+ auto* composite_reporter = new CompositeReporter;
if (FLAGS_enable_log_reporter) {
- reporters.emplace_back(new GprLogReporter("LogReporter"));
+ composite_reporter->add(
+ std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
}
- return reporters;
+ return std::shared_ptr<Reporter>(composite_reporter);
+}
+
+const std::shared_ptr<Reporter>& GetReporter() {
+ static std::shared_ptr<Reporter> reporter(InitBenchmarkReporters());
+ return reporter;
}
} // namespace testing
diff --git a/test/cpp/util/benchmark_config.h b/test/cpp/util/benchmark_config.h
index efbcad8..3a3a6d6 100644
--- a/test/cpp/util/benchmark_config.h
+++ b/test/cpp/util/benchmark_config.h
@@ -43,7 +43,13 @@
namespace testing {
void InitBenchmark(int* argc, char*** argv, bool remove_flags);
-std::vector<std::unique_ptr<Reporter> > 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<Reporter>& GetReporter();
} // namespace testing
} // namespace grpc