diff options
author | Craig Tiller <ctiller@google.com> | 2017-03-03 16:53:07 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-03-03 16:53:07 -0800 |
commit | 656a1ab01f3c4a43fda066b45160799f632d7c55 (patch) | |
tree | 926fc7d857c9f4542ee207ba393a1af1e5057c43 /test/cpp/microbenchmarks | |
parent | 1128d462c395d064a620c9e62cf29f152cbce33a (diff) | |
parent | f09ec59222e4abd8a534f89139f6b52378776fc4 (diff) |
Merge branch 'fssplit' into poll-wakeup
Diffstat (limited to 'test/cpp/microbenchmarks')
-rw-r--r-- | test/cpp/microbenchmarks/helpers.cc | 65 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/helpers.h | 32 |
2 files changed, 67 insertions, 30 deletions
diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc new file mode 100644 index 0000000000..947e81ffd8 --- /dev/null +++ b/test/cpp/microbenchmarks/helpers.cc @@ -0,0 +1,65 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "test/cpp/microbenchmarks/helpers.h" + +void TrackCounters::Finish(benchmark::State &state) { + std::ostringstream out; + AddToLabel(out, state); + auto label = out.str(); + if (label.length() && label[0] == ' ') { + label = label.substr(1); + } + state.SetLabel(label); +} + +void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { +#ifdef GPR_LOW_LEVEL_COUNTERS + out << " locks/iter:" << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) - + mu_locks_at_start_) / + (double)state.iterations()) + << " atm_cas/iter:" + << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_cas) - + atm_cas_at_start_) / + (double)state.iterations()) + << " atm_add/iter:" + << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_add) - + atm_add_at_start_) / + (double)state.iterations()); +#endif + grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); + out << " allocs/iter:" + << ((double)(counters_at_end.total_allocs_absolute - + counters_at_start_.total_allocs_absolute) / + (double)state.iterations()); +} diff --git a/test/cpp/microbenchmarks/helpers.h b/test/cpp/microbenchmarks/helpers.h index ea9024dce5..42a8fbaf0b 100644 --- a/test/cpp/microbenchmarks/helpers.h +++ b/test/cpp/microbenchmarks/helpers.h @@ -74,36 +74,8 @@ extern "C" gpr_atm gpr_counter_atm_add; class TrackCounters { public: - virtual void Finish(benchmark::State& state) { - std::ostringstream out; - AddToLabel(out, state); - auto label = out.str(); - if (label.length() && label[0] == ' ') { - label = label.substr(1); - } - state.SetLabel(label); - } - - virtual void AddToLabel(std::ostream& out, benchmark::State& state) { -#ifdef GPR_LOW_LEVEL_COUNTERS - out << " locks/iter:" << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) - - mu_locks_at_start_) / - (double)state.iterations()) - << " atm_cas/iter:" - << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_cas) - - atm_cas_at_start_) / - (double)state.iterations()) - << " atm_add/iter:" - << ((double)(gpr_atm_no_barrier_load(&gpr_counter_atm_add) - - atm_add_at_start_) / - (double)state.iterations()); -#endif - grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); - out << " allocs/iter:" - << ((double)(counters_at_end.total_allocs_absolute - - counters_at_start_.total_allocs_absolute) / - (double)state.iterations()); - } + virtual void Finish(benchmark::State& state); + virtual void AddToLabel(std::ostream& out, benchmark::State& state); private: #ifdef GPR_LOW_LEVEL_COUNTERS |