diff options
author | 2018-01-31 22:35:17 +0100 | |
---|---|---|
committer | 2018-01-31 22:35:17 +0100 | |
commit | 18f27376c531e857d8fb946d758c81880023ed42 (patch) | |
tree | e79ac5445c57a4c6bd36497435c4c236c46b9b41 /test/cpp/microbenchmarks/bm_fullstack_trickle.cc | |
parent | 382374eb6f373cb07b9b11371d6dda43138f0c26 (diff) |
avoid touching stats_ instance field before base constructor
Diffstat (limited to 'test/cpp/microbenchmarks/bm_fullstack_trickle.cc')
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 25 |
1 files changed, 14 insertions, 11 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); |