diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce9eac9..95fc828 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: make -j - name: Run tests - run: | + run: | cd core/build-tests GTEST_OUTPUT=json:test-results/ ctest @@ -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' @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 86c6f70..fd34238 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/core/BUILD b/core/BUILD index 0e1a575..ee3abf3 100644 --- a/core/BUILD +++ b/core/BUILD @@ -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", @@ -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), diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 950aca3..308cf0d 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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) @@ -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 - $ - $ + $ + $ ) # Option to enable strict warnings (for CI builds) @@ -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 @@ -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 $ - $ + PUBLIC + $ + $ ) # Disable valgrind compilation errors @@ -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 @@ -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( @@ -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() diff --git a/core/include/measurement.hpp b/core/include/measurement.hpp index ae773db..eb676e7 100644 --- a/core/include/measurement.hpp +++ b/core/include/measurement.hpp @@ -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(getpid())); + instrument_hooks_write_environment(g_hooks, getpid()); } ALWAYS_INLINE void measurement_start() { @@ -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(getpid()); + auto pid = getpid(); return instrument_hooks_add_marker(g_hooks, pid, marker_type, timestamp); } diff --git a/core/instrument-hooks b/core/instrument-hooks index 0c97182..ecdf31a 160000 --- a/core/instrument-hooks +++ b/core/instrument-hooks @@ -1 +1 @@ -Subproject commit 0c971823b17cb5a3bbd0cce4411cbee2c6fe4317 +Subproject commit ecdf31a3afd0fb879823e40df65129ec823d374b diff --git a/core/test/CMakeLists.txt b/core/test/CMakeLists.txt index 9266e20..c67157f 100644 --- a/core/test/CMakeLists.txt +++ b/core/test/CMakeLists.txt @@ -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)