Skip to content

Commit b563384

Browse files
feat(google_benchmark): add file name to benchmark URI
1 parent 3e2d001 commit b563384

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

google_benchmark/cmake/Codspeed.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
add_subdirectory(${PROJECT_SOURCE_DIR}/../core codspeed)
2+
3+
execute_process(
4+
COMMAND git rev-parse --show-toplevel
5+
OUTPUT_VARIABLE GIT_ROOT_DIR
6+
OUTPUT_STRIP_TRAILING_WHITESPACE)
7+
8+
target_compile_definitions(codspeed
9+
INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}")
10+
111
# Step 1: Check if CODSPEED_MODE is set via the command line
212

313
# CMake cache kind of breaks this mechanism, keeping it for first time

google_benchmark/include/benchmark/benchmark.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
171171
#include <cstddef>
172172
#include <initializer_list>
173173
#include <iosfwd>
174+
#include <iostream>
174175
#include <limits>
175176
#include <map>
176177
#include <memory>
@@ -1437,11 +1438,23 @@ class Fixture : public internal::Benchmark {
14371438
static ::benchmark::internal::Benchmark const* const BENCHMARK_PRIVATE_NAME( \
14381439
n) [[maybe_unused]]
14391440

1441+
#ifdef CODSPEED_INSTRUMENTATION
1442+
#include <filesystem>
1443+
#define BENCHMARK(...) \
1444+
BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \
1445+
(::benchmark::internal::RegisterBenchmarkInternal( \
1446+
std::make_unique<::benchmark::internal::FunctionBenchmark>( \
1447+
std::filesystem::relative(__FILE__, CODSPEED_GIT_ROOT_DIR) \
1448+
.string() + \
1449+
"::" + #__VA_ARGS__, \
1450+
__VA_ARGS__)))
1451+
#else
14401452
#define BENCHMARK(...) \
14411453
BENCHMARK_PRIVATE_DECLARE(_benchmark_) = \
14421454
(::benchmark::internal::RegisterBenchmarkInternal( \
14431455
std::make_unique<::benchmark::internal::FunctionBenchmark>( \
14441456
#__VA_ARGS__, __VA_ARGS__)))
1457+
#endif
14451458

14461459
// Old-style macros
14471460
#define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))

0 commit comments

Comments
 (0)