From 696eaa156eae83c4389c9c54ef5e803ab9f92247 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/src/benchmark.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/google_benchmark/src/benchmark.cc b/google_benchmark/src/benchmark.cc index 0358c9a..472c1ce 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 + callgrind_stop_instrumentation(); +#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 + callgrind_start_instrumentation(); +#endif } void State::SkipWithMessage(const std::string& msg) {