Skip to content

Commit a9eac46

Browse files
feat: add toolchain environment collection to CMake build
1 parent 84fcc36 commit a9eac46

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

core/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
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 89fb72a076ec71c9eca6eee9bca98bada4b4dfb4
18+
GIT_TAG e86719c70c9c0b1646db182a7c748230e243dace
1919
)
2020
FetchContent_MakeAvailable(instrument_hooks_repo)
2121
FetchContent_GetProperties(instrument_hooks_repo)
@@ -96,6 +96,25 @@ target_link_libraries(codspeed PRIVATE instrument_hooks)
9696
# Version
9797
add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")
9898

99+
# Collect compiler toolchain information for environment reporting
100+
execute_process(
101+
COMMAND ${CMAKE_CXX_COMPILER} --version
102+
OUTPUT_VARIABLE CODSPEED_CXX_COMPILER_FULL_VERSION
103+
OUTPUT_STRIP_TRAILING_WHITESPACE
104+
ERROR_QUIET
105+
)
106+
# Extract first line only
107+
if(CODSPEED_CXX_COMPILER_FULL_VERSION)
108+
string(REGEX REPLACE "\n.*" "" CODSPEED_CXX_COMPILER_FULL_VERSION "${CODSPEED_CXX_COMPILER_FULL_VERSION}")
109+
endif()
110+
111+
target_compile_definitions(codspeed PRIVATE
112+
CODSPEED_CXX_COMPILER_ID="${CMAKE_CXX_COMPILER_ID}"
113+
CODSPEED_CXX_COMPILER_VERSION="${CMAKE_CXX_COMPILER_VERSION}"
114+
CODSPEED_CXX_COMPILER_FULL_VERSION="${CODSPEED_CXX_COMPILER_FULL_VERSION}"
115+
CODSPEED_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
116+
)
117+
99118
# Specify the include directories for users of the library
100119
target_include_directories(
101120
codspeed

core/include/measurement.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ inline bool measurement_is_instrumented() {
3535
inline void measurement_set_metadata() {
3636
std::string version = get_version();
3737
instrument_hooks_set_integration(g_hooks, "codspeed-cpp", version.c_str());
38+
39+
// Report C++ toolchain information
40+
#ifdef CODSPEED_CXX_COMPILER_ID
41+
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "compiler_id",
42+
CODSPEED_CXX_COMPILER_ID);
43+
#endif
44+
#ifdef CODSPEED_CXX_COMPILER_VERSION
45+
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "version",
46+
CODSPEED_CXX_COMPILER_VERSION);
47+
#endif
48+
#ifdef CODSPEED_CXX_COMPILER_FULL_VERSION
49+
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "build",
50+
CODSPEED_CXX_COMPILER_FULL_VERSION);
51+
#endif
52+
#ifdef CODSPEED_BUILD_TYPE
53+
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "build_type",
54+
CODSPEED_BUILD_TYPE);
55+
#endif
56+
instrument_hooks_write_environment(g_hooks, static_cast<uint32_t>(getpid()));
3857
}
3958

4059
ALWAYS_INLINE void measurement_start() {
@@ -55,7 +74,7 @@ ALWAYS_INLINE uint64_t measurement_current_timestamp() {
5574
}
5675

5776
ALWAYS_INLINE uint8_t measurement_add_marker(uint8_t marker_type,
58-
uint64_t timestamp) {
77+
uint64_t timestamp) {
5978
auto pid = static_cast<uint32_t>(getpid());
6079
return instrument_hooks_add_marker(g_hooks, pid, marker_type, timestamp);
6180
}

0 commit comments

Comments
 (0)