mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
bench: add support for custom data directory
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.
This commit is contained in:
parent
ad9c2cceda
commit
fa66e0887c
5 changed files with 38 additions and 4 deletions
|
@ -27,7 +27,15 @@ 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();
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the name of the currently in-use benchmark.
|
||||
|
@ -103,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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ struct NetworkSetup
|
|||
};
|
||||
static NetworkSetup g_networksetup_instance;
|
||||
|
||||
/** Register test-only arguments */
|
||||
static void SetupUnitTestArgs(ArgsManager& argsman)
|
||||
void SetupCommonTestArgs(ArgsManager& argsman)
|
||||
{
|
||||
argsman.AddArg("-testdatadir", strprintf("Custom data directory (default: %s<random_string>)", fs::PathToString(fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / "")),
|
||||
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||
|
@ -125,7 +124,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
|
|||
gArgs.ClearPathCache();
|
||||
{
|
||||
SetupServerArgs(*m_node.args);
|
||||
SetupUnitTestArgs(*m_node.args);
|
||||
SetupCommonTestArgs(*m_node.args);
|
||||
std::string error;
|
||||
if (!m_node.args->ParseParameters(arguments.size(), arguments.data(), error)) {
|
||||
m_node.args->ClearArgs();
|
||||
|
|
|
@ -45,6 +45,9 @@ extern const std::function<std::string()> G_TEST_GET_FULL_NAME;
|
|||
|
||||
static constexpr CAmount CENT{1000000};
|
||||
|
||||
/** Register common test args. Shared across binaries that rely on the test framework. */
|
||||
void SetupCommonTestArgs(ArgsManager& argsman);
|
||||
|
||||
struct TestOpts {
|
||||
std::vector<const char*> extra_args{};
|
||||
bool coins_db_in_memory{true};
|
||||
|
|
Loading…
Add table
Reference in a new issue