bench: Remove -priority-level= option
What changed, and why it matters
This commit removes a command-line option called -priority-level from Bitcoin Core's internal benchmark testing tool. It is a code cleanup change affecting only the benchmark test harness, not the live Bitcoin network node software. There is no security relevance.
No security action needed. Treat as routine maintenance/refactoring of the benchmark tooling.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes the PriorityLevel enum, the -priority-level CLI argument parsing, and filtering logic from src/bench/bench.cpp, src/bench/bench.h, and src/bench/bench_bitcoin.cpp. BenchRunner now stores only a name-to-function mapping instead of name-to-(function, priority). The BENCHMARK macro no longer accepts a priority_level argument. This is a refactoring of the benchmark framework with no functional change to consensus, networking, wallet, or runtime node behavior.
Changed components
src/bench/bench.cppsrc/bench/bench.hsrc/bench/bench_bitcoin.cppInspect captured patch +9 / −70
diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp
index 3eb99ab5..9b74af51 100644
--- a/src/bench/bench.cpp
+++ b/src/bench/bench.cpp
@@ -5,25 +5,19 @@
#include <bench/bench.h>
#include <test/util/setup_common.h> // IWYU pragma: keep
-#include <tinyformat.h>
#include <util/fs.h>
-#include <util/string.h>
#include <chrono>
#include <compare>
#include <fstream>
#include <functional>
#include <iostream>
-#include <map>
-#include <ratio>
#include <regex>
-#include <set>
-#include <stdexcept>
#include <string>
+#include <utility>
#include <vector>
using namespace std::chrono_literals;
-using util::Join;
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
@@ -69,37 +63,15 @@ void GenerateTemplateResults(const std::vector<ankerl::nanobench::Result>& bench
namespace benchmark {
-// map a label to one or multiple priority levels
-std::map<std::string, uint8_t> map_label_priority = {
- {"high", PriorityLevel::HIGH},
- {"low", PriorityLevel::LOW},
- {"all", 0xff}
-};
-
-std::string ListPriorities()
-{
- using item_t = std::pair<std::string, uint8_t>;
- auto sort_by_priority = [](item_t a, item_t b){ return a.second < b.second; };
- std::set<item_t, decltype(sort_by_priority)> sorted_priorities(map_label_priority.begin(), map_label_priority.end(), sort_by_priority);
- return Join(sorted_priorities, ',', [](const auto& entry){ return entry.first; });
-}
-
-uint8_t StringToPriority(const std::string& str)
-{
- auto it = map_label_priority.find(str);
- if (it == map_label_priority.end()) throw std::runtime_error(strprintf("Unknown priority level %s", str));
- return it->second;
-}
-
BenchRunner::BenchmarkMap& BenchRunner::benchmarks()
{
static BenchmarkMap benchmarks_map;
return benchmarks_map;
}
-BenchRunner::BenchRunner(std::string name, BenchFunction func, PriorityLevel level)
+BenchRunner::BenchRunner(std::string name, BenchFunction func)
{
- benchmarks().insert(std::make_pair(name, std::make_pair(func, level)));
+ benchmarks().insert(std::make_pair(name, func));
}
void BenchRunner::RunAll(const Args& args)
@@ -120,12 +92,7 @@ void BenchRunner::RunAll(const Args& args)
};
std::vector<ankerl::nanobench::Result> benchmarkResults;
- for (const auto& [name, bench_func] : benchmarks()) {
- const auto& [func, priority_level] = bench_func;
-
- if (!(priority_level & args.priority)) {
- continue;
- }
+ for (const auto& [name, func] : benchmarks()) {
if (!std::regex_match(name, baseMatch, reFilter)) {
continue;
diff --git a/src/bench/bench.h b/src/bench/bench.h
index f6c41486..8dfd8a77 100644
--- a/src/bench/bench.h
+++ b/src/bench/bench.h
@@ -10,11 +10,9 @@
#include <util/macros.h>
#include <chrono>
-#include <cstdint>
#include <functional>
#include <map>
#include <string>
-#include <utility>
#include <vector>
/*
@@ -42,16 +40,6 @@ using ankerl::nanobench::Bench;
typedef std::function<void(Bench&)> BenchFunction;
-enum PriorityLevel : uint8_t
-{
- LOW = 1 << 0,
- HIGH = 1 << 2,
-};
-
-// List priority labels, comma-separated and sorted by increasing priority
-std::string ListPriorities();
-uint8_t StringToPriority(const std::string& str);
-
struct Args {
bool is_list_only;
bool sanity_check;
@@ -60,25 +48,24 @@ struct Args {
fs::path output_csv;
fs::path output_json;
std::string regex_filter;
- uint8_t priority;
std::vector<std::string> setup_args;
};
class BenchRunner
{
- // maps from "name" -> (function, priority_level)
- typedef std::map<std::string, std::pair<BenchFunction, PriorityLevel>> BenchmarkMap;
+ // maps from "name" -> function
+ using BenchmarkMap = std::map<std::string, BenchFunction>;
static BenchmarkMap& benchmarks();
public:
- BenchRunner(std::string name, BenchFunction func, PriorityLevel level);
+ BenchRunner(std::string name, BenchFunction func);
static void RunAll(const Args& args);
};
} // namespace benchmark
-// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo, priority_level);
+// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo{"foo", foo};
#define BENCHMARK(n, priority_level) \
- benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n, priority_level);
+ benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n)){STRINGIZE(n), n};
#endif // BITCOIN_BENCH_BENCH_H
diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
index 841d6258..987523a1 100644
--- a/src/bench/bench_bitcoin.cpp
+++ b/src/bench/bench_bitcoin.cpp
@@ -18,12 +18,8 @@
#include <sstream>
#include <vector>
-using util::SplitString;
-
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"};
static void SetupBenchArgs(ArgsManager& argsman)
{
@@ -37,8 +33,6 @@ static void SetupBenchArgs(ArgsManager& argsman)
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);
}
// parses a comma separated list like "10,20,30,50"
@@ -54,14 +48,6 @@ static std::vector<double> parseAsymptote(const std::string& str) {
return numbers;
}
-static uint8_t parsePriorityLevel(const std::string& str) {
- uint8_t levels{0};
- for (const auto& level: SplitString(str, ',')) {
- levels |= benchmark::StringToPriority(level);
- }
- return levels;
-}
-
static std::vector<std::string> parseTestSetupArgs(const ArgsManager& argsman)
{
// Parses unit test framework arguments supported by the benchmark framework.
@@ -144,7 +130,6 @@ int main(int argc, char** argv)
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.setup_args = parseTestSetupArgs(argsman);
benchmark::BenchRunner::RunAll(args);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.