From acb2c326a4682aef557fd5577f1c5aec1ce9a7cf Mon Sep 17 00:00:00 2001 From: not-matthias Date: Fri, 13 Mar 2026 19:37:03 +0100 Subject: [PATCH] fix: exclude paused sections from instrumentation measurement PauseTiming/ResumeTiming now stop/start Callgrind instrumentation in CODSPEED_ANALYSIS mode, ensuring setup/teardown code is not included in benchmark measurements. --- google_benchmark/include/benchmark/benchmark.h | 6 ------ google_benchmark/src/benchmark.cc | 8 +++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/google_benchmark/include/benchmark/benchmark.h b/google_benchmark/include/benchmark/benchmark.h index f55288d..2647069 100644 --- a/google_benchmark/include/benchmark/benchmark.h +++ b/google_benchmark/include/benchmark/benchmark.h @@ -1074,9 +1074,6 @@ struct State::StateIterator { if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) { return true; } -#ifdef CODSPEED_ANALYSIS - measurement_stop(); -#endif parent_->FinishKeepRunning(); #ifdef CODSPEED_ANALYSIS @@ -1103,9 +1100,6 @@ inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() { #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 0358c9a..d7c1d11 100644 --- a/google_benchmark/src/benchmark.cc +++ b/google_benchmark/src/benchmark.cc @@ -19,7 +19,7 @@ #include "codspeed.h" #include "internal_macros.h" -#ifdef CODSPEED_WALLTIME +#if defined(CODSPEED_WALLTIME) || defined(CODSPEED_ANALYSIS) #include "measurement.hpp" #endif @@ -272,6 +272,9 @@ void State::PauseTiming() { #ifdef CODSPEED_WALLTIME uint64_t pause_timestamp = measurement_current_timestamp(); #endif +#ifdef CODSPEED_ANALYSIS + measurement_stop(); +#endif // Add in time accumulated so far BM_CHECK(started_ && !finished_ && !skipped()); @@ -310,6 +313,9 @@ void State::ResumeTiming() { BM_CHECK(resume_timestamp_ == 0); resume_timestamp_ = measurement_current_timestamp(); #endif +#ifdef CODSPEED_ANALYSIS + measurement_start(); +#endif } void State::SkipWithMessage(const std::string& msg) {