diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 07a81029151..3e31c2a4cb8 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -79,9 +79,12 @@ static void write_csv(std::ostream* out, A0&& a0, Arg&&... arg) { class TrickledCHTTP2 : public EndpointPairFixture { public: TrickledCHTTP2(Service* service, bool streaming, size_t req_size, - size_t resp_size, size_t kilobits_per_second) - : EndpointPairFixture(service, MakeEndpoints(kilobits_per_second), - FixtureConfiguration()) { + size_t resp_size, size_t kilobits_per_second, + grpc_passthru_endpoint_stats* stats = + grpc_passthru_endpoint_stats_create()) + : EndpointPairFixture(service, MakeEndpoints(kilobits_per_second, stats), + FixtureConfiguration()), + stats_(stats) { if (FLAGS_log) { std::ostringstream fn; fn << "trickle." << (streaming ? "streaming" : "unary") << "." << req_size @@ -101,7 +104,11 @@ class TrickledCHTTP2 : public EndpointPairFixture { } } - virtual ~TrickledCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); } + virtual ~TrickledCHTTP2() { + if (stats_ != nullptr) { + grpc_passthru_endpoint_stats_destroy(stats_); + } + } void AddToLabel(std::ostream& out, benchmark::State& state) { out << " writes/iter:" @@ -205,15 +212,11 @@ class TrickledCHTTP2 : public EndpointPairFixture { std::unique_ptr log_; gpr_timespec start_ = gpr_now(GPR_CLOCK_MONOTONIC); - grpc_endpoint_pair MakeEndpoints(size_t kilobits) { - stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to - // initialize stats_ and - // pass MakeEndpoints's - // return value to base - // constructor? + static grpc_endpoint_pair MakeEndpoints(size_t kilobits, + grpc_passthru_endpoint_stats* stats) { grpc_endpoint_pair p; grpc_passthru_endpoint_create(&p.client, &p.server, Library::get().rq(), - stats_); + stats); double bytes_per_second = 125.0 * kilobits; p.client = grpc_trickle_endpoint_create(p.client, bytes_per_second); p.server = grpc_trickle_endpoint_create(p.server, bytes_per_second); diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 7e93cbd74d8..00ec72deee6 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -249,10 +249,18 @@ class InProcessCHTTP2 : public EndpointPairFixture { public: InProcessCHTTP2(Service* service, const FixtureConfiguration& fixture_configuration = - FixtureConfiguration()) - : EndpointPairFixture(service, MakeEndpoints(), fixture_configuration) {} - - virtual ~InProcessCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); } + FixtureConfiguration(), + grpc_passthru_endpoint_stats* stats = + grpc_passthru_endpoint_stats_create()) + : EndpointPairFixture(service, MakeEndpoints(stats), + fixture_configuration), + stats_(stats) {} + + virtual ~InProcessCHTTP2() { + if (stats_ != nullptr) { + grpc_passthru_endpoint_stats_destroy(stats_); + } + } void AddToLabel(std::ostream& out, benchmark::State& state) { EndpointPairFixture::AddToLabel(out, state); @@ -264,15 +272,10 @@ class InProcessCHTTP2 : public EndpointPairFixture { private: grpc_passthru_endpoint_stats* stats_; - grpc_endpoint_pair MakeEndpoints() { - stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to - // initialize stats_ and - // pass MakeEndpoints's - // return value to base - // constructor? + static grpc_endpoint_pair MakeEndpoints(grpc_passthru_endpoint_stats* stats) { grpc_endpoint_pair p; grpc_passthru_endpoint_create(&p.client, &p.server, Library::get().rq(), - stats_); + stats); return p; } }; diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index 0866b58f58d..86e3bbcd4e1 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -142,25 +142,25 @@ class EndpointPairFixture { class InProcessCHTTP2 : public EndpointPairFixture { public: - InProcessCHTTP2(Service* service) - : EndpointPairFixture(service, MakeEndpoints()) {} + InProcessCHTTP2(Service* service, grpc_passthru_endpoint_stats* stats = + grpc_passthru_endpoint_stats_create()) + : EndpointPairFixture(service, MakeEndpoints(stats)), stats_(stats) {} - virtual ~InProcessCHTTP2() { grpc_passthru_endpoint_stats_destroy(stats_); } + virtual ~InProcessCHTTP2() { + if (stats_ != nullptr) { + grpc_passthru_endpoint_stats_destroy(stats_); + } + } int writes_performed() const { return stats_->num_writes; } private: grpc_passthru_endpoint_stats* stats_; - grpc_endpoint_pair MakeEndpoints() { - stats_ = grpc_passthru_endpoint_stats_create(); // is there a better way to - // initialize stats_ and - // pass MakeEndpoints's - // return value to base - // constructor? + static grpc_endpoint_pair MakeEndpoints(grpc_passthru_endpoint_stats* stats) { grpc_endpoint_pair p; grpc_passthru_endpoint_create(&p.client, &p.server, initialize_stuff.rq(), - stats_); + stats); return p; } };