mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 04:52:36 +02:00

If an unknown option is given via either the command line args or the conf file, throw an error and exit Update tests for ArgsManager knowing args Ignore unknown options in the config file for bitcoin-cli Fix tests and bitcoin-cli to match actual options used
84 lines
3.6 KiB
C++
84 lines
3.6 KiB
C++
// Copyright (c) 2015-2017 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <bench/bench.h>
|
|
|
|
#include <crypto/sha256.h>
|
|
#include <key.h>
|
|
#include <validation.h>
|
|
#include <util.h>
|
|
#include <random.h>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <memory>
|
|
|
|
static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
|
|
static const char* DEFAULT_BENCH_FILTER = ".*";
|
|
static const char* DEFAULT_BENCH_SCALING = "1.0";
|
|
static const char* DEFAULT_BENCH_PRINTER = "console";
|
|
static const char* DEFAULT_PLOT_PLOTLYURL = "https://cdn.plot.ly/plotly-latest.min.js";
|
|
static const int64_t DEFAULT_PLOT_WIDTH = 1024;
|
|
static const int64_t DEFAULT_PLOT_HEIGHT = 768;
|
|
|
|
static void SetupBenchArgs()
|
|
{
|
|
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-list", "List benchmarks without executing them. Can be combined with -scaling and -filter", false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-evals=<n>", strprintf("Number of measurement evaluations to perform. (default: %u)", DEFAULT_BENCH_EVALUATIONS), false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-scaling=<n>", strprintf("Scaling factor for benchmark's runtime (default: %u)", DEFAULT_BENCH_SCALING), false, OptionsCategory::OPTIONS);
|
|
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), false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-plot-plotlyurl=<uri>", strprintf("URL to use for plotly.js (default: %s)", DEFAULT_PLOT_PLOTLYURL), false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-plot-width=<x>", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), false, OptionsCategory::OPTIONS);
|
|
gArgs.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), false, OptionsCategory::OPTIONS);
|
|
|
|
// Hidden
|
|
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
|
|
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
SetupBenchArgs();
|
|
std::string error;
|
|
if (!gArgs.ParseParameters(argc, argv, error)) {
|
|
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
|
|
return false;
|
|
}
|
|
|
|
if (HelpRequested(gArgs)) {
|
|
std::cout << gArgs.GetHelpMessage();
|
|
|
|
return 0;
|
|
}
|
|
|
|
SHA256AutoDetect();
|
|
RandomInit();
|
|
ECC_Start();
|
|
SetupEnvironment();
|
|
|
|
int64_t evaluations = gArgs.GetArg("-evals", DEFAULT_BENCH_EVALUATIONS);
|
|
std::string regex_filter = gArgs.GetArg("-filter", DEFAULT_BENCH_FILTER);
|
|
std::string scaling_str = gArgs.GetArg("-scaling", DEFAULT_BENCH_SCALING);
|
|
bool is_list_only = gArgs.GetBoolArg("-list", false);
|
|
|
|
double scaling_factor = boost::lexical_cast<double>(scaling_str);
|
|
|
|
|
|
std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
|
|
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
|
|
if ("plot" == printer_arg) {
|
|
printer.reset(new benchmark::PlotlyPrinter(
|
|
gArgs.GetArg("-plot-plotlyurl", DEFAULT_PLOT_PLOTLYURL),
|
|
gArgs.GetArg("-plot-width", DEFAULT_PLOT_WIDTH),
|
|
gArgs.GetArg("-plot-height", DEFAULT_PLOT_HEIGHT)));
|
|
}
|
|
|
|
benchmark::BenchRunner::RunAll(*printer, evaluations, scaling_factor, regex_filter, is_list_only);
|
|
|
|
ECC_Stop();
|
|
}
|