Skip to content

Commit 630756c

Browse files
committed
Merge bitcoin/bitcoin#26957: bench: update logging benchmarks
8c47d59 doc: improve -debuglogfile help to be a bit clearer (jonatack) 20d89d6 bench: document expected results in logging benchmarks (jonatack) d8deba8 bench: add LogPrintfCategory and LogPrintLevel benchmarks (Jon Atack) 102b203 bench: order the logging benchmark code by output (Jon Atack) 4b3fdbf bench: update logging benchmark naming for clarity (Jon Atack) 4684aa8 bench: allow logging benchmarks to be order-independent (Larry Ruane) Pull request description: Update our logging benchmarks for evaluating ongoing work like #25203 and refactoring proposals like #26619 and #26697. - make the logging benchmarks order-independent (Larry Ruane) - add missing benchmarks for the `LogPrintLevel` and `LogPrintfCategory` macros that our logging is migrating to; at some later point it should be feasible to drop some of the previous logging benchmarks - update the logging benchmark naming to be clear which benchmark corresponds to which log macro, and update the ordering to be the same as the output - add clarifying documentation to the logging benchmarks - improve the `-debuglogfile` config option help to be clearer; can be tested by running `./src/bitcoind -help | grep -A4 '\-debuglogfile'` Reviewers can run the logging benchmarks with: ```bash ./src/bench/bench_bitcoin -filter='LogP*.*' ``` ACKs for top commit: LarryRuane: ACK 8c47d59 martinus: code review & tested ACK 8c47d59, here are my benchmark results: achow101: ACK 8c47d59 Tree-SHA512: 705f8720c9ceaf14a1945039c7578a0c17a12215cbc44908099af4ac444561c3f95d833c5a91b325cdd4470737d8a01e2da64db2d542dd7c9a3747fbfdbf213e
2 parents 2305643 + 8c47d59 commit 630756c

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

src/bench/logging.cpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
#include <logging.h>
77
#include <test/util/setup_common.h>
88

9+
// All but 2 of the benchmarks should have roughly similar performance:
10+
//
11+
// LogPrintWithoutCategory should be ~3 orders of magnitude faster, as nothing is logged.
12+
//
13+
// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.
914

1015
static void Logging(benchmark::Bench& bench, const std::vector<const char*>& extra_args, const std::function<void()>& log)
1116
{
17+
// Reset any enabled logging categories from a previous benchmark run.
18+
LogInstance().DisableCategory(BCLog::LogFlags::ALL);
19+
1220
TestingSetup test_setup{
1321
CBaseChainParams::REGTEST,
1422
extra_args,
@@ -17,32 +25,67 @@ static void Logging(benchmark::Bench& bench, const std::vector<const char*>& ext
1725
bench.run([&] { log(); });
1826
}
1927

20-
static void LoggingYoThreadNames(benchmark::Bench& bench)
28+
static void LogPrintLevelWithThreadNames(benchmark::Bench& bench)
2129
{
22-
Logging(bench, {"-logthreadnames=1"}, [] { LogPrintf("%s\n", "test"); });
30+
Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] {
31+
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); });
2332
}
24-
static void LoggingNoThreadNames(benchmark::Bench& bench)
33+
34+
static void LogPrintLevelWithoutThreadNames(benchmark::Bench& bench)
2535
{
26-
Logging(bench, {"-logthreadnames=0"}, [] { LogPrintf("%s\n", "test"); });
36+
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] {
37+
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); });
2738
}
28-
static void LoggingYoCategory(benchmark::Bench& bench)
39+
40+
static void LogPrintWithCategory(benchmark::Bench& bench)
2941
{
3042
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
3143
}
32-
static void LoggingNoCategory(benchmark::Bench& bench)
44+
45+
static void LogPrintWithoutCategory(benchmark::Bench& bench)
3346
{
3447
Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
3548
}
36-
static void LoggingNoFile(benchmark::Bench& bench)
49+
50+
static void LogPrintfCategoryWithThreadNames(benchmark::Bench& bench)
51+
{
52+
Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] {
53+
LogPrintfCategory(BCLog::NET, "%s\n", "test");
54+
});
55+
}
56+
57+
static void LogPrintfCategoryWithoutThreadNames(benchmark::Bench& bench)
58+
{
59+
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] {
60+
LogPrintfCategory(BCLog::NET, "%s\n", "test");
61+
});
62+
}
63+
64+
static void LogPrintfWithThreadNames(benchmark::Bench& bench)
65+
{
66+
Logging(bench, {"-logthreadnames=1"}, [] { LogPrintf("%s\n", "test"); });
67+
}
68+
69+
static void LogPrintfWithoutThreadNames(benchmark::Bench& bench)
70+
{
71+
Logging(bench, {"-logthreadnames=0"}, [] { LogPrintf("%s\n", "test"); });
72+
}
73+
74+
static void LogWithoutWriteToFile(benchmark::Bench& bench)
3775
{
76+
// Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.
3877
Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
3978
LogPrintf("%s\n", "test");
4079
LogPrint(BCLog::NET, "%s\n", "test");
4180
});
4281
}
4382

44-
BENCHMARK(LoggingYoThreadNames, benchmark::PriorityLevel::HIGH);
45-
BENCHMARK(LoggingNoThreadNames, benchmark::PriorityLevel::HIGH);
46-
BENCHMARK(LoggingYoCategory, benchmark::PriorityLevel::HIGH);
47-
BENCHMARK(LoggingNoCategory, benchmark::PriorityLevel::HIGH);
48-
BENCHMARK(LoggingNoFile, benchmark::PriorityLevel::HIGH);
83+
BENCHMARK(LogPrintLevelWithThreadNames, benchmark::PriorityLevel::HIGH);
84+
BENCHMARK(LogPrintLevelWithoutThreadNames, benchmark::PriorityLevel::HIGH);
85+
BENCHMARK(LogPrintWithCategory, benchmark::PriorityLevel::HIGH);
86+
BENCHMARK(LogPrintWithoutCategory, benchmark::PriorityLevel::HIGH);
87+
BENCHMARK(LogPrintfCategoryWithThreadNames, benchmark::PriorityLevel::HIGH);
88+
BENCHMARK(LogPrintfCategoryWithoutThreadNames, benchmark::PriorityLevel::HIGH);
89+
BENCHMARK(LogPrintfWithThreadNames, benchmark::PriorityLevel::HIGH);
90+
BENCHMARK(LogPrintfWithoutThreadNames, benchmark::PriorityLevel::HIGH);
91+
BENCHMARK(LogWithoutWriteToFile, benchmark::PriorityLevel::HIGH);

src/init/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace init {
2424
void AddLoggingArgs(ArgsManager& argsman)
2525
{
26-
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file. Relative paths will be prefixed by a net-specific datadir location. (-nodebuglogfile to disable; default: %s)", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
26+
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file (default: %s). Relative paths will be prefixed by a net-specific datadir location. Pass -nodebuglogfile to disable writing the log to a file.", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2727
argsman.AddArg("-debug=<category>", "Output debug and trace logging (default: -nodebug, supplying <category> is optional). "
2828
"If <category> is not supplied or if <category> = 1, output all debug and trace logging. <category> can be: " + LogInstance().LogCategoriesString() + ". This option can be specified multiple times to output multiple categories.",
2929
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);

0 commit comments

Comments
 (0)