diff --git a/google_benchmark/src/benchmark.cc b/google_benchmark/src/benchmark.cc index 5a7dbb7..6452d89 100644 --- a/google_benchmark/src/benchmark.cc +++ b/google_benchmark/src/benchmark.cc @@ -572,8 +572,6 @@ void RunBenchmarks(const std::vector& benchmarks, if (codspeed != nullptr) { codspeed->start_benchmark(runner.GetBenchmarkName()); } - - measurement_start(); #endif runner.DoOneRepetition(); @@ -605,8 +603,6 @@ void RunBenchmarks(const std::vector& benchmarks, } #ifdef CODSPEED_WALLTIME - measurement_stop(); - if (codspeed != nullptr) { codspeed->end_benchmark(); } diff --git a/google_benchmark/src/benchmark_runner.cc b/google_benchmark/src/benchmark_runner.cc index 1fb6149..75a14cb 100644 --- a/google_benchmark/src/benchmark_runner.cc +++ b/google_benchmark/src/benchmark_runner.cc @@ -466,8 +466,10 @@ void BenchmarkRunner::DoOneRepetition() { manager.reset(new internal::ThreadManager(b.threads())); internal::ThreadTimer timer = internal::ThreadTimer::Create(); b.Setup(); + measurement_start(); State st = b.RunInstrumented(codspeed::CodSpeed::getInstance(), &timer, manager.get(), nullptr, nullptr); + measurement_stop(); b.Teardown(); return; @@ -486,6 +488,12 @@ void BenchmarkRunner::DoOneRepetition() { RunWarmUp(); } + // IMPORTANT: We must not sample the warmup otherwise the flamegraph timings will be incorrect since we + // divide by the iteration count. +#ifdef CODSPEED_WALLTIME + measurement_start(); +#endif + IterationResults i; // We *may* be gradually increasing the length (iteration count) // of the benchmark until we decide the results are significant. @@ -519,6 +527,9 @@ void BenchmarkRunner::DoOneRepetition() { "if we did more iterations than we want to do the next time, " "then we should have accepted the current iteration run."); } +#ifdef CODSPEED_WALLTIME + measurement_stop(); +#endif // Produce memory measurements if requested. MemoryManager::Result* memory_result = nullptr;