From a145013d6da069c59cdeb75b2a09cc538adb747c Mon Sep 17 00:00:00 2001 From: Vy Nguyen Date: Thu, 7 Oct 2021 17:29:19 -0400 Subject: [PATCH] Temporarily disable benchmarks (#27629) benchmark 1.6.0 introduced API breaking changes so we temporarily disabled the benchmarks that are using the old API to avoid breaking. --- .../microbenchmarks/bm_cq_multiple_threads.cc | 2 +- test/cpp/microbenchmarks/bm_threadpool.cc | 7 +++-- test/cpp/util/test_config.h | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 66bc5d87d51..2c4241c0d91 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -162,7 +162,7 @@ static void teardown() { */ static void BM_Cq_Throughput(benchmark::State& state) { gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); - auto thd_idx = state.thread_index; + auto thd_idx = hack::get_thread_idx(state); gpr_mu_lock(&g_mu); g_threads_active++; diff --git a/test/cpp/microbenchmarks/bm_threadpool.cc b/test/cpp/microbenchmarks/bm_threadpool.cc index dd57bce5377..601392dd8ed 100644 --- a/test/cpp/microbenchmarks/bm_threadpool.cc +++ b/test/cpp/microbenchmarks/bm_threadpool.cc @@ -152,12 +152,13 @@ class SuicideFunctorForAdd : public grpc_completion_queue_functor { // Performs the scenario of external thread(s) adding closures into pool. static void BM_ThreadPoolExternalAdd(benchmark::State& state) { static grpc_core::ThreadPool* external_add_pool = nullptr; + int thread_idx = hack::get_thread_idx(state); // Setup for each run of test. - if (state.thread_index == 0) { + if (thread_idx == 0) { const int num_threads = state.range(1); external_add_pool = new grpc_core::ThreadPool(num_threads); } - const int num_iterations = state.range(0) / state.threads; + const int num_iterations = state.range(0) / hack::get_threads(state); while (state.KeepRunningBatch(num_iterations)) { BlockingCounter counter(num_iterations); for (int i = 0; i < num_iterations; ++i) { @@ -167,7 +168,7 @@ static void BM_ThreadPoolExternalAdd(benchmark::State& state) { } // Teardown at the end of each test run. - if (state.thread_index == 0) { + if (thread_idx == 0) { state.SetItemsProcessed(state.range(0)); delete external_add_pool; } diff --git a/test/cpp/util/test_config.h b/test/cpp/util/test_config.h index fb2b257ddea..bd7285b742b 100644 --- a/test/cpp/util/test_config.h +++ b/test/cpp/util/test_config.h @@ -19,6 +19,8 @@ #ifndef GRPC_TEST_CPP_UTIL_TEST_CONFIG_H #define GRPC_TEST_CPP_UTIL_TEST_CONFIG_H +#include + #ifndef GRPC_GTEST_FLAG_SET_DEATH_TEST_STYLE #define GRPC_GTEST_FLAG_SET_DEATH_TEST_STYLE(style) \ ::testing::FLAGS_gtest_death_test_style = style @@ -29,6 +31,35 @@ namespace testing { void InitTest(int* argc, char*** argv, bool remove_flags); +// FIXME(vyng): remove this +// This is hack to accommdate accessing .threads and .thread_index on benchmark +// State object. (In 1.6.0, the fields were made into methods, hence it's API +// breaking). + +namespace hack { + +template +auto get_threads(T& t) -> decltype(t.threads()) { + return t.threads(); +} + +template +auto get_threads(T& t) -> decltype(t.threads) { + return t.threads; +} + +template +auto get_thread_idx(T& t) -> decltype(t.thread_index()) { + return t.thread_index(); +} + +template +auto get_thread_idx(T& t) -> decltype(t.thread_index) { + return t.thread_index; +} + +} // namespace hack + } // namespace testing } // namespace grpc