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
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Codspeed C++

## Release

For now, releasing is done manually, by tagging a git rev with vX.Y.Z.

When releasing a new version, please make sure the [version](https://github.com/CodSpeedHQ/codspeed-cpp/blob/fix-walltime-pid/core/CMakeLists.txt#L3) is updated in the `core/CMakeLists.txt` file to match the pushed version
71 changes: 67 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,83 @@ add_library(codspeed src/codspeed.cpp src/walltime.cpp src/uri.cpp)
# Version
add_compile_definitions(CODSPEED_VERSION="${CODSPEED_VERSION}")

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

# Disable valgrind compilation errors
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Disable the old-style-cast warning for the specific target
target_compile_options(codspeed PRIVATE -Wno-old-style-cast)
endif()

# Specify the include directories for users of the library
target_include_directories(
execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE GIT_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COMMAND_RESULT
)

if(NOT GIT_COMMAND_RESULT EQUAL 0)
message(
WARNING
"Failed to determine the git root directory.\
Check that git is in your PATH, and that you are in a git repository.\
Continuing, but codspeed features will not be useable"
)
# Default to user's cmake source directory
set(GIT_ROOT_DIR ${CMAKE_SOURCE_DIR})
endif()

target_compile_definitions(
codspeed
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}"
)

set(CODSPEED_MODE_ALLOWED_VALUES "OFF" "instrumentation" "walltime")
set(CODSPEED_MODE "OFF" CACHE STRING "Build mode for Codspeed")
set_property(
CACHE CODSPEED_MODE
PROPERTY STRINGS ${CODSPEED_MODE_ALLOWED_VALUES}
)

if(NOT CODSPEED_MODE STREQUAL "OFF")
target_compile_definitions(codspeed INTERFACE -DCODSPEED_ENABLED)

if(NOT CMAKE_BUILD_TYPE)
message(
WARNING
"CMAKE_BUILD_TYPE is not set. Consider setting it to 'RelWithDebInfo'."
)
elseif(NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(
WARNING
"CMAKE_BUILD_TYPE is set to '${CMAKE_BUILD_TYPE}', but 'RelWithDebInfo' is recommended."
)
endif()

# Define a preprocessor macro based on the build mode
if(CODSPEED_MODE STREQUAL "instrumentation")
target_compile_definitions(
codspeed
INTERFACE -DCODSPEED_INSTRUMENTATION
)
elseif(CODSPEED_MODE STREQUAL "walltime")
target_compile_definitions(codspeed INTERFACE -DCODSPEED_WALLTIME)
else()
message(
FATAL_ERROR
"Invalid build mode: ${CODSPEED_MODE}. Use one of ${CODSPEED_MODE_ALLOWED_VALUES}."
)
endif()
endif()

message(STATUS "Codspeed mode: ${CODSPEED_MODE}")

option(ENABLE_TESTS "Enable building the unit tests which depend on gtest" OFF)
if(ENABLE_TESTS)
enable_testing()
enable_testing()
add_subdirectory(test)
endif()
12 changes: 10 additions & 2 deletions core/src/walltime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
#include <numeric>
#include <sstream>
#include <string>
#include <thread>
#ifdef _WIN32
#include <process.h>
#else
#include <unistd.h>
#endif
#include <vector>

const double IQR_OUTLIER_FACTOR = 1.5;
Expand Down Expand Up @@ -105,7 +109,11 @@ void write_codspeed_benchmarks_to_json(

std::string creator_name = "codspeed-cpp";
std::string creator_version = CODSPEED_VERSION;
std::thread::id creator_pid = std::this_thread::get_id();
#ifdef _WIN32
pid_t creator_pid = _getpid();
#else
pid_t creator_pid = getpid();
#endif
std::string instrument_type = "walltime";

oss << "{\n";
Expand Down
3 changes: 3 additions & 0 deletions examples/google_benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ include(FetchContent)

project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)

# On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected.
set(CMAKE_BUILD_TYPE RelWithDebInfo)

option(BENCHMARK_ENABLE_GTEST_TESTS OFF)

FetchContent_Declare(
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
'';
};

clang = pkgs.mkShell {
buildInputs = with pkgs; [ clang ] ++ commonBuildInputs;
shellHook = ''
export CXX=clang++;
echo "Welcome to the C++ development environment with Clang!"
'';
};

lsp = pkgs.mkShell {
buildInputs =
with pkgs;
Expand Down
43 changes: 0 additions & 43 deletions google_benchmark/cmake/Codspeed.cmake
Original file line number Diff line number Diff line change
@@ -1,44 +1 @@
add_subdirectory(${PROJECT_SOURCE_DIR}/../core codspeed)

execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE GIT_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_COMMAND_RESULT
)

if(NOT GIT_COMMAND_RESULT EQUAL 0)
message(
WARNING
"Failed to determine the git root directory.\
Check that git is in your PATH, and that you are in a git repository.\
Continuing, but codspeed features will not be useable"
)
# Default to user's cmake source directory
set(GIT_ROOT_DIR ${CMAKE_SOURCE_DIR})
endif()

target_compile_definitions(
codspeed
INTERFACE -DCODSPEED_GIT_ROOT_DIR="${GIT_ROOT_DIR}"
)

if(DEFINED CODSPEED_MODE)
target_compile_definitions(codspeed INTERFACE -DCODSPEED_ENABLED)
# Define a preprocessor macro based on the build mode
if(CODSPEED_MODE STREQUAL "instrumentation")
target_compile_definitions(
codspeed
INTERFACE -DCODSPEED_INSTRUMENTATION
)
elseif(CODSPEED_MODE STREQUAL "walltime")
target_compile_definitions(codspeed INTERFACE -DCODSPEED_WALLTIME)
else()
message(
FATAL_ERROR
"Invalid build mode: ${CODSPEED_MODE}. Use 'instrumentation' or 'walltime'."
)
endif()
endif()

message(STATUS "Build mode set to: ${CODSPEED_MODE}")
1 change: 1 addition & 0 deletions google_benchmark/src/benchmark_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BenchmarkInstance {
const std::vector<Statistics>& statistics() const { return statistics_; }
int repetitions() const {
#ifdef CODSPEED_INSTRUMENTATION
(void)repetitions_;
return 1;
#else
return repetitions_;
Expand Down