From 649071319a5999d5fb02d5abf3f5003e2dd59ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 14 Aug 2026 10:52:02 +0200 Subject: [PATCH] fix: Instrument the KeepRunningBatch() loops The start_benchmark()/end_benchmark() hooks were attached to the StateIterator only, so the benchmarks looping with while (state.KeepRunningBatch(n)) were executed but never measured. Move them to StartKeepRunning()/FinishKeepRunning(), which both the range-based and the KeepRunning*() loops go through. --- google_benchmark/include/benchmark/benchmark.h | 18 ------------------ google_benchmark/src/benchmark.cc | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/google_benchmark/include/benchmark/benchmark.h b/google_benchmark/include/benchmark/benchmark.h index f55288d..9951fd6 100644 --- a/google_benchmark/include/benchmark/benchmark.h +++ b/google_benchmark/include/benchmark/benchmark.h @@ -1074,16 +1074,7 @@ struct State::StateIterator { if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) { return true; } -#ifdef CODSPEED_ANALYSIS - measurement_stop(); -#endif parent_->FinishKeepRunning(); - -#ifdef CODSPEED_ANALYSIS - if (parent_->codspeed_ != NULL) { - parent_->codspeed_->end_benchmark(); - } -#endif return false; } @@ -1096,16 +1087,7 @@ inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() { return StateIterator(this); } inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() { -#ifdef CODSPEED_ANALYSIS - if (this->codspeed_ != NULL) { - this->codspeed_->start_benchmark(name_); - } -#endif - StartKeepRunning(); -#ifdef CODSPEED_ANALYSIS - measurement_start(); -#endif return StateIterator(); } diff --git a/google_benchmark/src/benchmark.cc b/google_benchmark/src/benchmark.cc index 610a62c..6955b3e 100644 --- a/google_benchmark/src/benchmark.cc +++ b/google_benchmark/src/benchmark.cc @@ -354,6 +354,11 @@ void State::SetLabel(const std::string& label) { } void State::StartKeepRunning() { +#ifdef CODSPEED_ANALYSIS + if (codspeed_ != NULL) { + codspeed_->start_benchmark(name_); + } +#endif BM_CHECK(!started_ && !finished_); started_ = true; total_iterations_ = skipped() ? 0 : max_iterations; @@ -364,9 +369,15 @@ void State::StartKeepRunning() { if (!skipped()) { ResumeTiming(); } +#ifdef CODSPEED_ANALYSIS + measurement_start(); +#endif } void State::FinishKeepRunning() { +#ifdef CODSPEED_ANALYSIS + measurement_stop(); +#endif BM_CHECK(started_ && (!finished_ || skipped())); if (!skipped()) { PauseTiming(); @@ -378,6 +389,11 @@ void State::FinishKeepRunning() { if (BENCHMARK_BUILTIN_EXPECT(profiler_manager_ != nullptr, false)) { profiler_manager_->BeforeTeardownStop(); } +#ifdef CODSPEED_ANALYSIS + if (codspeed_ != NULL) { + codspeed_->end_benchmark(); + } +#endif } namespace internal {