Skip to content

Commit de91ac0

Browse files
feat: bump instrument-hooks to use int32_t for pid
1 parent d57b59f commit de91ac0

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

core/CMakeLists.txt

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include(FetchContent)
1515
FetchContent_Declare(
1616
instrument_hooks_repo
1717
GIT_REPOSITORY https://github.com/CodSpeedHQ/instrument-hooks
18-
GIT_TAG 4376be3e1e2d0e0c82d690bcb8e54bde98b7805c
18+
GIT_TAG ecdf31a3afd0fb879823e40df65129ec823d374b
1919
)
2020
FetchContent_MakeAvailable(instrument_hooks_repo)
2121
FetchContent_GetProperties(instrument_hooks_repo)
@@ -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
@@ -99,24 +90,32 @@ add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")
9990
# Collect compiler toolchain information for environment reporting
10091
# Use the shared detect_toolchain.sh script (same as Bazel) for consistent output
10192
execute_process(
102-
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_toolchain.sh"
103-
"${CMAKE_CXX_COMPILER}" "${CMAKE_BUILD_TYPE}"
93+
COMMAND
94+
bash "${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_toolchain.sh"
95+
"${CMAKE_CXX_COMPILER}" "${CMAKE_BUILD_TYPE}"
10496
OUTPUT_VARIABLE CODSPEED_TOOLCHAIN_HEADER
10597
OUTPUT_STRIP_TRAILING_WHITESPACE
10698
RESULT_VARIABLE DETECT_TOOLCHAIN_RESULT
10799
)
108100
if(DETECT_TOOLCHAIN_RESULT EQUAL 0)
109-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/toolchain_info.h" "${CODSPEED_TOOLCHAIN_HEADER}\n")
101+
file(
102+
WRITE "${CMAKE_CURRENT_BINARY_DIR}/toolchain_info.h"
103+
"${CODSPEED_TOOLCHAIN_HEADER}\n"
104+
)
110105
else()
111-
message(WARNING "detect_toolchain.sh failed, toolchain info will not be available")
106+
message(
107+
WARNING
108+
"detect_toolchain.sh failed, toolchain info will not be available"
109+
)
112110
endif()
113111
target_include_directories(codspeed PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
114112

115113
# Specify the include directories for users of the library
116114
target_include_directories(
117115
codspeed
118-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
119-
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
116+
PUBLIC
117+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
118+
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
120119
)
121120

122121
# Disable valgrind compilation errors
@@ -159,7 +158,13 @@ target_compile_definitions(
159158

160159
message(STATUS "Using codspeed root directory: ${CODSPEED_ROOT_DIR}")
161160

162-
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+
)
163168
set(CODSPEED_MODE "off" CACHE STRING "Build mode for Codspeed")
164169
set_property(
165170
CACHE CODSPEED_MODE
@@ -168,7 +173,10 @@ set_property(
168173

169174
if(NOT CODSPEED_MODE STREQUAL "off")
170175
target_compile_definitions(codspeed PUBLIC -DCODSPEED_ENABLED)
171-
target_compile_definitions(codspeed PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}")
176+
target_compile_definitions(
177+
codspeed
178+
PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}"
179+
)
172180

173181
if(NOT CMAKE_BUILD_TYPE)
174182
message(
@@ -183,11 +191,12 @@ if(NOT CODSPEED_MODE STREQUAL "off")
183191
endif()
184192

185193
# Define a preprocessor macro based on the build mode
186-
if(CODSPEED_MODE STREQUAL "instrumentation" OR CODSPEED_MODE STREQUAL "simulation" OR CODSPEED_MODE STREQUAL "memory")
187-
target_compile_definitions(
188-
codspeed
189-
PUBLIC -DCODSPEED_ANALYSIS
190-
)
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)
191200
elseif(CODSPEED_MODE STREQUAL "walltime")
192201
target_compile_definitions(codspeed PUBLIC -DCODSPEED_WALLTIME)
193202
else()

core/include/measurement.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline void measurement_set_metadata() {
5353
instrument_hooks_set_environment(g_hooks, "cpp", "build_type",
5454
CODSPEED_BUILD_TYPE);
5555
#endif
56-
instrument_hooks_write_environment(g_hooks, static_cast<uint32_t>(getpid()));
56+
instrument_hooks_write_environment(g_hooks, getpid());
5757
}
5858

5959
ALWAYS_INLINE void measurement_start() {
@@ -65,7 +65,7 @@ ALWAYS_INLINE void measurement_stop() {
6565
}
6666

6767
ALWAYS_INLINE void measurement_set_executed_benchmark(const std::string& name) {
68-
auto current_pid = static_cast<uint32_t>(getpid());
68+
auto current_pid = getpid();
6969
instrument_hooks_executed_benchmark(g_hooks, current_pid, name.c_str());
7070
}
7171

@@ -75,7 +75,7 @@ ALWAYS_INLINE uint64_t measurement_current_timestamp() {
7575

7676
ALWAYS_INLINE uint8_t measurement_add_marker(uint8_t marker_type,
7777
uint64_t timestamp) {
78-
auto pid = static_cast<uint32_t>(getpid());
78+
auto pid = getpid();
7979
return instrument_hooks_add_marker(g_hooks, pid, marker_type, timestamp);
8080
}
8181

0 commit comments

Comments
 (0)