diff options
author | Craig Tiller <ctiller@google.com> | 2017-02-07 08:28:51 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-02-07 08:28:51 -0800 |
commit | b038beb7245877b71e30e782ddd6c86d82d11d17 (patch) | |
tree | ad1ff2c2e5ac711e868f59ecda4d443e152afa47 /test/cpp/microbenchmarks | |
parent | b4726ff0a6760f1b0a3e5a9a3914789b6ca9deeb (diff) |
Add counters for mutex acquisitions, expose in bm_fullstack
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack.cc | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/test/cpp/microbenchmarks/bm_fullstack.cc b/test/cpp/microbenchmarks/bm_fullstack.cc index c3e96c572c..c5ace53ff9 100644 --- a/test/cpp/microbenchmarks/bm_fullstack.cc +++ b/test/cpp/microbenchmarks/bm_fullstack.cc @@ -94,7 +94,37 @@ static void ApplyCommonChannelArguments(ChannelArguments* c) { c->SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, INT_MAX); } -class FullstackFixture { +#ifdef GPR_MU_COUNTERS +extern "C" gpr_atm grpc_mu_locks; +#endif + +class BaseFixture { + public: + void Finish(benchmark::State& s) { + std::ostringstream out; + this->AddToLabel(out, s); +#ifdef GPR_MU_COUNTERS + out << " locks/iteration:" + << ((double)(gpr_atm_no_barrier_load(&grpc_mu_locks) - + mu_locks_at_start_) / + (double)s.iterations()); +#endif + auto label = out.str(); + if (label.length() && label[0] == ' ') { + label = label.substr(1); + } + s.SetLabel(label); + } + + virtual void AddToLabel(std::ostream& out, benchmark::State& s) = 0; + + private: +#ifdef GPR_MU_COUNTERS + const size_t mu_locks_at_start_ = gpr_atm_no_barrier_load(&grpc_mu_locks); +#endif +}; + +class FullstackFixture : public BaseFixture { public: FullstackFixture(Service* service, const grpc::string& address) { ServerBuilder b; @@ -130,7 +160,7 @@ class TCP : public FullstackFixture { public: TCP(Service* service) : FullstackFixture(service, MakeAddress()) {} - void Finish(benchmark::State& state) {} + void AddToLabel(std::ostream& out, benchmark::State& state) {} private: static grpc::string MakeAddress() { @@ -145,7 +175,7 @@ class UDS : public FullstackFixture { public: UDS(Service* service) : FullstackFixture(service, MakeAddress()) {} - void Finish(benchmark::State& state) {} + void AddToLabel(std::ostream& out, benchmark::State& state) override {} private: static grpc::string MakeAddress() { @@ -157,7 +187,7 @@ class UDS : public FullstackFixture { } }; -class EndpointPairFixture { +class EndpointPairFixture : public BaseFixture { public: EndpointPairFixture(Service* service, grpc_endpoint_pair endpoints) { ServerBuilder b; @@ -233,7 +263,7 @@ class SockPair : public EndpointPairFixture { "test", initialize_stuff.rq(), 8192)) { } - void Finish(benchmark::State& state) {} + void AddToLabel(std::ostream& out, benchmark::State& state) {} }; class InProcessCHTTP2 : public EndpointPairFixture { @@ -241,11 +271,9 @@ class InProcessCHTTP2 : public EndpointPairFixture { InProcessCHTTP2(Service* service) : EndpointPairFixture(service, MakeEndpoints()) {} - void Finish(benchmark::State& state) { - std::ostringstream out; - out << "writes/iteration:" + void AddToLabel(std::ostream& out, benchmark::State& state) { + out << " writes/iteration:" << ((double)stats_.num_writes / (double)state.iterations()); - state.SetLabel(out.str()); } private: |