Skip to content

Commit 3212716

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

4 files changed

Lines changed: 27 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,25 @@ ALWAYS_INLINE void measurement_add_benchmark_timestamps(uint64_t start,
8888
measurement_add_marker(MARKER_TYPE_BENCHMARK_END, end);
8989
}
9090

91+
#ifdef CODSPEED_ANALYSIS
92+
static bool measurement_collecting = true;
93+
94+
ALWAYS_INLINE void measurement_pause_timing() {
95+
if (measurement_collecting) {
96+
callgrind_toggle_collect();
97+
measurement_collecting = false;
98+
}
99+
}
100+
101+
ALWAYS_INLINE void measurement_resume_timing() {
102+
if (!measurement_collecting) {
103+
callgrind_toggle_collect();
104+
measurement_collecting = true;
105+
}
106+
}
107+
#else
108+
ALWAYS_INLINE void measurement_pause_timing() {}
109+
ALWAYS_INLINE void measurement_resume_timing() {}
110+
#endif
111+
91112
#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)