diff options
author | Craig Tiller <ctiller@google.com> | 2017-03-03 16:52:37 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-03-03 16:52:37 -0800 |
commit | f09ec59222e4abd8a534f89139f6b52378776fc4 (patch) | |
tree | efe76223d005dab9e753acb229d8ad1f07a97c8f | |
parent | 0dc57ad46f376356c3d4d155e974b0c37e9609df (diff) |
Fix mac build
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | build.yaml | 2 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/helpers.cc | 65 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/helpers.h | 32 | ||||
-rw-r--r-- | tools/run_tests/generated/sources_and_headers.json | 1 | ||||
-rw-r--r-- | vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj | 2 | ||||
-rw-r--r-- | vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj.filters | 5 |
8 files changed, 79 insertions, 31 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dbc2b4b8bf..c521b7916e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3106,6 +3106,7 @@ endif() if (gRPC_BUILD_TESTS) add_library(grpc_benchmark + test/cpp/microbenchmarks/helpers.cc ) if(WIN32 AND MSVC) @@ -4976,6 +4976,7 @@ endif LIBGRPC_BENCHMARK_SRC = \ + test/cpp/microbenchmarks/helpers.cc \ PUBLIC_HEADERS_CXX += \ @@ -18380,6 +18381,7 @@ test/cpp/interop/interop_client.cc: $(OPENSSL_DEP) test/cpp/interop/interop_server.cc: $(OPENSSL_DEP) test/cpp/interop/interop_server_bootstrap.cc: $(OPENSSL_DEP) test/cpp/interop/server_helper.cc: $(OPENSSL_DEP) +test/cpp/microbenchmarks/helpers.cc: $(OPENSSL_DEP) test/cpp/qps/client_async.cc: $(OPENSSL_DEP) test/cpp/qps/client_sync.cc: $(OPENSSL_DEP) test/cpp/qps/driver.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index a39ee9f44b..e9f622de9e 100644 --- a/build.yaml +++ b/build.yaml @@ -1221,6 +1221,8 @@ libs: - test/cpp/microbenchmarks/fullstack_context_mutators.h - test/cpp/microbenchmarks/fullstack_fixtures.h - test/cpp/microbenchmarks/helpers.h + src: + - test/cpp/microbenchmarks/helpers.cc deps: - benchmark - grpc++ 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 diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 06fc3799e3..2dbbe03784 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -5794,6 +5794,7 @@ "src": [ "test/cpp/microbenchmarks/fullstack_context_mutators.h", "test/cpp/microbenchmarks/fullstack_fixtures.h", + "test/cpp/microbenchmarks/helpers.cc", "test/cpp/microbenchmarks/helpers.h" ], "third_party": false, diff --git a/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj b/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj index 62e10bf177..228227a531 100644 --- a/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj +++ b/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj @@ -165,7 +165,7 @@ <ClInclude Include="$(SolutionDir)\..\test\cpp\microbenchmarks\helpers.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="$(SolutionDir)\..\vsprojects\dummy.c"> + <ClCompile Include="$(SolutionDir)\..\test\cpp\microbenchmarks\helpers.cc"> </ClCompile> </ItemGroup> <ItemGroup> diff --git a/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj.filters b/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj.filters index 3e003edd5e..8e865bcc1b 100644 --- a/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj.filters +++ b/vsprojects/vcxproj/test/grpc_benchmark/grpc_benchmark.vcxproj.filters @@ -1,6 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> + <ClCompile Include="$(SolutionDir)\..\test\cpp\microbenchmarks\helpers.cc"> + <Filter>test\cpp\microbenchmarks</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> <ClInclude Include="$(SolutionDir)\..\test\cpp\microbenchmarks\fullstack_context_mutators.h"> <Filter>test\cpp\microbenchmarks</Filter> </ClInclude> |