Skip to content

Commit 5c5b388

Browse files
feat!(google_benchmark): improve location of valgrind trapdoors
1 parent a1db652 commit 5c5b388

File tree

8 files changed

+36
-12
lines changed

8 files changed

+36
-12
lines changed

core/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CODSPEED_VERSION = "1.0.0"
77
cc_library(
88
name = "codspeed",
99
srcs = glob(["src/**/*.cpp"] + ["src/**/*.h"] + ["src/**/*.hpp"]),
10-
hdrs = ["include/codspeed.h"],
10+
hdrs = glob(["include/**/*.h"] + ["include/**/*.hpp"]),
1111
includes = ["include"],
1212
defines = [
1313
"CODSPEED_VERSION=\\\"{}\\\"".format(CODSPEED_VERSION),
File renamed without changes.

core/src/measurement.hpp renamed to core/include/measurement.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ inline void measurement_set_metadata() {
2020
CALLGRIND_DUMP_STATS_AT(metadata.c_str());
2121
}
2222

23-
inline void measurement_start() {
23+
__attribute__((always_inline)) inline void measurement_start() {
2424
CALLGRIND_ZERO_STATS;
2525
CALLGRIND_START_INSTRUMENTATION;
2626
}
2727

28-
inline void measurement_stop(const std::string &name) {
28+
__attribute__((always_inline)) inline void measurement_stop(
29+
const std::string &name) {
2930
CALLGRIND_STOP_INSTRUMENTATION;
3031
CALLGRIND_DUMP_STATS_AT(name.c_str());
3132
};
File renamed without changes.

core/src/codspeed.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ void CodSpeed::start_benchmark(const std::string &name) {
8282
}
8383

8484
current_benchmark = uri;
85-
measurement_start();
8685
}
8786

8887
void CodSpeed::end_benchmark() {

google_benchmark/include/benchmark/benchmark.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
185185

186186
#ifdef CODSPEED_ENABLED
187187
#include <codspeed.h>
188+
#include <measurement.hpp>>
188189

189190
#include <filesystem>
190191
#endif // CODSPEED_ENABLED
@@ -945,6 +946,9 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
945946

946947
public:
947948
const IterationCount max_iterations;
949+
#ifdef CODSPEED_INSTRUMENTATION
950+
codspeed::CodSpeed *codspeed_;
951+
#endif
948952

949953
private:
950954
bool started_;
@@ -965,7 +969,12 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
965969
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
966970
internal::ThreadTimer* timer, internal::ThreadManager* manager,
967971
internal::PerfCountersMeasurement* perf_counters_measurement,
968-
ProfilerManager* profiler_manager);
972+
ProfilerManager* profiler_manager
973+
#ifdef CODSPEED_INSTRUMENTATION
974+
,
975+
codspeed::CodSpeed *codspeed = NULL
976+
#endif
977+
);
969978

970979
void StartKeepRunning();
971980
// Implementation of KeepRunning() and KeepRunningBatch().
@@ -1055,6 +1064,11 @@ struct State::StateIterator {
10551064
BENCHMARK_ALWAYS_INLINE
10561065
bool operator!=(StateIterator const&) const {
10571066
if (BENCHMARK_BUILTIN_EXPECT(cached_ != 0, true)) return true;
1067+
#ifdef CODSPEED_INSTRUMENTATION
1068+
if (parent_->codspeed_ != NULL) {
1069+
parent_->codspeed_->end_benchmark();
1070+
}
1071+
#endif
10581072
parent_->FinishKeepRunning();
10591073
return false;
10601074
}
@@ -1065,15 +1079,15 @@ struct State::StateIterator {
10651079
};
10661080

10671081
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() {
1068-
#ifdef CODSPEED_INSTRUMENTATION
1069-
codspeed::CodSpeed::getInstance()->start_benchmark(name());
1070-
#endif
10711082
return StateIterator(this);
10721083
}
10731084
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {
10741085
StartKeepRunning();
10751086
#ifdef CODSPEED_INSTRUMENTATION
1076-
codspeed::CodSpeed::getInstance()->end_benchmark();
1087+
if (this->codspeed_ != NULL) {
1088+
this->codspeed_->start_benchmark(name_);
1089+
measurement_start();
1090+
}
10771091
#endif
10781092
return StateIterator();
10791093
}

google_benchmark/src/benchmark.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,18 @@ State::State(std::string name, IterationCount max_iters,
174174
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
175175
internal::ThreadTimer* timer, internal::ThreadManager* manager,
176176
internal::PerfCountersMeasurement* perf_counters_measurement,
177-
ProfilerManager* profiler_manager)
177+
ProfilerManager* profiler_manager
178+
#ifdef CODSPEED_INSTRUMENTATION
179+
,
180+
codspeed::CodSpeed* codspeed
181+
#endif
182+
)
178183
: total_iterations_(0),
179184
batch_leftover_(0),
180185
max_iterations(max_iters),
186+
#ifdef CODSPEED_INSTRUMENTATION
187+
codspeed_(codspeed),
188+
#endif
181189
started_(false),
182190
finished_(false),
183191
skipped_(internal::NotSkipped),

google_benchmark/src/benchmark_api_internal.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ State BenchmarkInstance::RunInstrumented(
102102

103103
internal::ThreadTimer warmup_timer = internal::ThreadTimer::Create();
104104
State warmup_state(name_.function_name, 1, args_, 0, 1, &warmup_timer,
105-
manager, perf_counters_measurement, profiler_manager);
105+
manager, perf_counters_measurement, profiler_manager,
106+
NULL);
106107
benchmark_.Run(warmup_state);
107108

108109
State st(name().str(), 1, args_, 0, 1, timer, manager,
109-
perf_counters_measurement, profiler_manager);
110+
perf_counters_measurement, profiler_manager, codspeed);
111+
;
110112
benchmark_.Run(st);
111113
return st;
112114
}

0 commit comments

Comments
 (0)