Skip to content

Commit e47ecff

Browse files
committed
fix: exclude paused sections from instrumentation measurement
1 parent f5a917f commit e47ecff

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include(FetchContent)
1515
FetchContent_Declare(
1616
instrument_hooks_repo
1717
GIT_REPOSITORY https://github.com/CodSpeedHQ/instrument-hooks
18-
GIT_TAG b9ddb5bc654b2e6fa13eb18efcd3a45e7ecda0bb
18+
GIT_TAG 1ec92c8c9db59db2d0adc37f47d003d3db4e1c64
1919
)
2020
FetchContent_MakeAvailable(instrument_hooks_repo)
2121
FetchContent_GetProperties(instrument_hooks_repo)

core/include/measurement.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ inline void measurement_set_metadata() {
5656
instrument_hooks_write_environment(g_hooks, getpid());
5757
}
5858

59+
#ifdef CODSPEED_ANALYSIS
60+
// inline (C++17) so every translation unit shares one definition; a static
61+
// would give each TU its own copy and silently desync the toggle parity.
62+
inline bool measurement_collecting = true;
63+
#endif
64+
5965
ALWAYS_INLINE void measurement_start() {
6066
instrument_hooks_start_benchmark_inline(g_hooks);
6167
}
@@ -88,4 +94,23 @@ ALWAYS_INLINE void measurement_add_benchmark_timestamps(uint64_t start,
8894
measurement_add_marker(MARKER_TYPE_BENCHMARK_END, end);
8995
}
9096

97+
#ifdef CODSPEED_ANALYSIS
98+
ALWAYS_INLINE void measurement_pause_timing() {
99+
if (measurement_collecting) {
100+
callgrind_toggle_collect();
101+
measurement_collecting = false;
102+
}
103+
}
104+
105+
ALWAYS_INLINE void measurement_resume_timing() {
106+
if (!measurement_collecting) {
107+
callgrind_toggle_collect();
108+
measurement_collecting = true;
109+
}
110+
}
111+
#else
112+
ALWAYS_INLINE void measurement_pause_timing() {}
113+
ALWAYS_INLINE void measurement_resume_timing() {}
114+
#endif
115+
91116
#endif // MEASUREMENT_H

google_benchmark/src/benchmark.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
#include "codspeed.h"
2020
#include "internal_macros.h"
2121

22-
#ifdef CODSPEED_WALLTIME
2322
#include "measurement.hpp"
24-
#endif
2523

2624
#ifndef BENCHMARK_OS_WINDOWS
2725
#if !defined(BENCHMARK_OS_FUCHSIA) && !defined(BENCHMARK_OS_QURT)
@@ -272,6 +270,7 @@ void State::PauseTiming() {
272270
#ifdef CODSPEED_WALLTIME
273271
uint64_t pause_timestamp = measurement_current_timestamp();
274272
#endif
273+
measurement_pause_timing();
275274

276275
// Add in time accumulated so far
277276
BM_CHECK(started_ && !finished_ && !skipped());
@@ -310,6 +309,7 @@ void State::ResumeTiming() {
310309
BM_CHECK(resume_timestamp_ == 0);
311310
resume_timestamp_ = measurement_current_timestamp();
312311
#endif
312+
measurement_resume_timing();
313313
}
314314

315315
void State::SkipWithMessage(const std::string& msg) {
@@ -324,6 +324,7 @@ void State::SkipWithMessage(const std::string& msg) {
324324
total_iterations_ = 0;
325325
if (timer_->running()) {
326326
timer_->StopTimer();
327+
measurement_pause_timing();
327328
}
328329
}
329330

@@ -339,6 +340,7 @@ void State::SkipWithError(const std::string& msg) {
339340
total_iterations_ = 0;
340341
if (timer_->running()) {
341342
timer_->StopTimer();
343+
measurement_pause_timing();
342344
}
343345
}
344346

0 commit comments

Comments
 (0)