Skip to content

Commit

Permalink
scripted-diff: Replace AddArgs / GetArgs calls with Setting Register …
Browse files Browse the repository at this point in the history
…/ Get calls

This commit is a pure refactoring and does not change behavior in any way.

-BEGIN VERIFY SCRIPT-
python contrib/devtools/reg-settings.py
git add -N src/bench/bench_bitcoin_settings.h src/bitcoin-tx_settings.h src/bitcoin-util_settings.h src/bitcoin-wallet_settings.h src/chainparamsbase_settings.h src/common/args_settings.h src/init/common_settings.h src/init_settings.h src/qt/bitcoin_settings.h src/test/argsman_tests_settings.h src/test/logging_tests_settings.h src/wallet/init_settings.h
git rm contrib/devtools/reg-settings.py
-END VERIFY SCRIPT-
  • Loading branch information
ryanofsky committed Nov 15, 2024
1 parent f33c0b1 commit c42d27d
Show file tree
Hide file tree
Showing 66 changed files with 2,257 additions and 1,279 deletions.
593 changes: 0 additions & 593 deletions contrib/devtools/reg-settings.py

This file was deleted.

3 changes: 2 additions & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <common/settings.h>
#include <cstdint>
#include <hash.h>
#include <init_settings.h>
#include <logging.h>
#include <logging/timer.h>
#include <netbase.h>
Expand Down Expand Up @@ -190,7 +191,7 @@ void ReadFromStream(AddrMan& addr, DataStream& ssPeers)

util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgroupman, const ArgsManager& args)
{
auto check_addrman = std::clamp<int32_t>(args.GetIntArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
auto check_addrman = std::clamp<int32_t>(CheckaddrmanSetting::Get(args, DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
bool deterministic = HasTestOption(args, "addrman"); // use a deterministic addrman only for tests

auto addrman{std::make_unique<AddrMan>(netgroupman, deterministic, /*consistency_check_ratio=*/check_addrman)};
Expand Down
37 changes: 18 additions & 19 deletions src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bench/bench_bitcoin_settings.h>
#include <bench/bench.h>
#include <bench/bench_bitcoin_settings.h>
#include <common/args.h>
#include <crypto/sha256.h>
#include <test/util/setup_common.h>
#include <tinyformat.h>
#include <util/fs.h>
#include <util/string.h>
#include <test/util/setup_common.h>

#include <chrono>
#include <cstdint>
Expand All @@ -26,15 +26,14 @@ 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);
argsman.AddArg("-list", "List benchmarks without executing them", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-min-time=<milliseconds>", strprintf("Minimum runtime per benchmark, in milliseconds (default: %d)", DEFAULT_MIN_TIME_MS), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
argsman.AddArg("-output-csv=<output.csv>", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-output-json=<output.json>", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-sanity-check", "Run benchmarks for only one iteration with no output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-priority-level=<l1,l2,l3>", strprintf("Run benchmarks of one or multiple priority level(s) (%s), default: '%s'",
benchmark::ListPriorities(), DEFAULT_PRIORITY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
AsymptoteSetting::Register(argsman);
FilterSetting::Register(argsman);
ListSetting::Register(argsman);
MinTimeSetting::Register(argsman);
OutputCsvSetting::Register(argsman);
OutputJsonSetting::Register(argsman);
SanityCheckSetting::Register(argsman);
PriorityLevelSetting::Register(argsman);
}

// parses a comma separated list like "10,20,30,50"
Expand Down Expand Up @@ -133,14 +132,14 @@ int main(int argc, char** argv)

try {
benchmark::Args args;
args.asymptote = parseAsymptote(argsman.GetArg("-asymptote", ""));
args.is_list_only = argsman.GetBoolArg("-list", false);
args.min_time = std::chrono::milliseconds(argsman.GetIntArg("-min-time", DEFAULT_MIN_TIME_MS));
args.output_csv = argsman.GetPathArg("-output-csv");
args.output_json = argsman.GetPathArg("-output-json");
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.asymptote = parseAsymptote(AsymptoteSetting::Get(argsman));
args.is_list_only = ListSetting::Get(argsman);
args.min_time = std::chrono::milliseconds(MinTimeSetting::Get(argsman));
args.output_csv = OutputCsvSetting::Get(argsman);
args.output_json = OutputJsonSetting::Get(argsman);
args.regex_filter = FilterSetting::Get(argsman);
args.sanity_check = SanityCheckSetting::Get(argsman);
args.priority = parsePriorityLevel(PriorityLevelSetting::Get(argsman));
args.setup_args = parseTestSetupArgs(argsman);

benchmark::BenchRunner::RunAll(args);
Expand Down
39 changes: 39 additions & 0 deletions src/bench/bench_bitcoin_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,51 @@
#ifndef BITCOIN_BENCH_BENCH_BITCOIN_SETTINGS_H
#define BITCOIN_BENCH_BENCH_BITCOIN_SETTINGS_H

#include <common/setting.h>

#include <cstdint>
#include <string>
#include <vector>

static const char* DEFAULT_BENCH_FILTER = ".*";
static constexpr int64_t DEFAULT_MIN_TIME_MS{10};
/** Priority level default value, run "all" priority levels */
static const std::string DEFAULT_PRIORITY{"all"};

using AsymptoteSetting = common::Setting<
"-asymptote=<n1,n2,n3,...>", std::string, common::SettingOptions{.legacy = true},
"Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark">;

using FilterSetting = common::Setting<
"-filter=<regex>", std::string, common::SettingOptions{.legacy = true},
"Regular expression filter to select benchmark by name (default: %s)">
::DefaultFn<[] { return DEFAULT_BENCH_FILTER; }>;

using ListSetting = common::Setting<
"-list", bool, common::SettingOptions{.legacy = true},
"List benchmarks without executing them">;

using MinTimeSetting = common::Setting<
"-min-time=<milliseconds>", int64_t, common::SettingOptions{.legacy = true, .disallow_negation = true},
"Minimum runtime per benchmark, in milliseconds (default: %d)">
::Default<DEFAULT_MIN_TIME_MS>;

using OutputCsvSetting = common::Setting<
"-output-csv=<output.csv>", fs::path, common::SettingOptions{.legacy = true},
"Generate CSV file with the most important benchmark results">;

using OutputJsonSetting = common::Setting<
"-output-json=<output.json>", fs::path, common::SettingOptions{.legacy = true},
"Generate JSON file with all benchmark results">;

using SanityCheckSetting = common::Setting<
"-sanity-check", bool, common::SettingOptions{.legacy = true},
"Run benchmarks for only one iteration with no output">;

using PriorityLevelSetting = common::Setting<
"-priority-level=<l1,l2,l3>", std::string, common::SettingOptions{.legacy = true},
"Run benchmarks of one or multiple priority level(s) (%s), default: '%s'">
::DefaultFn<[] { return DEFAULT_PRIORITY; }>
::HelpFn<[](const auto& fmt) { return strprintf(fmt, benchmark::ListPriorities(), DEFAULT_PRIORITY); }>;

#endif // BITCOIN_BENCH_BENCH_BITCOIN_SETTINGS_H
Loading

0 comments on commit c42d27d

Please sign in to comment.