Skip to content

Commit 17f1f3d

Browse files
committed
fix: use lightweight callgrind toggle for pause/resume timing
measurement_start()/measurement_stop() write markers and manage benchmark lifecycle — calling them on every pause/resume corrupts the marker structure and causes "No results found" errors. Instead, add measurement_pause()/measurement_resume() that only toggle CALLGRIND_STOP/START_INSTRUMENTATION without touching markers or stats.
1 parent acb2c32 commit 17f1f3d

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

core/include/measurement.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ ALWAYS_INLINE void measurement_stop() {
4545
instrument_hooks_stop_benchmark_inline(g_hooks);
4646
}
4747

48+
ALWAYS_INLINE void measurement_pause() { CALLGRIND_STOP_INSTRUMENTATION; }
49+
50+
ALWAYS_INLINE void measurement_resume() { CALLGRIND_START_INSTRUMENTATION; }
51+
4852
ALWAYS_INLINE void measurement_set_executed_benchmark(const std::string& name) {
4953
auto current_pid = getpid();
5054
instrument_hooks_executed_benchmark(g_hooks, current_pid, name.c_str());

google_benchmark/include/benchmark/benchmark.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,9 @@ struct State::StateIterator {
10741074
if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) {
10751075
return true;
10761076
}
1077+
#ifdef CODSPEED_ANALYSIS
1078+
measurement_stop();
1079+
#endif
10771080
parent_->FinishKeepRunning();
10781081

10791082
#ifdef CODSPEED_ANALYSIS
@@ -1100,6 +1103,9 @@ inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {
11001103
#endif
11011104

11021105
StartKeepRunning();
1106+
#ifdef CODSPEED_ANALYSIS
1107+
measurement_start();
1108+
#endif
11031109
return StateIterator();
11041110
}
11051111

google_benchmark/src/benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void State::PauseTiming() {
273273
uint64_t pause_timestamp = measurement_current_timestamp();
274274
#endif
275275
#ifdef CODSPEED_ANALYSIS
276-
measurement_stop();
276+
measurement_pause();
277277
#endif
278278

279279
// Add in time accumulated so far
@@ -314,7 +314,7 @@ void State::ResumeTiming() {
314314
resume_timestamp_ = measurement_current_timestamp();
315315
#endif
316316
#ifdef CODSPEED_ANALYSIS
317-
measurement_start();
317+
measurement_resume();
318318
#endif
319319
}
320320

0 commit comments

Comments
 (0)