Skip to content

Commit 198b668

Browse files
committed
Merge remote-tracking branch 'origin/main' into cod-2033-codspeed-cpp-includes-setupteardown-in-instrumentation-mode
# Conflicts: # core/CMakeLists.txt
2 parents eafc113 + f5a917f commit 198b668

13 files changed

Lines changed: 386 additions & 50 deletions

File tree

.github/workflows/ci.yml

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ jobs:
1919
with:
2020
extra_args: --all-files
2121

22+
toolchain-detection-tests:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Run toolchain detection tests
27+
run: bash core/scripts/test_detect_toolchain.sh
28+
2229
tests:
2330
runs-on: ubuntu-latest
24-
steps:
31+
steps:
2532
- name: Checkout code
2633
uses: actions/checkout@v3
2734
with:
@@ -43,7 +50,7 @@ jobs:
4350
make -j
4451
4552
- name: Run tests
46-
run: |
53+
run: |
4754
cd core/build-tests
4855
GTEST_OUTPUT=json:test-results/ ctest
4956
@@ -126,7 +133,7 @@ jobs:
126133
- name: Build benchmark example
127134
run: |
128135
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=${{ matrix.codspeed-mode }} --@codspeed_core//:strict_warnings=on
129-
136+
130137
- name: Run the benchmarks
131138
uses: CodSpeedHQ/action@main
132139
if: matrix.codspeed-mode != 'off'
@@ -200,3 +207,56 @@ jobs:
200207
- name: Build benchmark example
201208
run: |
202209
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=${{ matrix.codspeed-mode }} --@codspeed_core//:strict_warnings=on
210+
211+
macos-walltime-cmake-test:
212+
runs-on: macos-latest
213+
steps:
214+
- uses: actions/checkout@v4
215+
with:
216+
submodules: "recursive"
217+
218+
- name: Build benchmark example
219+
run: |
220+
mkdir -p examples/google_benchmark_cmake/build
221+
cd examples/google_benchmark_cmake/build
222+
cmake -DCODSPEED_MODE=walltime ..
223+
make -j
224+
225+
- name: Run the benchmarks
226+
uses: CodSpeedHQ/action@main
227+
with:
228+
run: examples/google_benchmark_cmake/build/benchmark_example --benchmark_filter=BM_FibonacciRecursive_Darwin
229+
mode: walltime
230+
# TODO: Remove this once the runner has been released with macos support
231+
runner-version: branch:main
232+
233+
macos-walltime-bazel-test:
234+
runs-on: macos-latest
235+
steps:
236+
- uses: actions/checkout@v4
237+
with:
238+
submodules: "recursive"
239+
240+
- name: Set up Bazel
241+
uses: bazel-contrib/setup-bazel@0.14.0
242+
with:
243+
bazelisk-cache: true
244+
disk-cache: ${{ github.workflow }}
245+
repository-cache: true
246+
247+
- name: Build benchmark example
248+
run: |
249+
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=walltime --@codspeed_core//:strict_warnings=on
250+
251+
- name: Run the benchmarks
252+
uses: CodSpeedHQ/action@main
253+
with:
254+
# Note: using bazel run directly fails with a permission error on `/var/tmp/_bazel_codspeed/`
255+
# This is because bazel does not like the user switch between running `bazel build` as a user then running `bazel run` as sudo and refuses to run.
256+
# For now, `$USER` remains the original user, but the program is ran with uid 0 with `sudo --preserve-env`
257+
# This problem is temporary because the runner does not YET do the same uid/gid spoofing on macos as it does on linux.
258+
#
259+
# BUILD_WORKSPACE_DIRECTORY is normally set by `bazel run`; we set it manually so workspace-relative __FILE__ resolution works when invoking the binary directly.
260+
run: BUILD_WORKSPACE_DIRECTORY=$PWD ./bazel-bin/examples/google_benchmark_bazel/my_benchmark --benchmark_filter=BM_FibonacciRecursive_Darwin
261+
mode: walltime
262+
runner-version: branch:main

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ repos:
1515
hooks:
1616
- id: clang-format
1717
files: \.(cpp|cc|cxx|h|hpp)$
18+
- repo: https://github.com/BlankSpruce/gersemi-pre-commit
19+
rev: 0.27.2
20+
hooks:
21+
- id: gersemi

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@
55

66

77

8+
## [2.4.0] - 2026-06-04
9+
10+
### <!-- 0 -->🚀 Features
11+
- Add Darwin-specific fib variant for macOS flamegraph coverage
12+
13+
### <!-- 4 -->⚡ Performance
14+
- Prevent constant-folding of fib input across iterations
15+
16+
### <!-- 7 -->⚙️ Internals
17+
- Bump instrument-hooks
18+
19+
20+
## [2.3.0] - 2026-04-28
21+
22+
### <!-- 0 -->🚀 Features
23+
- Add cmake formatter to precommit hooks
24+
- Bump instrument-hooks to use int32_t for pid
25+
- Fix bazel build by forcing C++17
26+
27+
### <!-- 7 -->⚙️ Internals
28+
- Add macos integration test
29+
- Explicitly convert pid to unsigned
30+
- Bump instrument-hooks to suppress stub warnings
31+
32+
33+
## [2.2.0] - 2026-04-17
34+
35+
### <!-- 0 -->🚀 Features
36+
- Add toolchain environment collection to bazel
37+
- Add toolchain environment collection to CMake build
38+
39+
### <!-- 1 -->🐛 Bug Fixes
40+
- Use slugged name for environment section
41+
- Fix clang 19 compilation error
42+
43+
### <!-- 7 -->⚙️ Internals
44+
- Bump instrument-hooks to collect runtime libraries
45+
- Use the same logic for toolchain detection
46+
- Stop targeting our fork for BCR PR (#43)
47+
48+
849
## [2.1.0] - 2026-01-21
950

1051
### <!-- 0 -->🚀 Features
@@ -202,6 +243,9 @@
202243
- Import google benchmark "fork"
203244

204245

246+
[2.4.0]: https://github.com/CodSpeedHQ/runner/compare/v2.3.0..v2.4.0
247+
[2.3.0]: https://github.com/CodSpeedHQ/runner/compare/v2.2.0..v2.3.0
248+
[2.2.0]: https://github.com/CodSpeedHQ/runner/compare/v2.1.0..v2.2.0
205249
[2.1.0]: https://github.com/CodSpeedHQ/runner/compare/v2.0.0..v2.1.0
206250
[2.0.0]: https://github.com/CodSpeedHQ/runner/compare/v1.4.1..v2.0.0
207251
[1.4.1]: https://github.com/CodSpeedHQ/runner/compare/v1.4.0..v1.4.1

core/BUILD

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ config_setting(
88
constraint_values = ["@platforms//os:windows"],
99
)
1010

11+
config_setting(
12+
name = "macos",
13+
constraint_values = ["@platforms//os:macos"],
14+
)
15+
1116
# Strict warnings mode
1217
string_flag(
1318
name = "strict_warnings",
@@ -68,6 +73,29 @@ cc_library(
6873
)
6974

7075

76+
# Generate a header with C++ toolchain information
77+
genrule(
78+
name = "toolchain_info_gen",
79+
srcs = ["scripts/detect_toolchain.sh"],
80+
outs = ["toolchain_info.h"],
81+
cmd = """
82+
case "$(COMPILATION_MODE)" in
83+
opt) BUILD_TYPE="Release" ;;
84+
dbg) BUILD_TYPE="Debug" ;;
85+
fastbuild) BUILD_TYPE="FastBuild" ;;
86+
*) BUILD_TYPE="$(COMPILATION_MODE)" ;;
87+
esac
88+
bash $(location scripts/detect_toolchain.sh) "$(CC)" "$$BUILD_TYPE" > $@
89+
""",
90+
toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"],
91+
)
92+
93+
cc_library(
94+
name = "toolchain_info",
95+
hdrs = [":toolchain_info_gen"],
96+
includes = ["."],
97+
)
98+
7199
# Define the codspeed library
72100
cc_library(
73101
name = "codspeed",
@@ -77,6 +105,9 @@ cc_library(
77105
copts = select({
78106
":windows": ["/std:c++17"],
79107
"//conditions:default": ["-std=c++17"],
108+
}) + select({
109+
":macos": ["-mmacosx-version-min=10.15"],
110+
"//conditions:default": [],
80111
}),
81112
defines = [
82113
"CODSPEED_VERSION=\\\"{}\\\"".format(CODSPEED_VERSION),
@@ -87,7 +118,7 @@ cc_library(
87118
":walltime_mode": ["CODSPEED_ENABLED", "CODSPEED_WALLTIME", "CODSPEED_MODE_DISPLAY=\\\"walltime\\\""],
88119
"//conditions:default": [],
89120
}),
90-
deps = [":instrument_hooks"],
121+
deps = [":instrument_hooks", ":toolchain_info"],
91122
visibility = ["//visibility:public"],
92123
)
93124

core/CMakeLists.txt

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
set(CODSPEED_VERSION 2.1.0)
3+
set(CODSPEED_VERSION 2.4.0)
44

55
project(codspeed VERSION ${CODSPEED_VERSION} LANGUAGES CXX C)
66

@@ -25,17 +25,13 @@ endif()
2525
set(instrument_hooks_SOURCE_DIR ${instrument_hooks_repo_SOURCE_DIR})
2626

2727
# Add the instrument_hooks library
28-
add_library(
29-
instrument_hooks
30-
STATIC
31-
${instrument_hooks_SOURCE_DIR}/dist/core.c
32-
)
28+
add_library(instrument_hooks STATIC ${instrument_hooks_SOURCE_DIR}/dist/core.c)
3329

3430
target_include_directories(
3531
instrument_hooks
3632
PUBLIC
37-
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
38-
$<INSTALL_INTERFACE:includes>
33+
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
34+
$<INSTALL_INTERFACE:includes>
3935
)
4036

4137
# Option to enable strict warnings (for CI builds)
@@ -61,25 +57,20 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
6157
list(PREPEND INSTRUMENT_HOOKS_CFLAGS -Wall -Werror)
6258
endif()
6359

64-
target_compile_options(
65-
instrument_hooks
66-
PRIVATE
67-
${INSTRUMENT_HOOKS_CFLAGS}
68-
)
60+
target_compile_options(instrument_hooks PRIVATE ${INSTRUMENT_HOOKS_CFLAGS})
6961
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
7062
target_compile_options(
7163
instrument_hooks
7264
PRIVATE
73-
/wd4101 # unreferenced local variable (equivalent to -Wno-unused-variable)
74-
/wd4189 # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
75-
/wd4100 # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
76-
/wd4245 # signed/unsigned mismatch
77-
/wd4132 # const object should be initialized
78-
/wd4146 # unary minus operator applied to unsigned type
65+
/wd4101 # unreferenced local variable (equivalent to -Wno-unused-variable)
66+
/wd4189 # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
67+
/wd4100 # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
68+
/wd4245 # signed/unsigned mismatch
69+
/wd4132 # const object should be initialized
70+
/wd4146 # unary minus operator applied to unsigned type
7971
)
8072
endif()
8173

82-
8374
# Add the main library
8475
add_library(
8576
codspeed
@@ -96,11 +87,35 @@ target_link_libraries(codspeed PRIVATE instrument_hooks)
9687
# Version
9788
add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")
9889

90+
# Collect compiler toolchain information for environment reporting
91+
# Use the shared detect_toolchain.sh script (same as Bazel) for consistent output
92+
execute_process(
93+
COMMAND
94+
bash "${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_toolchain.sh"
95+
"${CMAKE_CXX_COMPILER}" "${CMAKE_BUILD_TYPE}"
96+
OUTPUT_VARIABLE CODSPEED_TOOLCHAIN_HEADER
97+
OUTPUT_STRIP_TRAILING_WHITESPACE
98+
RESULT_VARIABLE DETECT_TOOLCHAIN_RESULT
99+
)
100+
if(DETECT_TOOLCHAIN_RESULT EQUAL 0)
101+
file(
102+
WRITE "${CMAKE_CURRENT_BINARY_DIR}/toolchain_info.h"
103+
"${CODSPEED_TOOLCHAIN_HEADER}\n"
104+
)
105+
else()
106+
message(
107+
WARNING
108+
"detect_toolchain.sh failed, toolchain info will not be available"
109+
)
110+
endif()
111+
target_include_directories(codspeed PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
112+
99113
# Specify the include directories for users of the library
100114
target_include_directories(
101115
codspeed
102-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
103-
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
116+
PUBLIC
117+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
118+
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
104119
)
105120

106121
# Disable valgrind compilation errors
@@ -143,7 +158,13 @@ target_compile_definitions(
143158

144159
message(STATUS "Using codspeed root directory: ${CODSPEED_ROOT_DIR}")
145160

146-
set(CODSPEED_MODE_ALLOWED_VALUES "off" "instrumentation" "simulation" "memory" "walltime")
161+
set(CODSPEED_MODE_ALLOWED_VALUES
162+
"off"
163+
"instrumentation"
164+
"simulation"
165+
"memory"
166+
"walltime"
167+
)
147168
set(CODSPEED_MODE "off" CACHE STRING "Build mode for Codspeed")
148169
set_property(
149170
CACHE CODSPEED_MODE
@@ -152,7 +173,10 @@ set_property(
152173

153174
if(NOT CODSPEED_MODE STREQUAL "off")
154175
target_compile_definitions(codspeed PUBLIC -DCODSPEED_ENABLED)
155-
target_compile_definitions(codspeed PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}")
176+
target_compile_definitions(
177+
codspeed
178+
PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}"
179+
)
156180

157181
if(NOT CMAKE_BUILD_TYPE)
158182
message(
@@ -167,11 +191,12 @@ if(NOT CODSPEED_MODE STREQUAL "off")
167191
endif()
168192

169193
# Define a preprocessor macro based on the build mode
170-
if(CODSPEED_MODE STREQUAL "instrumentation" OR CODSPEED_MODE STREQUAL "simulation" OR CODSPEED_MODE STREQUAL "memory")
171-
target_compile_definitions(
172-
codspeed
173-
PUBLIC -DCODSPEED_ANALYSIS
174-
)
194+
if(
195+
CODSPEED_MODE STREQUAL "instrumentation"
196+
OR CODSPEED_MODE STREQUAL "simulation"
197+
OR CODSPEED_MODE STREQUAL "memory"
198+
)
199+
target_compile_definitions(codspeed PUBLIC -DCODSPEED_ANALYSIS)
175200
elseif(CODSPEED_MODE STREQUAL "walltime")
176201
target_compile_definitions(codspeed PUBLIC -DCODSPEED_WALLTIME)
177202
else()

core/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = "codspeed_core",
3-
version = "2.1.0",
3+
version = "2.4.0",
44
)
55

66
bazel_dep(name = "rules_cc", version = "0.0.17")

0 commit comments

Comments
 (0)