From 365b46eee3e792ecb5c975b60d4fc6d86383097a Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Fri, 19 Jul 2024 15:30:42 +0300 Subject: [PATCH] bench runner can run external command --- bench/bench.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bench/bench.cpp b/bench/bench.cpp index 38149bed5..eae97840e 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "test_suite.hpp" @@ -57,6 +58,8 @@ std::stringstream strout; parse_options popts; bool with_file_io = false; +char const* external_command = nullptr; + #if defined(__clang__) string_view toolset = "clang"; #elif defined(__GNUC__) @@ -173,6 +176,40 @@ print_prefix( arch << "," << impl.name(); } +void +start_external(file_item const& f, any_impl const& i, string_view verb) +{ + if( !external_command ) + return; + + std::stringstream command; + command << external_command << " Starting \""; + print_prefix(command, f, i, verb ) << '"'; + std::string const command_s = command.str(); + (void)std::system( command_s.c_str() ); +} + +void +finish_external( + file_item const& f, + any_impl const& i, + string_view verb, + sample const& result) +{ + if( !external_command ) + return; + + std::stringstream command; + command << external_command << " Completed \""; + print_prefix(command, f, i, verb ) + << "," << result.calls + << "," << result.millis + << "," << result.mbs + << '"'; + std::string const command_s = command.str(); + (void)std::system( command_s.c_str() ); +} + void bench( string_view verb, @@ -203,7 +240,10 @@ bench( repeat = 1000; for(unsigned k = 0; k < Trials; ++k) { + start_external(vf[i], *vi[j], verb); auto result = run_for(std::chrono::seconds(5), f); + finish_external(vf[i], *vi[j], verb, result); + result.calls *= repeat; result.mbs = megabytes_per_second( vf[i], result.calls, result.millis); @@ -1159,6 +1199,8 @@ main( return 4; } + external_command = std::getenv("BOOST_JSON_BENCH_EXTERNAL_COMMAND"); + file_list vf; for( int i = 1; i < argc; ++i )