Skip to content

Commit 221410b

Browse files
committed
bench: specialize working directory name
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.
1 parent d812cf1 commit 221410b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/bench/bench.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
2929

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

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

3443
namespace {
3544

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

0 commit comments

Comments
 (0)