Skip to content

Commit 352b991

Browse files
feat!(google_benchmark): improve location of valgrind trapdoors
1 parent fe032ce commit 352b991

File tree

9 files changed

+47
-16
lines changed

9 files changed

+47
-16
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),

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ target_include_directories(
3232
# Disable valgrind compilation errors
3333
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
3434
# Disable the old-style-cast warning for the specific target
35-
target_compile_options(codspeed PRIVATE -Wno-old-style-cast)
35+
target_compile_options(codspeed INTERFACE -Wno-old-style-cast)
3636
endif()
3737

3838
execute_process(
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: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
183183

184184
#include "benchmark/export.h"
185185

186+
#ifdef CODSPEED_ENABLED
187+
#include <codspeed.h>
188+
#include <measurement.hpp>
189+
190+
#include <filesystem>
191+
#endif // CODSPEED_ENABLED
192+
186193
#if defined(_MSC_VER)
187194
#include <intrin.h> // for _ReadWriteBarrier
188195
#endif
@@ -939,6 +946,9 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
939946

940947
public:
941948
const IterationCount max_iterations;
949+
#ifdef CODSPEED_INSTRUMENTATION
950+
codspeed::CodSpeed *codspeed_;
951+
#endif
942952

943953
private:
944954
bool started_;
@@ -959,7 +969,12 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
959969
const std::vector<int64_t>& ranges, int thread_i, int n_threads,
960970
internal::ThreadTimer* timer, internal::ThreadManager* manager,
961971
internal::PerfCountersMeasurement* perf_counters_measurement,
962-
ProfilerManager* profiler_manager);
972+
ProfilerManager* profiler_manager
973+
#ifdef CODSPEED_INSTRUMENTATION
974+
,
975+
codspeed::CodSpeed *codspeed = NULL
976+
#endif
977+
);
963978

964979
void StartKeepRunning();
965980
// Implementation of KeepRunning() and KeepRunningBatch().
@@ -1049,6 +1064,11 @@ struct State::StateIterator {
10491064
BENCHMARK_ALWAYS_INLINE
10501065
bool operator!=(StateIterator const&) const {
10511066
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
10521072
parent_->FinishKeepRunning();
10531073
return false;
10541074
}
@@ -1063,6 +1083,12 @@ inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() {
10631083
}
10641084
inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {
10651085
StartKeepRunning();
1086+
#ifdef CODSPEED_INSTRUMENTATION
1087+
if (this->codspeed_ != NULL) {
1088+
this->codspeed_->start_benchmark(name_);
1089+
measurement_start();
1090+
}
1091+
#endif
10661092
return StateIterator();
10671093
}
10681094

@@ -1439,10 +1465,6 @@ class Fixture : public internal::Benchmark {
14391465
n) [[maybe_unused]]
14401466

14411467
#ifdef CODSPEED_ENABLED
1442-
#include <codspeed.h>
1443-
1444-
#include <filesystem>
1445-
14461468
#define CUR_FILE \
14471469
codspeed::get_path_relative_to_workspace(__FILE__) + "::"
14481470
#define NAMESPACE \

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@ State BenchmarkInstance::RunInstrumented(
9797
internal::ThreadManager* manager,
9898
internal::PerfCountersMeasurement* perf_counters_measurement,
9999
ProfilerManager* profiler_manager) const {
100-
State st(name_.function_name, 1, args_, 0, 1, timer, manager,
101-
perf_counters_measurement, profiler_manager);
102100
// Do one repetition to avoid flakiness due to inconcistencies in CPU cache
103101
// from execution order
104102

105103
internal::ThreadTimer warmup_timer = internal::ThreadTimer::Create();
106104
State warmup_state(name_.function_name, 1, args_, 0, 1, &warmup_timer,
107-
manager, perf_counters_measurement, profiler_manager);
105+
manager, perf_counters_measurement, profiler_manager,
106+
NULL);
108107
benchmark_.Run(warmup_state);
109-
codspeed->start_benchmark(name().str());
108+
109+
State st(name().str(), 1, args_, 0, 1, timer, manager,
110+
perf_counters_measurement, profiler_manager, codspeed);
111+
;
110112
benchmark_.Run(st);
111-
codspeed->end_benchmark();
112113
return st;
113114
}
114115
#endif

0 commit comments

Comments
 (0)