Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
make -j

- name: Run tests
run: |
run: |
Comment thread
GuillaumeLagrange marked this conversation as resolved.
cd core/build-tests
GTEST_OUTPUT=json:test-results/ ctest

Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
- name: Build benchmark example
run: |
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=${{ matrix.codspeed-mode }} --@codspeed_core//:strict_warnings=on

- name: Run the benchmarks
uses: CodSpeedHQ/action@main
if: matrix.codspeed-mode != 'off'
Expand Down Expand Up @@ -207,3 +207,59 @@ jobs:
- name: Build benchmark example
run: |
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=${{ matrix.codspeed-mode }} --@codspeed_core//:strict_warnings=on

macos-walltime-cmake-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Build benchmark example
run: |
mkdir -p examples/google_benchmark_cmake/build
cd examples/google_benchmark_cmake/build
cmake -DCODSPEED_MODE=walltime ..
make -j

- name: Run the benchmarks
uses: CodSpeedHQ/action@main
env:
CODSPEED_SKIP_UPLOAD: "true"
with:
run: examples/google_benchmark_cmake/build/benchmark_example --benchmark_filter=Fibo
mode: walltime
# TODO: Remove this once the runner has been released with macos support
runner-version: branch:main

macos-walltime-bazel-test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Set up Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true

- name: Build benchmark example
run: |
bazel build //examples/google_benchmark_bazel:my_benchmark --@codspeed_core//:codspeed_mode=walltime --@codspeed_core//:strict_warnings=on

- name: Run the benchmarks
uses: CodSpeedHQ/action@main
env:
CODSPEED_SKIP_UPLOAD: "true"
with:
# Note: using bazel run directly fails with a permission error on `/var/tmp/_bazel_codspeed/`
# 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.
# For now, `$USER` remains the original user, but the program is ran with uid 0 with `sudo --preserve-env`
# This problem is temporary because the runner does not YET do the same uid/gid spoofing on macos as it does on linux.
run: ./bazel-bin/examples/google_benchmark_bazel/my_benchmark --benchmark_filter=Fibo
mode: walltime
# TODO: Remove this once the runner has been released with macos support
runner-version: branch:main
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ repos:
hooks:
- id: clang-format
files: \.(cpp|cc|cxx|h|hpp)$
- repo: https://github.com/BlankSpruce/gersemi-pre-commit
rev: 0.27.2
hooks:
- id: gersemi
8 changes: 8 additions & 0 deletions core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ config_setting(
constraint_values = ["@platforms//os:windows"],
)

config_setting(
name = "macos",
constraint_values = ["@platforms//os:macos"],
)

# Strict warnings mode
string_flag(
name = "strict_warnings",
Expand Down Expand Up @@ -100,6 +105,9 @@ cc_library(
copts = select({
":windows": ["/std:c++17"],
"//conditions:default": ["-std=c++17"],
}) + select({
":macos": ["-mmacosx-version-min=10.15"],
"//conditions:default": [],
}),
defines = [
"CODSPEED_VERSION=\\\"{}\\\"".format(CODSPEED_VERSION),
Expand Down
75 changes: 42 additions & 33 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(FetchContent)
FetchContent_Declare(
instrument_hooks_repo
GIT_REPOSITORY https://github.com/CodSpeedHQ/instrument-hooks
GIT_TAG 0c971823b17cb5a3bbd0cce4411cbee2c6fe4317
GIT_TAG ecdf31a3afd0fb879823e40df65129ec823d374b
)
FetchContent_MakeAvailable(instrument_hooks_repo)
FetchContent_GetProperties(instrument_hooks_repo)
Expand All @@ -25,17 +25,13 @@ endif()
set(instrument_hooks_SOURCE_DIR ${instrument_hooks_repo_SOURCE_DIR})

# Add the instrument_hooks library
add_library(
instrument_hooks
STATIC
${instrument_hooks_SOURCE_DIR}/dist/core.c
)
add_library(instrument_hooks STATIC ${instrument_hooks_SOURCE_DIR}/dist/core.c)

target_include_directories(
instrument_hooks
PUBLIC
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
$<INSTALL_INTERFACE:includes>
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
$<INSTALL_INTERFACE:includes>
)

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

target_compile_options(
instrument_hooks
PRIVATE
${INSTRUMENT_HOOKS_CFLAGS}
)
target_compile_options(instrument_hooks PRIVATE ${INSTRUMENT_HOOKS_CFLAGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(
instrument_hooks
PRIVATE
/wd4101 # unreferenced local variable (equivalent to -Wno-unused-variable)
/wd4189 # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
/wd4100 # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
/wd4245 # signed/unsigned mismatch
/wd4132 # const object should be initialized
/wd4146 # unary minus operator applied to unsigned type
/wd4101 # unreferenced local variable (equivalent to -Wno-unused-variable)
/wd4189 # local variable is initialized but not referenced (equivalent to -Wno-unused-but-set-variable)
/wd4100 # unreferenced formal parameter (equivalent to -Wno-unused-parameter)
/wd4245 # signed/unsigned mismatch
/wd4132 # const object should be initialized
/wd4146 # unary minus operator applied to unsigned type
)
endif()


# Add the main library
add_library(
codspeed
Expand All @@ -99,24 +90,32 @@ add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")
# Collect compiler toolchain information for environment reporting
# Use the shared detect_toolchain.sh script (same as Bazel) for consistent output
execute_process(
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_toolchain.sh"
"${CMAKE_CXX_COMPILER}" "${CMAKE_BUILD_TYPE}"
COMMAND
bash "${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_toolchain.sh"
"${CMAKE_CXX_COMPILER}" "${CMAKE_BUILD_TYPE}"
OUTPUT_VARIABLE CODSPEED_TOOLCHAIN_HEADER
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE DETECT_TOOLCHAIN_RESULT
)
if(DETECT_TOOLCHAIN_RESULT EQUAL 0)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/toolchain_info.h" "${CODSPEED_TOOLCHAIN_HEADER}\n")
file(
WRITE "${CMAKE_CURRENT_BINARY_DIR}/toolchain_info.h"
"${CODSPEED_TOOLCHAIN_HEADER}\n"
)
else()
message(WARNING "detect_toolchain.sh failed, toolchain info will not be available")
message(
WARNING
"detect_toolchain.sh failed, toolchain info will not be available"
)
endif()
target_include_directories(codspeed PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")

# Specify the include directories for users of the library
target_include_directories(
codspeed
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${instrument_hooks_SOURCE_DIR}/includes>
)

# Disable valgrind compilation errors
Expand Down Expand Up @@ -159,7 +158,13 @@ target_compile_definitions(

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

set(CODSPEED_MODE_ALLOWED_VALUES "off" "instrumentation" "simulation" "memory" "walltime")
set(CODSPEED_MODE_ALLOWED_VALUES
"off"
"instrumentation"
"simulation"
"memory"
"walltime"
)
set(CODSPEED_MODE "off" CACHE STRING "Build mode for Codspeed")
set_property(
CACHE CODSPEED_MODE
Expand All @@ -168,7 +173,10 @@ set_property(

if(NOT CODSPEED_MODE STREQUAL "off")
target_compile_definitions(codspeed PUBLIC -DCODSPEED_ENABLED)
target_compile_definitions(codspeed PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}")
target_compile_definitions(
codspeed
PUBLIC -DCODSPEED_MODE_DISPLAY="${CODSPEED_MODE}"
)

if(NOT CMAKE_BUILD_TYPE)
message(
Expand All @@ -183,11 +191,12 @@ if(NOT CODSPEED_MODE STREQUAL "off")
endif()

# Define a preprocessor macro based on the build mode
if(CODSPEED_MODE STREQUAL "instrumentation" OR CODSPEED_MODE STREQUAL "simulation" OR CODSPEED_MODE STREQUAL "memory")
target_compile_definitions(
codspeed
PUBLIC -DCODSPEED_ANALYSIS
)
if(
CODSPEED_MODE STREQUAL "instrumentation"
OR CODSPEED_MODE STREQUAL "simulation"
OR CODSPEED_MODE STREQUAL "memory"
)
target_compile_definitions(codspeed PUBLIC -DCODSPEED_ANALYSIS)
elseif(CODSPEED_MODE STREQUAL "walltime")
target_compile_definitions(codspeed PUBLIC -DCODSPEED_WALLTIME)
else()
Comment thread
GuillaumeLagrange marked this conversation as resolved.
Expand Down
4 changes: 2 additions & 2 deletions core/include/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inline void measurement_set_metadata() {
instrument_hooks_set_environment(g_hooks, "cpp", "build_type",
CODSPEED_BUILD_TYPE);
#endif
instrument_hooks_write_environment(g_hooks, static_cast<uint32_t>(getpid()));
instrument_hooks_write_environment(g_hooks, getpid());
}

ALWAYS_INLINE void measurement_start() {
Expand All @@ -75,7 +75,7 @@ ALWAYS_INLINE uint64_t measurement_current_timestamp() {

ALWAYS_INLINE uint8_t measurement_add_marker(uint8_t marker_type,
uint64_t timestamp) {
auto pid = static_cast<uint32_t>(getpid());
auto pid = getpid();
return instrument_hooks_add_marker(g_hooks, pid, marker_type, timestamp);
}

Expand Down
18 changes: 6 additions & 12 deletions core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(googletest)

add_executable(unit_tests
uri.cpp
codspeed.cpp
walltime.cpp
)
add_executable(unit_tests uri.cpp codspeed.cpp walltime.cpp)

target_include_directories(unit_tests PRIVATE ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(unit_tests
PRIVATE
codspeed
GTest::gtest
GTest::gtest_main
target_link_libraries(
unit_tests
PRIVATE codspeed GTest::gtest GTest::gtest_main
)

# Treat warnings as errors for tests to catch issues early
if(MSVC)
target_compile_options(unit_tests PRIVATE /W4 /WX)
target_compile_options(unit_tests PRIVATE /W4 /WX)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(unit_tests PRIVATE -Wall -Wextra -Werror)
target_compile_options(unit_tests PRIVATE -Wall -Wextra -Werror)
endif()

include(GoogleTest)
Expand Down
Loading