Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/instrument-hooks
26 changes: 25 additions & 1 deletion google_benchmark/src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
}

Expand All @@ -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();
}
}

Expand Down
Loading