From 378738ff709b913f595c30aec65c99ff9304dc2c Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 10:25:44 +0200 Subject: [PATCH 01/14] Switching to std::chrono for time measurement --- compiler-launcher/compiler-launcher.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler-launcher/compiler-launcher.cpp b/compiler-launcher/compiler-launcher.cpp index 087eab9..f2632bd 100644 --- a/compiler-launcher/compiler-launcher.cpp +++ b/compiler-launcher/compiler-launcher.cpp @@ -21,9 +21,6 @@ #include #include -#include -#include - #include #include @@ -36,14 +33,15 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, bool time_trace_flag) { namespace fs = std::filesystem; + // Run program and measure CPU time - rusage children_rusage_begin; - rusage children_rusage_end; - getrusage(RUSAGE_CHILDREN, &children_rusage_begin); + using exec_clock_t = std::chrono::high_resolution_clock; + // TODO: Bypass shell call? + exec_clock_t::time_point const exec_t0 = exec_clock_t::now(); int const ret = std::system(compile_command.c_str()); - getrusage(RUSAGE_CHILDREN, &children_rusage_end); + exec_clock_t::time_point const exec_t1 = exec_clock_t::now(); // Check child exit status if (int const exit_status = WEXITSTATUS(ret); exit_status != 0) { @@ -68,8 +66,9 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, // Generate time-trace file if not already generated namespace nl = nlohmann; - std::size_t const time_micros = children_rusage_end.ru_utime.tv_usec - - children_rusage_begin.ru_utime.tv_usec; + std::size_t const time_micros = + std::chrono::duration_cast(exec_t1 - exec_t0) + .count(); nl::json time_trace_json; time_trace_json["traceEvents"] = nlohmann::json::array(); From 39c08fcdec6daa79e7903541859e7b7e541e5d0a Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 10:39:14 +0200 Subject: [PATCH 02/14] added help arguments --- compiler-launcher/compiler-launcher.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler-launcher/compiler-launcher.cpp b/compiler-launcher/compiler-launcher.cpp index f2632bd..7917929 100644 --- a/compiler-launcher/compiler-launcher.cpp +++ b/compiler-launcher/compiler-launcher.cpp @@ -13,6 +13,7 @@ /// flag to override the current compiler, allowing CMake targets to be compiled /// with different compilers within a single CMake build. +#include #include #include #include @@ -33,7 +34,6 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, bool time_trace_flag) { namespace fs = std::filesystem; - // Run program and measure CPU time using exec_clock_t = std::chrono::high_resolution_clock; @@ -99,7 +99,11 @@ int main(int argc, char const *argv[]) { // Override flag prefix constexpr std::string_view override_flag_prefix = "--override-compiler="; - if (argc < 3) { + // Help display + if (argc < 3 || + std::any_of(argv, argv + argc, [](std::string_view arg) -> bool { + return arg == "--help" || arg == "-h" || arg == "-help"; + })) { fmt::print("Usage: {} time_trace_export_path.json COMPILER [ARGS]...\n\n" "{} - Override previously set compiler\n\n" "If CTBENCH_TTW_VERBOSE is set, " From f8cb4018ca4fff1ef17ad5570cbee370bf0ebc95 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 11:28:24 +0200 Subject: [PATCH 03/14] switched to using boost process with argument list instead of a shell command --- compiler-launcher/compiler-launcher.cpp | 37 +++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/compiler-launcher/compiler-launcher.cpp b/compiler-launcher/compiler-launcher.cpp index 7917929..3e64a73 100644 --- a/compiler-launcher/compiler-launcher.cpp +++ b/compiler-launcher/compiler-launcher.cpp @@ -16,10 +16,11 @@ #include #include #include -#include #include #include +#include #include +#include #include #include @@ -28,8 +29,19 @@ #include +/// Concatenates an argument list into a command string +/// in which the arguments are separated by whitespaces. +inline std::string +to_command_string(std::vector const &command_args) { + return std::accumulate( + command_args.begin(), command_args.end(), std::string{}, + [](std::string accumulator, std::string_view argument) { + return std::move(accumulator) + ' ' + argument.data(); + }); +} + inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, - std::string compile_command, + std::vector command_args, std::filesystem::path compile_obj_path, bool time_trace_flag) { namespace fs = std::filesystem; @@ -38,15 +50,14 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, using exec_clock_t = std::chrono::high_resolution_clock; - // TODO: Bypass shell call? exec_clock_t::time_point const exec_t0 = exec_clock_t::now(); - int const ret = std::system(compile_command.c_str()); + int const ret = boost::process::system(command_args); exec_clock_t::time_point const exec_t1 = exec_clock_t::now(); // Check child exit status if (int const exit_status = WEXITSTATUS(ret); exit_status != 0) { fmt::print("Following compile command exited with status {}: `{}`.\n", - exit_status, compile_command); + exit_status, to_command_string(command_args)); exit(exit_status); }; @@ -117,8 +128,8 @@ int main(int argc, char const *argv[]) { // Compiler exec comes after the wrapper exec and the destination for the // time-trace file, as these two are set as compiler launcher by the CMake // boilerplate. - std::string compiler_executable = argv[compiler_id]; - std::ostringstream args_builder; + // std::string compiler_executable = argv[compiler_id]; + std::vector command_args({argv[compiler_id]}); fs::path obj_path; bool has_time_trace_flag = false; @@ -140,22 +151,20 @@ int main(int argc, char const *argv[]) { // Handling --override-compiler flag else if (current_argument.starts_with(override_flag_prefix)) { current_argument.remove_prefix(override_flag_prefix.size()); - compiler_executable = current_argument; + command_args[0] = current_argument; // Do not pass argument to the compiler continue; } - args_builder << ' ' << *beg; + command_args.push_back(*beg); } - std::string compile_command = - std::move(compiler_executable) + args_builder.str(); - if (std::getenv("CTBENCH_TTW_VERBOSE") != nullptr) { - fmt::print("[CTBENCH_TTW] Compile command: {}\n", compile_command); + fmt::print("[CTBENCH_TTW] Compile command: {}\n", + to_command_string(command_args)); } - return get_timetrace_file(argv[path_id], std::move(compile_command), + return get_timetrace_file(argv[path_id], std::move(command_args), std::move(obj_path), has_time_trace_flag); } From 0e0355f4e296a417a18731019217885f70ead97f Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 11:32:44 +0200 Subject: [PATCH 04/14] header cleanup --- compiler-launcher/compiler-launcher.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler-launcher/compiler-launcher.cpp b/compiler-launcher/compiler-launcher.cpp index 3e64a73..4c95757 100644 --- a/compiler-launcher/compiler-launcher.cpp +++ b/compiler-launcher/compiler-launcher.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include From 55e15758846669bb30f167eba8944a15ba78735c Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 11:36:21 +0200 Subject: [PATCH 05/14] added build result upload to CI --- .github/workflows/main.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1223269..bf37b1b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,11 @@ jobs: uses: actions/checkout@v3 - name: Compiling and running ctbench tests on Archlinux uses: ./.github/actions/run-tests-archlinux + - uses: actions/upload-artifact@v3 + with: + name: build_result + path: build/ + ubuntu-testing: runs-on: self-hosted container: @@ -22,3 +27,7 @@ jobs: uses: actions/checkout@v3 - name: Compiling and running ctbench tests on Ubuntu uses: ./.github/actions/run-tests-ubuntu + - uses: actions/upload-artifact@v3 + with: + name: build_result + path: build/ From 0e1b253a741d2deb998dfe303a4cc41ccb450716 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 11:47:50 +0200 Subject: [PATCH 06/14] uploading example build folder --- .github/actions/run-tests-archlinux/entrypoint.sh | 2 +- .github/actions/run-tests-ubuntu/entrypoint.sh | 3 ++- .github/workflows/main.yml | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/actions/run-tests-archlinux/entrypoint.sh b/.github/actions/run-tests-archlinux/entrypoint.sh index d2899e1..0c8e044 100755 --- a/.github/actions/run-tests-archlinux/entrypoint.sh +++ b/.github/actions/run-tests-archlinux/entrypoint.sh @@ -18,4 +18,4 @@ cmake --build --preset release --target install cd example || exit cmake --preset release -cmake --build --preset release +cmake --build --preset release --target ctbench-graph-all diff --git a/.github/actions/run-tests-ubuntu/entrypoint.sh b/.github/actions/run-tests-ubuntu/entrypoint.sh index d2899e1..d1d814f 100755 --- a/.github/actions/run-tests-ubuntu/entrypoint.sh +++ b/.github/actions/run-tests-ubuntu/entrypoint.sh @@ -18,4 +18,5 @@ cmake --build --preset release --target install cd example || exit cmake --preset release -cmake --build --preset release +cmake --build --preset release --target ctbench-graph-all + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf37b1b..cca9d37 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/upload-artifact@v3 with: name: build_result - path: build/ + path: example/build/ ubuntu-testing: runs-on: self-hosted @@ -30,4 +30,4 @@ jobs: - uses: actions/upload-artifact@v3 with: name: build_result - path: build/ + path: example/build/ From a26410c8a4c0ad575bda5e8d04ba79ea01d2d69b Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 13:42:22 +0200 Subject: [PATCH 07/14] refactoring + get_timetrace_file does not exit on non-zero status code but forwards the exit code by returning it instead --- compiler-launcher/compiler-launcher.cpp | 40 ++++++++++++++----------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/compiler-launcher/compiler-launcher.cpp b/compiler-launcher/compiler-launcher.cpp index 4c95757..5f2956f 100644 --- a/compiler-launcher/compiler-launcher.cpp +++ b/compiler-launcher/compiler-launcher.cpp @@ -38,25 +38,33 @@ to_command_string(std::vector const &command_args) { }); } +/// Invokes the compiler, measures the execution time, and either +/// copies the time-trace file or generates one to the desired location. +/// The return value is the exit code of the compiler. +/// If the exit code is not zero, then no time-trace file is copied or +/// generated. inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, std::vector command_args, std::filesystem::path compile_obj_path, bool time_trace_flag) { namespace fs = std::filesystem; + namespace ch = std::chrono; // Run program and measure CPU time - using exec_clock_t = std::chrono::high_resolution_clock; + using exec_clock_t = ch::high_resolution_clock; exec_clock_t::time_point const exec_t0 = exec_clock_t::now(); - int const ret = boost::process::system(command_args); + int const exit_code = boost::process::system(command_args); exec_clock_t::time_point const exec_t1 = exec_clock_t::now(); - // Check child exit status - if (int const exit_status = WEXITSTATUS(ret); exit_status != 0) { + // Check child exit code + if (exit_code != 0) { fmt::print("Following compile command exited with status {}: `{}`.\n", - exit_status, to_command_string(command_args)); - exit(exit_status); + exit_code, to_command_string(command_args)); + + // Forward exit code + return exit_code; }; // Create destination directory @@ -76,8 +84,7 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, namespace nl = nlohmann; std::size_t const time_micros = - std::chrono::duration_cast(exec_t1 - exec_t0) - .count(); + ch::duration_cast(exec_t1 - exec_t0).count(); nl::json time_trace_json; time_trace_json["traceEvents"] = nlohmann::json::array(); @@ -88,8 +95,8 @@ inline int get_timetrace_file(std::filesystem::path const time_trace_file_dest, std::ofstream(time_trace_file_dest) << time_trace_json; } - // Forward return value - return ret; + // Forward exit code + return exit_code; } /// Wrapper for a compiler command. @@ -133,23 +140,22 @@ int main(int argc, char const *argv[]) { for (auto beg = &argv[args_start_id], end = &argv[argc]; beg < end; beg++) { // Current argument as a string_view - std::string_view current_argument{*beg}; + std::string_view current_arg{*beg}; // Handling -o flag - if (current_argument == std::string_view("-o") && beg + 1 != end) { + if (current_arg == "-o" && beg + 1 != end) { obj_path = *(beg + 1); } // Handling Clang -ftime-trace flag - else if (current_argument == "-ftime-trace" || - current_argument == "--ftime-trace") { + else if (current_arg == "-ftime-trace" || current_arg == "--ftime-trace") { has_time_trace_flag = true; } // Handling --override-compiler flag - else if (current_argument.starts_with(override_flag_prefix)) { - current_argument.remove_prefix(override_flag_prefix.size()); - command_args[0] = current_argument; + else if (current_arg.starts_with(override_flag_prefix)) { + current_arg.remove_prefix(override_flag_prefix.size()); + command_args[0] = current_arg; // Do not pass argument to the compiler continue; From 5aed1e8608338f900bdb66cb94410004f3ca847a Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 15:53:36 +0200 Subject: [PATCH 08/14] more cmake presets for compilation using gcc/clang/clang+time-trace in debug or release modes --- example/CMakePresets.json | 68 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/example/CMakePresets.json b/example/CMakePresets.json index 0632b03..1b147bd 100644 --- a/example/CMakePresets.json +++ b/example/CMakePresets.json @@ -27,22 +27,60 @@ "generator" : "Ninja", "binaryDir" : "${sourceDir}/build/release", "cacheVariables" : { - "ENABLE_TIME_TRACE" : "ON", - "CMAKE_CXX_COMPILER" : "clang++", - "CMAKE_C_COMPILER" : "clang", - "CMAKE_EXPORT_COMPILE_COMMANDS" : "ON", "CMAKE_BUILD_TYPE" : "RelWithDebInfo" } }, + { + "name" : "release-clang", + "inherits" : "release", + "displayName" : "Release - Clang", + "description" : "Same as release preset, but using Clang", + "binaryDir" : "${sourceDir}/build/release-clang", + "cacheVariables" : { + "CMAKE_CXX_COMPILER" : "clang++", + "CMAKE_C_COMPILER" : "clang" + } + }, + { + "name" : "release-clang-tt", + "inherits" : "release-clang", + "displayName" : "Release - Clang with time-trace", + "description" : "Same as release preset, but using Clang with time-trace", + "binaryDir" : "${sourceDir}/build/release-clang-tt", + "cacheVariables" : { + "ENABLE_TIME_TRACE" : "ON" + } + }, { "name" : "debug", "inherits" : "release", "displayName" : "Debug", - "description" : "Debug", + "description" : "Compile with debug symbols", "binaryDir" : "${sourceDir}/build/debug", "cacheVariables" : { "CMAKE_BUILD_TYPE" : "Debug" } + }, + { + "name" : "debug-clang", + "inherits" : "debug", + "displayName" : "Debug - Clang", + "description" : "Same as debug preset, but using Clang", + "binaryDir" : "${sourceDir}/build/debug-clang", + "cacheVariables" : { + "CMAKE_CXX_COMPILER" : "clang++", + "CMAKE_C_COMPILER" : "clang" + } + }, + { + "name" : "debug-clang-tt", + "inherits" : "debug-clang", + "displayName" : "Debug - Clang with time-trace", + "description" : "Same as debug preset, but using Clang with time-trace", + "binaryDir" : "${sourceDir}/build/debug-clang", + "cacheVariables" : { + "ENABLE_TIME_TRACE" : "ON" + } } ], "buildPresets" : [ @@ -56,10 +94,30 @@ "ctbench-graph-all" ] }, + { + "name" : "release-clang", + "inherits" : "release", + "configurePreset" : "release-clang" + }, + { + "name" : "release-clang-tt", + "inherits" : "release-clang", + "configurePreset" : "release-clang-tt" + }, { "name" : "debug", "inherits" : "release", "configurePreset" : "debug" + }, + { + "name" : "debug-clang", + "inherits" : "debug", + "configurePreset" : "debug-clang" + }, + { + "name" : "debug-clang-tt", + "inherits" : "debug-clang", + "configurePreset" : "debug-clang-tt" } ] } From c5c557eb602f7911318204e2a50f516914a483d0 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 15:55:05 +0200 Subject: [PATCH 09/14] github actions now testing all targets (gcc + clang + clang-tt) --- .github/actions/run-tests-archlinux/entrypoint.sh | 10 ++++++++-- .github/actions/run-tests-ubuntu/entrypoint.sh | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/actions/run-tests-archlinux/entrypoint.sh b/.github/actions/run-tests-archlinux/entrypoint.sh index 0c8e044..2f0bbf7 100755 --- a/.github/actions/run-tests-archlinux/entrypoint.sh +++ b/.github/actions/run-tests-archlinux/entrypoint.sh @@ -16,6 +16,12 @@ cmake --build --preset release --target test-all cmake --build --preset release --target install -cd example || exit +cd example + cmake --preset release -cmake --build --preset release --target ctbench-graph-all +cmake --preset release-clang +cmake --preset release-clang-tt + +cmake --build --preset release +cmake --build --preset release-clang +cmake --build --preset release-clang-tt diff --git a/.github/actions/run-tests-ubuntu/entrypoint.sh b/.github/actions/run-tests-ubuntu/entrypoint.sh index d1d814f..8721071 100755 --- a/.github/actions/run-tests-ubuntu/entrypoint.sh +++ b/.github/actions/run-tests-ubuntu/entrypoint.sh @@ -16,7 +16,13 @@ cmake --build --preset release --target test-all cmake --build --preset release --target install -cd example || exit +cd example + cmake --preset release -cmake --build --preset release --target ctbench-graph-all +cmake --preset release-clang +cmake --preset release-clang-tt + +cmake --build --preset release +cmake --build --preset release-clang +cmake --build --preset release-clang-tt From 06a80719400ff1042444b2615f25fbc9508d9a39 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 15:57:47 +0200 Subject: [PATCH 10/14] added changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..335f851 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +## 1.3.4 + +- Added changelog + +### compiler-launcher + +- Added `-h/-help/help` flag to display help in CLI +- Fixed compiler execution time measurement for measurements without time-trace From 87c6455a5ac89b5994b467bd174d21602b4c1242 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 15:58:04 +0200 Subject: [PATCH 11/14] bumped patch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6891232..9955f60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(ctbench VERSION 1.3.3) +project(ctbench VERSION 1.3.4) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) From 0d6203ee2db3eb298ded6bc96e856d09ba065021 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 16:07:53 +0200 Subject: [PATCH 12/14] changelog update --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 335f851..14a55e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,18 @@ - Added `-h/-help/help` flag to display help in CLI - Fixed compiler execution time measurement for measurements without time-trace + +### Example project + +- Added new presets, the available ones are now: + - `release-gcc` + - `release-clang` + - `release-clang-tt` + - `debug-gcc` + - `debug-clang` + - `debug-clang-tt` + +### CI/CD + +- Now compiling all presets +- Results are uploaded as artifacts From a77be64a9d220a3f9310b55b11c96ff8b00081ae Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 16:13:50 +0200 Subject: [PATCH 13/14] removed trailing endline --- .github/actions/run-tests-ubuntu/entrypoint.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/run-tests-ubuntu/entrypoint.sh b/.github/actions/run-tests-ubuntu/entrypoint.sh index 8721071..2f0bbf7 100755 --- a/.github/actions/run-tests-ubuntu/entrypoint.sh +++ b/.github/actions/run-tests-ubuntu/entrypoint.sh @@ -25,4 +25,3 @@ cmake --preset release-clang-tt cmake --build --preset release cmake --build --preset release-clang cmake --build --preset release-clang-tt - From 56946f5af26e5f42505442016d85fca55b05f0b6 Mon Sep 17 00:00:00 2001 From: Jules P?nuchot Date: Tue, 18 Jul 2023 17:54:15 +0200 Subject: [PATCH 14/14] build result upload name conflict fixed --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cca9d37..39d8e77 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: uses: ./.github/actions/run-tests-archlinux - uses: actions/upload-artifact@v3 with: - name: build_result + name: archlinux-build-result path: example/build/ ubuntu-testing: @@ -29,5 +29,5 @@ jobs: uses: ./.github/actions/run-tests-ubuntu - uses: actions/upload-artifact@v3 with: - name: build_result + name: ubuntu-build-result path: example/build/