diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 3559a96..af6b2d8 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -15,7 +15,7 @@ include(FetchContent) FetchContent_Declare( instrument_hooks_repo GIT_REPOSITORY https://github.com/CodSpeedHQ/instrument-hooks - GIT_TAG b9ddb5bc654b2e6fa13eb18efcd3a45e7ecda0bb + GIT_TAG b6c4a75ecd81462bfc4d975e13060217799cd6ef ) FetchContent_MakeAvailable(instrument_hooks_repo) FetchContent_GetProperties(instrument_hooks_repo) diff --git a/core/instrument-hooks b/core/instrument-hooks index b9ddb5b..b6c4a75 160000 --- a/core/instrument-hooks +++ b/core/instrument-hooks @@ -1 +1 @@ -Subproject commit b9ddb5bc654b2e6fa13eb18efcd3a45e7ecda0bb +Subproject commit b6c4a75ecd81462bfc4d975e13060217799cd6ef diff --git a/google_benchmark/src/benchmark.cc b/google_benchmark/src/benchmark.cc index 0358c9a..aa464ec 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 @@ -61,6 +61,24 @@ #include "thread_timer.h" namespace benchmark { + +#ifdef CODSPEED_ANALYSIS +// Callgrind cost collection is kept off outside the benchmark loop (one +// initial toggle below, inverting the --collect-atstart=yes default) and +// toggled on/off by ResumeTiming()/PauseTiming(). This keeps harness code and +// paused sections out of the measurement without flushing the simulated cache +// (unlike CALLGRIND_STOP_INSTRUMENTATION). The toggle must be the first +// statement in PauseTiming() and the last in ResumeTiming(). +#define CODSPEED_TOGGLE_COLLECT() CALLGRIND_TOGGLE_COLLECT +namespace { +struct CodSpeedCollectInit { + CodSpeedCollectInit() { CODSPEED_TOGGLE_COLLECT(); } +} const codspeed_collect_init; +} // namespace +#else +#define CODSPEED_TOGGLE_COLLECT() +#endif + // Print a list of benchmarks. This option overrides all other options. BM_DEFINE_bool(benchmark_list_tests, false); @@ -272,6 +290,7 @@ void State::PauseTiming() { #ifdef CODSPEED_WALLTIME uint64_t pause_timestamp = measurement_current_timestamp(); #endif + CODSPEED_TOGGLE_COLLECT(); // Add in time accumulated so far BM_CHECK(started_ && !finished_ && !skipped()); @@ -310,6 +329,7 @@ void State::ResumeTiming() { BM_CHECK(resume_timestamp_ == 0); resume_timestamp_ = measurement_current_timestamp(); #endif + CODSPEED_TOGGLE_COLLECT(); } void State::SkipWithMessage(const std::string& msg) { @@ -324,6 +344,8 @@ void State::SkipWithMessage(const std::string& msg) { total_iterations_ = 0; if (timer_->running()) { timer_->StopTimer(); + // Skipped mid-loop without pausing: restore the collection-off state. + CODSPEED_TOGGLE_COLLECT(); } } @@ -339,6 +361,8 @@ void State::SkipWithError(const std::string& msg) { total_iterations_ = 0; if (timer_->running()) { timer_->StopTimer(); + // Skipped mid-loop without pausing: restore the collection-off state. + CODSPEED_TOGGLE_COLLECT(); } }