Skip to content

Commit 969ee85

Browse files
author
MarcoFalke
committed
Merge #18662: test: Replace gArgs with local argsman in bench
faf989f util: Document why ArgsManager (con/de)structor is not inline (MarcoFalke) fae00a7 bench: Remove unused argsman.ClearArgs (MarcoFalke) fa46aeb scripted-diff: Replace gArgs with local argsman in bench (MarcoFalke) fa2bc41 tools: Add unused argsman to bench_bitcoin (MarcoFalke) Pull request description: All utilities use the same gArgs global that the node uses. This is generally fine and does not lead to issues unless a bench test is going to spin up a NodeContext via the TestingSetup. In that case the two uses of gArgs conflict and currently it needs to be cleared: https://github.com/bitcoin/bitcoin/blob/544709763e1f45148d1926831e07ff03487673ee/src/bench/bench_bitcoin.cpp#L76 One solution would be to do nothing, because the current code works with that workaround. Another solution would be to not use the same global in all binaries. ACKs for top commit: promag: ACK faf989f. ryanofsky: Code review ACK faf989f. Just new commit added restoring forward declaration Tree-SHA512: 8ee4b28eee294d41c002f801fa844b0c23c919a3061f5109638701db0947b3b0ea28caa7311ae5f126fc660648bbaa0890853e6b06bdc5868692f52ba8c05f66
2 parents 8f24979 + faf989f commit 969ee85

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,40 @@ static const char* DEFAULT_PLOT_PLOTLYURL = "https://cdn.plot.ly/plotly-latest.m
1717
static const int64_t DEFAULT_PLOT_WIDTH = 1024;
1818
static const int64_t DEFAULT_PLOT_HEIGHT = 768;
1919

20-
static void SetupBenchArgs()
20+
static void SetupBenchArgs(ArgsManager& argsman)
2121
{
22-
SetupHelpOptions(gArgs);
23-
24-
gArgs.AddArg("-list", "List benchmarks without executing them. Can be combined with -scaling and -filter", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
25-
gArgs.AddArg("-evals=<n>", strprintf("Number of measurement evaluations to perform. (default: %u)", DEFAULT_BENCH_EVALUATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
26-
gArgs.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
27-
gArgs.AddArg("-scaling=<n>", strprintf("Scaling factor for benchmark's runtime (default: %u)", DEFAULT_BENCH_SCALING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
28-
gArgs.AddArg("-printer=(console|plot)", strprintf("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)", DEFAULT_BENCH_PRINTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
29-
gArgs.AddArg("-plot-plotlyurl=<uri>", strprintf("URL to use for plotly.js (default: %s)", DEFAULT_PLOT_PLOTLYURL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
30-
gArgs.AddArg("-plot-width=<x>", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
31-
gArgs.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
22+
SetupHelpOptions(argsman);
23+
24+
argsman.AddArg("-list", "List benchmarks without executing them. Can be combined with -scaling and -filter", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
25+
argsman.AddArg("-evals=<n>", strprintf("Number of measurement evaluations to perform. (default: %u)", DEFAULT_BENCH_EVALUATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
26+
argsman.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
27+
argsman.AddArg("-scaling=<n>", strprintf("Scaling factor for benchmark's runtime (default: %u)", DEFAULT_BENCH_SCALING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
28+
argsman.AddArg("-printer=(console|plot)", strprintf("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)", DEFAULT_BENCH_PRINTER), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
29+
argsman.AddArg("-plot-plotlyurl=<uri>", strprintf("URL to use for plotly.js (default: %s)", DEFAULT_PLOT_PLOTLYURL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
30+
argsman.AddArg("-plot-width=<x>", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
31+
argsman.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
3232
}
3333

3434
int main(int argc, char** argv)
3535
{
36-
SetupBenchArgs();
36+
ArgsManager argsman;
37+
SetupBenchArgs(argsman);
3738
std::string error;
38-
if (!gArgs.ParseParameters(argc, argv, error)) {
39+
if (!argsman.ParseParameters(argc, argv, error)) {
3940
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
4041
return EXIT_FAILURE;
4142
}
4243

43-
if (HelpRequested(gArgs)) {
44-
std::cout << gArgs.GetHelpMessage();
44+
if (HelpRequested(argsman)) {
45+
std::cout << argsman.GetHelpMessage();
4546

4647
return EXIT_SUCCESS;
4748
}
4849

49-
int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
50-
std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
51-
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
52-
bool is_list_only = gArgs.GetBoolArg("-list", false);
50+
int64_t evaluations = argsman.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
51+
std::string regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER);
52+
std::string scaling_str = argsman.GetArg("-scaling", DEFAULT_BENCH_SCALING);
53+
bool is_list_only = argsman.GetBoolArg("-list", false);
5354

5455
if (evaluations == 0) {
5556
return EXIT_SUCCESS;
@@ -65,16 +66,14 @@ int main(int argc, char** argv)
6566
}
6667

6768
std::unique_ptr<benchmark::Printer> printer = MakeUnique<benchmark::ConsolePrinter>();
68-
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
69+
std::string printer_arg = argsman.GetArg("-printer", DEFAULT_BENCH_PRINTER);
6970
if ("plot" == printer_arg) {
7071
printer.reset(new benchmark::PlotlyPrinter(
71-
gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
72-
gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
73-
gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
72+
argsman.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
73+
argsman.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
74+
argsman.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
7475
}
7576

76-
gArgs.ClearArgs(); // gArgs no longer needed. Clear it here to avoid interactions with the testing setup in the benches
77-
7877
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
7978

8079
return EXIT_SUCCESS;

src/util/system.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ static bool CheckValid(const std::string& key, const util::SettingsValue& val, u
226226
return true;
227227
}
228228

229-
ArgsManager::ArgsManager()
230-
{
231-
// nothing to do
232-
}
229+
// Define default constructor and destructor that are not inline, so code instantiating this class doesn't need to
230+
// #include class definitions for all members.
231+
// For example, m_settings has an internal dependency on univalue.
232+
ArgsManager::ArgsManager() {}
233+
ArgsManager::~ArgsManager() {}
233234

234235
const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
235236
{

src/util/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class ArgsManager
192192

193193
public:
194194
ArgsManager();
195+
~ArgsManager();
195196

196197
/**
197198
* Select the network in use

0 commit comments

Comments
 (0)