diff --git a/contrib/teamcity/build-configurations.sh b/contrib/teamcity/build-configurations.sh --- a/contrib/teamcity/build-configurations.sh +++ b/contrib/teamcity/build-configurations.sh @@ -270,7 +270,7 @@ "-DSECP256K1_ENABLE_MODULE_RECOVERY=ON" ) CMAKE_FLAGS="${CMAKE_FLAGS[*]}" "${DEVTOOLS_DIR}"/build_cmake.sh - ninja bench-bitcoin + ./src/bench/bitcoin-bench -printer=junit > junit_results_bench.xml ninja bench-secp256k1 ;; diff --git a/src/bench/bench.h b/src/bench/bench.h --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -129,6 +129,18 @@ int64_t m_width; int64_t m_height; }; + +// Junit compatible printer, allow to log durations on compatible CI +class JunitPrinter : public Printer { +public: + void header() override; + void result(const State &state) override; + void footer() override; + +private: + std::vector> bench_results; + double total_duration; +}; } // namespace benchmark // BENCHMARK(foo, num_iters_for_one_second) expands to: benchmark::BenchRunner diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -85,6 +85,39 @@ << ""; } +void benchmark::JunitPrinter::header() { + std::cout << "" << std::endl; +} + +void benchmark::JunitPrinter::result(const State &state) { + auto results = state.m_elapsed_results; + double bench_duration = + state.m_num_iters * + std::accumulate(results.begin(), results.end(), 0.0); + + /* + * Don't print the results now, we need them all to build the + * node. + */ + bench_results.emplace_back(std::move(state.m_name), bench_duration); + total_duration += bench_duration; +} + +void benchmark::JunitPrinter::footer() { + std::cout << std::setprecision(6); + std::cout << "" << std::endl; + + for (const auto &result : bench_results) { + std::cout << "" << std::endl; + } + + std::cout << "" << std::endl; +} + benchmark::BenchRunner::BenchmarkMap &benchmark::BenchRunner::benchmarks() { static std::map benchmarks_map; return benchmarks_map; diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -43,9 +43,10 @@ DEFAULT_BENCH_SCALING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg( - "-printer=(console|plot)", + "-printer=(console|junit|plot)", strprintf("Choose printer format. console: print data to console. " - "plot: Print results as HTML graph (default: %s)", + "junit: print results as a Junit compliant XML." + "plot: print results as HTML graph (default: %s)", DEFAULT_BENCH_PRINTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-plot-plotlyurl=", @@ -101,6 +102,9 @@ gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH), gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT))); } + if ("junit" == printer_arg) { + printer.reset(new benchmark::JunitPrinter()); + } benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);