Skip to content
Merged
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 1ec92c8c9db59db2d0adc37f47d003d3db4e1c64
)
FetchContent_MakeAvailable(instrument_hooks_repo)
FetchContent_GetProperties(instrument_hooks_repo)
Expand Down
25 changes: 25 additions & 0 deletions core/include/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ inline void measurement_set_metadata() {
instrument_hooks_write_environment(g_hooks, getpid());
}

#ifdef CODSPEED_ANALYSIS
// inline (C++17) so every translation unit shares one definition; a static
// would give each TU its own copy and silently desync the toggle parity.
inline bool measurement_collecting = true;
#endif

ALWAYS_INLINE void measurement_start() {
instrument_hooks_start_benchmark_inline(g_hooks);
}
Comment thread
not-matthias marked this conversation as resolved.
Expand Down Expand Up @@ -88,4 +94,23 @@ ALWAYS_INLINE void measurement_add_benchmark_timestamps(uint64_t start,
measurement_add_marker(MARKER_TYPE_BENCHMARK_END, end);
}

#ifdef CODSPEED_ANALYSIS
ALWAYS_INLINE void measurement_pause_timing() {
if (measurement_collecting) {
callgrind_toggle_collect();
measurement_collecting = false;
}
}

ALWAYS_INLINE void measurement_resume_timing() {
if (!measurement_collecting) {
callgrind_toggle_collect();
measurement_collecting = true;
}
}
#else
ALWAYS_INLINE void measurement_pause_timing() {}
ALWAYS_INLINE void measurement_resume_timing() {}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
#endif

#endif // MEASUREMENT_H
2 changes: 1 addition & 1 deletion core/instrument-hooks
6 changes: 4 additions & 2 deletions google_benchmark/src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#include "codspeed.h"
#include "internal_macros.h"

#ifdef CODSPEED_WALLTIME
#include "measurement.hpp"
#endif

#ifndef BENCHMARK_OS_WINDOWS
#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_OS_QURT)
Expand Down Expand Up @@ -272,6 +270,7 @@ void State::PauseTiming() {
#ifdef CODSPEED_WALLTIME
uint64_t pause_timestamp = measurement_current_timestamp();
#endif
measurement_pause_timing();

// Add in time accumulated so far
BM_CHECK(started_ && !finished_ && !skipped());
Expand Down Expand Up @@ -310,6 +309,7 @@ void State::ResumeTiming() {
BM_CHECK(resume_timestamp_ == 0);
resume_timestamp_ = measurement_current_timestamp();
#endif
measurement_resume_timing();
}

void State::SkipWithMessage(const std::string& msg) {
Expand All @@ -324,6 +324,7 @@ void State::SkipWithMessage(const std::string& msg) {
total_iterations_ = 0;
if (timer_->running()) {
timer_->StopTimer();
measurement_pause_timing();
}
}

Expand All @@ -339,6 +340,7 @@ void State::SkipWithError(const std::string& msg) {
total_iterations_ = 0;
if (timer_->running()) {
timer_->StopTimer();
measurement_pause_timing();
}
}

Expand Down
Loading