Skip to content

Commit

Permalink
bench: specialize working directory name
Browse files Browse the repository at this point in the history
Since G_TEST_GET_FULL_NAME is not initialized in the benchmark framework,
benchmarks using the unit test setup run in the same directory without
any clear distinction between them.
This poses an extra complication for locating any specific benchmark
directory during a failure.

In master, all benchmarks run in the following path:
/<OS_tmp_dir>/test_common bitcoin/<random_uint256>/

After this commit, benchmarks are contained within its own directory:
/<OS_tmp_dir>/test_common bitcoin/<benchmark_name>/<random_uint256>/

This makes it easier to find any benchmark run when a failure occurs.
  • Loading branch information
furszy committed Sep 30, 2024
1 parent d812cf1 commit 221410b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ const std::function<void(const std::string&)> G_TEST_LOG_FUN{};

const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{};

const std::function<std::string()> G_TEST_GET_FULL_NAME{};
/**
* Retrieve the name of the currently in-use benchmark.
* This is applicable only to benchmarks that utilize the unit test
* framework context setup (e.g. ones using 'MakeNoLogFileContext<TestingSetup>()').
* It places the datadir of each benchmark run within their respective benchmark name.
*/
static std::string g_running_benchmark_name;
const std::function<std::string()> G_TEST_GET_FULL_NAME = []() {
return g_running_benchmark_name;
};

namespace {

Expand Down Expand Up @@ -117,6 +126,7 @@ void BenchRunner::RunAll(const Args& args)
bench.output(nullptr);
}
bench.name(name);
g_running_benchmark_name = name;
if (args.min_time > 0ms) {
// convert to nanos before dividing to reduce rounding errors
std::chrono::nanoseconds min_time_ns = args.min_time;
Expand Down

0 comments on commit 221410b

Please sign in to comment.