diff options
author | Ava Chow <github@achow101.com> | 2024-11-13 19:14:23 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-11-13 19:14:23 -0500 |
commit | 42282592943755be2b91ff27a4fafd997df98586 (patch) | |
tree | dac60db8796ba8ef773694e98c541e54b9cd75f8 /src/bench | |
parent | 36f5effa1783a72d57c393588059a688068336e2 (diff) | |
parent | fa66e0887ca1a1445d8b18ba1fadb12b2d911048 (diff) |
Merge bitcoin/bitcoin#31000: bench: add support for custom data directory
fa66e0887ca1a1445d8b18ba1fadb12b2d911048 bench: add support for custom data directory (furszy)
ad9c2cceda9cd893c0f754e49f7fca6e417ee95f test, bench: specialize working directory name (furszy)
Pull request description:
Expands the benchmark framework with the existing `-testdatadir` arg,
enabling the ability to change the benchmark data directory.
This is useful for running benchmarks on different storage devices, and
not just under the OS `/tmp/` directory.
A good use case is #28574, where we are benchmarking the wallet
migration process on an HDD.
ACKs for top commit:
maflcko:
re-ACK fa66e0887ca1a1445d8b18ba1fadb12b2d911048
achow101:
ACK fa66e0887ca1a1445d8b18ba1fadb12b2d911048
tdb3:
re ACK fa66e0887ca1a1445d8b18ba1fadb12b2d911048
hodlinator:
re-ACK fa66e0887ca1a1445d8b18ba1fadb12b2d911048
pablomartin4btc:
re-ACK fa66e0887ca1a1445d8b18ba1fadb12b2d911048
Tree-SHA512: 4e87206c07e26fe193c07074ae9eb0cc9c70a58aeea8cf27d18fb5425d77e4b00dbe0e6d6a75c17b427744e9066458b9a84e5ef7b0420f02a4fccb9c5ef4dacc
Diffstat (limited to 'src/bench')
-rw-r--r-- | src/bench/bench.cpp | 30 | ||||
-rw-r--r-- | src/bench/bench.h | 1 | ||||
-rw-r--r-- | src/bench/bench_bitcoin.cpp | 15 |
3 files changed, 44 insertions, 2 deletions
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index a2dbb11888..26daff5070 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -27,9 +27,26 @@ using util::Join; const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; -const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS{}; +/** + * Retrieves the available test setup command line arguments that may be used + * in the benchmark. They will be used only if the benchmark utilizes a + * 'BasicTestingSetup' or any child of it. + */ +static std::function<std::vector<const char*>()> g_bench_command_line_args{}; +const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS = []() { + return g_bench_command_line_args(); +}; -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 { @@ -94,6 +111,14 @@ void BenchRunner::RunAll(const Args& args) std::cout << "Running with -sanity-check option, output is being suppressed as benchmark results will be useless." << std::endl; } + // Load inner test setup args + g_bench_command_line_args = [&args]() { + std::vector<const char*> ret; + ret.reserve(args.setup_args.size()); + for (const auto& arg : args.setup_args) ret.emplace_back(arg.c_str()); + return ret; + }; + std::vector<ankerl::nanobench::Result> benchmarkResults; for (const auto& [name, bench_func] : benchmarks()) { const auto& [func, priority_level] = bench_func; @@ -117,6 +142,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; diff --git a/src/bench/bench.h b/src/bench/bench.h index f0705f4fed..2df203ce23 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -61,6 +61,7 @@ struct Args { fs::path output_json; std::string regex_filter; uint8_t priority; + std::vector<std::string> setup_args; }; class BenchRunner diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index 555dca7d59..88afe68a1a 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -8,6 +8,7 @@ #include <tinyformat.h> #include <util/fs.h> #include <util/string.h> +#include <test/util/setup_common.h> #include <chrono> #include <cstdint> @@ -27,6 +28,7 @@ static const std::string DEFAULT_PRIORITY{"all"}; static void SetupBenchArgs(ArgsManager& argsman) { SetupHelpOptions(argsman); + SetupCommonTestArgs(argsman); argsman.AddArg("-asymptote=<n1,n2,n3,...>", "Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); @@ -60,6 +62,18 @@ static uint8_t parsePriorityLevel(const std::string& str) { return levels; } +static std::vector<std::string> parseTestSetupArgs(const ArgsManager& argsman) +{ + // Parses unit test framework arguments supported by the benchmark framework. + std::vector<std::string> args; + static std::vector<std::string> AVAILABLE_ARGS = {"-testdatadir"}; + for (const std::string& arg_name : AVAILABLE_ARGS) { + auto op_arg = argsman.GetArg(arg_name); + if (op_arg) args.emplace_back(strprintf("%s=%s", arg_name, *op_arg)); + } + return args; +} + int main(int argc, char** argv) { ArgsManager argsman; @@ -131,6 +145,7 @@ int main(int argc, char** argv) args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); args.sanity_check = argsman.GetBoolArg("-sanity-check", false); args.priority = parsePriorityLevel(argsman.GetArg("-priority-level", DEFAULT_PRIORITY)); + args.setup_args = parseTestSetupArgs(argsman); benchmark::BenchRunner::RunAll(args); |