From c33ba0c30dd4ab4c1879f320c0f5fd6dba5f03ef Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 28 Nov 2022 14:56:10 +0100 Subject: [PATCH 1/9] Bumped CMake required version as CMake 3.25 introduces generator expressions in compiler launcher setting --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2db7a..98b78bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.25) project(ctbench VERSION 0.1.0) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) From cdc9e6bd1c6eaa6ed3046f0c69dd4477dd5fd1fd Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 29 Nov 2022 10:45:11 +0100 Subject: [PATCH 2/9] Changed argument ordering --- cmake/install.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/install.cmake b/cmake/install.cmake index 1a5cf70..3b10b05 100644 --- a/cmake/install.cmake +++ b/cmake/install.cmake @@ -9,8 +9,9 @@ export(EXPORT ctbench-targets FILE ctbench-targets.cmake) install( EXPORT ctbench-targets - DESTINATION ${ConfigPackageLocation} - NAMESPACE ctbench::) + NAMESPACE ctbench:: + DESTINATION ${ConfigPackageLocation}) + install(FILES cmake/ctbench-api.cmake DESTINATION ${ConfigPackageLocation}) # CMake package config files From 0d98ac5eeae566e6144962338726d56501d1e597 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 29 Nov 2022 10:46:35 +0100 Subject: [PATCH 3/9] Working towards a more unified target management using FetchContent and FindPackage --- cmake/ctbench-api.cmake | 51 ++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/cmake/ctbench-api.cmake b/cmake/ctbench-api.cmake index 118d7aa..6fa331a 100644 --- a/cmake/ctbench-api.cmake +++ b/cmake/ctbench-api.cmake @@ -12,31 +12,18 @@ #@ #@ Sets ctbench executable/target prefixes for FetchContent support. -function(_ctbench_set_prefixes) - if(ctbench_FOUND) - # ctbench_FOUND being true means ctbench found through find_package. - - set(GRAPHER_PREFIX - ctbench:: - CACHE STRING "Prefix for grapher executables") - - # ttw is a special case as it is used as a compiler launcher. - # Therefore we can't use the imported executable target, - # and have to provide an executable name assuming ttw can be found in PATH. - set(TTW_PREFIX - "" - CACHE STRING "Prefix for TTW executable") - else() - # ctbench_FOUND being false means ctbench was imported inside of the tree. - - set(GRAPHER_PREFIX - ${CMAKE_CURRENT_BINARY_DIR}/grapher/ - CACHE STRING "Prefix for grapher executables") - - set(TTW_PREFIX - ${CMAKE_CURRENT_BINARY_DIR}/ttw/ - CACHE STRING "Prefix for TTW executable") - endif() +function(_ctbench_set_variables) + # if(TARGET ctbench::ctbench-grapher-plot) + # # message("Setting CTBENCH_GRAPHER_PLOT_EXEC") + # # set(CTBENCH_GRAPHER_PLOT_EXEC "$" CACHE STRING "Path to ctbench-grapher-plot executable") + # else() + # message(relou) + # endif() + # + # if(TARGET ctbench::ctbench-ttw) + # message("Setting CTBENCH_GRAPHER_TTW_EXEC") + # set(CTBENCH_GRAPHER_TTW_EXEC "$" CACHE STRING "Path to ctbench-ttw executable") + # endif() endfunction() #@ @@ -56,15 +43,16 @@ endfunction() function(_ctbench_internal_add_compile_benchmark target_name output source options) - _ctbench_set_prefixes() + _ctbench_set_variables() add_library(${target_name} OBJECT EXCLUDE_FROM_ALL ${source}) target_include_directories(${target_name} PUBLIC "../include") # Setting ctbench-ttw as a compiler launcher set_target_properties( ${target_name} PROPERTIES CXX_COMPILER_LAUNCHER - "${TTW_PREFIX}ctbench-ttw;${output}") + "$;${output}") + # Make sure ttw is built even when ctbench is imported using FetchContent if(NOT ctbench_FOUND) add_dependencies(${target_name} ctbench-ttw) endif() @@ -117,7 +105,7 @@ function( end step samples) - _ctbench_set_prefixes() + _ctbench_set_variables() # Setting names add_custom_target(${name}) @@ -162,7 +150,7 @@ function( step samples generator) - _ctbench_set_prefixes() + _ctbench_set_variables() # Setting names add_custom_target(${name}) @@ -200,12 +188,13 @@ endfunction(ctbench_add_custom_benchmark) #! - `benchmarks...`: List of benchmark names function(ctbench_add_graph category config) - _ctbench_set_prefixes() + _ctbench_set_variables() set(config_path ${CMAKE_CURRENT_SOURCE_DIR}/${config}) add_custom_target( ${category} - COMMAND ${GRAPHER_PREFIX}ctbench-grapher-plot --output=${category} + # COMMAND ${CTBENCH_GRAPHER_PLOT_EXEC} --output=${category} + COMMAND ctbench::ctbench-grapher-plot --output=${category} --config=${config_path} ${ARGN} DEPENDS ${config_path} ${ARGN} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) From 3791800f68ed9a7fcef5340ebee508d6b44533ba Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 29 Nov 2022 10:48:26 +0100 Subject: [PATCH 4/9] Removed empty ttw test file --- ttw/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ttw/CMakeLists.txt b/ttw/CMakeLists.txt index 5588c12..95970e8 100644 --- a/ttw/CMakeLists.txt +++ b/ttw/CMakeLists.txt @@ -1,9 +1,3 @@ add_executable(ctbench-ttw ttw.cpp) target_link_libraries(ctbench-ttw PRIVATE ctbench-compile-opts) target_include_directories(ctbench-ttw PRIVATE include) - -if(BUILD_TESTING) - add_executable(ctbench-ttw-test-exec tests/ttw.cpp) - target_include_directories(ctbench-ttw-test-exec PRIVATE include) - add_test(NAME ctbench-ttw-test COMMAND ctbench-ttw-test-exec) -endif(BUILD_TESTING) From e9c9e16babcea74022407c9d9899217420cdd17b Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 5 Dec 2022 13:49:16 +0100 Subject: [PATCH 5/9] Dropped fetchcontent compatibility --- cmake/ctbench-api.cmake | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/cmake/ctbench-api.cmake b/cmake/ctbench-api.cmake index 6fa331a..4b6c9ea 100644 --- a/cmake/ctbench-api.cmake +++ b/cmake/ctbench-api.cmake @@ -6,29 +6,6 @@ #@ ## ============================================================================= -## ============================================================================= -#@ -#@ _ctbench_internal_add_compile_benchmark -#@ -#@ Sets ctbench executable/target prefixes for FetchContent support. - -function(_ctbench_set_variables) - # if(TARGET ctbench::ctbench-grapher-plot) - # # message("Setting CTBENCH_GRAPHER_PLOT_EXEC") - # # set(CTBENCH_GRAPHER_PLOT_EXEC "$" CACHE STRING "Path to ctbench-grapher-plot executable") - # else() - # message(relou) - # endif() - # - # if(TARGET ctbench::ctbench-ttw) - # message("Setting CTBENCH_GRAPHER_TTW_EXEC") - # set(CTBENCH_GRAPHER_TTW_EXEC "$" CACHE STRING "Path to ctbench-ttw executable") - # endif() -endfunction() - -#@ -#@ -- - ## ============================================================================= #@ #@ _ctbench_internal_add_compile_benchmark @@ -52,11 +29,6 @@ function(_ctbench_internal_add_compile_benchmark target_name output source ${target_name} PROPERTIES CXX_COMPILER_LAUNCHER "$;${output}") - # Make sure ttw is built even when ctbench is imported using FetchContent - if(NOT ctbench_FOUND) - add_dependencies(${target_name} ctbench-ttw) - endif() - # Pass benchmark size target_compile_options(${target_name} PRIVATE ${options}) From f481e0db32fb3253c3199c91ba89ce6e191f8305 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 5 Dec 2022 13:53:52 +0100 Subject: [PATCH 6/9] Removed fetchcontent instructions from readme --- readme.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 55fbdc3..1204eb3 100644 --- a/readme.md +++ b/readme.md @@ -26,21 +26,19 @@ reference project for using ctbench. ## Using ctbench -### Integrating ctbench in your project - -You can integrate `ctbench` by adding this into your CMake listfiles: - -```cmake -include(FetchContent) -FetchContent_Declare( - ctbench - GIT_REPOSITORY https://github.com/jpenuchot/ctbench.git - GIT_TAG main - GIT_SHALLOW) -FetchContent_MakeAvailable(ctbench) +### Installing `ctbench` + +```sh +git clone https://github.com/jpenuchot/ctbench +cd ctbench +cmake --preset release +cmake --build --preset release +sudo cmake --build --preset release --target install ``` -or through `find_package(ctbench REQUIRED)` after installing it. +### Integrating `ctbench` in your project + +Use `find_package(ctbench REQUIRED)` after installing it. The [Rule of Cheese](https://github.com/JPenuchot/rule-of-cheese) project can be used as an example of how to use `ctbench`. It is the project that gave birth to From 6497481e69ad0942a7d46e5ea8ba4ebc3043bf8e Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 5 Dec 2022 13:57:16 +0100 Subject: [PATCH 7/9] Removed calls to _ctbench_set_variables --- cmake/ctbench-api.cmake | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmake/ctbench-api.cmake b/cmake/ctbench-api.cmake index 4b6c9ea..37fb663 100644 --- a/cmake/ctbench-api.cmake +++ b/cmake/ctbench-api.cmake @@ -20,7 +20,6 @@ function(_ctbench_internal_add_compile_benchmark target_name output source options) - _ctbench_set_variables() add_library(${target_name} OBJECT EXCLUDE_FROM_ALL ${source}) target_include_directories(${target_name} PUBLIC "../include") @@ -77,7 +76,6 @@ function( end step samples) - _ctbench_set_variables() # Setting names add_custom_target(${name}) @@ -122,8 +120,6 @@ function( step samples generator) - _ctbench_set_variables() - # Setting names add_custom_target(${name}) @@ -160,8 +156,6 @@ endfunction(ctbench_add_custom_benchmark) #! - `benchmarks...`: List of benchmark names function(ctbench_add_graph category config) - _ctbench_set_variables() - set(config_path ${CMAKE_CURRENT_SOURCE_DIR}/${config}) add_custom_target( ${category} From b7d96b540ad5d6e360f27fe61ac0376414da15b5 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 5 Dec 2022 14:35:47 +0100 Subject: [PATCH 8/9] Added instructions for time-trace profiling and plotting --- readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/readme.md b/readme.md index 1204eb3..5c60675 100644 --- a/readme.md +++ b/readme.md @@ -80,6 +80,16 @@ int sum() { } ``` +By default, only compiler execution time is measured. +If you want to generate plots using Clang's builtin profiler, add the following: + +```cmake +add_compile_options(-ftime-trace -ftime-trace-granularity=1) +``` + +Note that plotting profiler data takes more time +and will generate a *lot* of plot files. + Then you can declare a benchmark case target in CMake with the following: ```cmake From 9f7444a66fe33abdac1dc81ad94cf28891919b56 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Mon, 5 Dec 2022 14:38:07 +0100 Subject: [PATCH 9/9] version bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98b78bc..715fbc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(ctbench VERSION 0.1.0) +project(ctbench VERSION 1.0.0) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)