Skip to content

Commit d835807

Browse files
feat(google_benchmark): add file name to benchmark URI
1 parent 472d164 commit d835807

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

google_benchmark/cmake/Codspeed.cmake

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
# Step 1: Check if CODSPEED_MODE is set via the command line
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+
RESULT_VARIABLE GIT_COMMAND_RESULT
8+
)
9+
10+
if(NOT GIT_COMMAND_RESULT EQUAL 0)
11+
message(
12+
WARNING
13+
"Failed to determine the git root directory.\
14+
Check that git is in your PATH, and that you are in a git repository.\
15+
Continuing, but codspeed features will not be useable"
16+
)
17+
# Default to user's cmake source directory
18+
set(GIT_ROOT_DIR ${CMAKE_SOURCE_DIR})
19+
endif()
20+
21+
target_compile_definitions(
22+
codspeed
23+
INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}"
24+
)
225

326
if(DEFINED CODSPEED_MODE)
427
# Define a preprocessor macro based on the build mode

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)