diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2018-01-31 22:35:17 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2018-01-31 22:35:17 +0100 |
commit | 18f27376c531e857d8fb946d758c81880023ed42 (patch) | |
tree | e79ac5445c57a4c6bd36497435c4c236c46b9b41 /test/cpp/microbenchmarks | |
parent | 382374eb6f373cb07b9b11371d6dda43138f0c26 (diff) |
avoid touching stats_ instance field before base constructor
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 25 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/fullstack_fixtures.h | 25 |
2 files changed, 28 insertions, 22 deletions
diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 07a8102915..3e31c2a4cb 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<std::ofstream> 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 7e93cbd74d..00ec72deee 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; } }; |