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

-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 8, 2024
1 parent 6a55981 commit 416860f
Show file tree
Hide file tree
Showing 63 changed files with 2,268 additions and 1,230 deletions.
551 changes: 0 additions & 551 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).value_or(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
34 changes: 17 additions & 17 deletions src/bench/bench_bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bench/bench.h>
#include <bench/bench_bitcoin_settings.h>
#include <common/args.h>
#include <crypto/sha256.h>
#include <tinyformat.h>
Expand All @@ -28,15 +29,14 @@ static void SetupBenchArgs(ArgsManager& argsman)
{
SetupHelpOptions(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 @@ -123,14 +123,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));

benchmark::BenchRunner::RunAll(args);

Expand Down
45 changes: 45 additions & 0 deletions src/bench/bench_bitcoin_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef BENCH_BENCH_BITCOIN_SETTINGS_H
#define BENCH_BENCH_BITCOIN_SETTINGS_H

#include <common/setting.h>

#include <string>
#include <vector>

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

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

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

using MinTimeSetting = common::Setting<
"-min-time=<milliseconds>", int64_t, {.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, {.legacy = true},
"Generate CSV file with the most important benchmark results">;

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

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

using PriorityLevelSetting = common::Setting<
"-priority-level=<l1,l2,l3>", std::string, {.legacy = true},
"Run benchmarks of one or multiple priority level(s) (%s), default: '%s'">
::Default<DEFAULT_PRIORITY>
::HelpArgs<benchmark::ListPriorities(), DEFAULT_PRIORITY>;

#endif // BENCH_BENCH_BITCOIN_SETTINGS_H
Loading

0 comments on commit 416860f

Please sign in to comment.