Bitcoin Core 28.99.0
P2P Digital Currency
logging.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
6#include <logging.h>
8
9#include <functional>
10#include <vector>
11
12// All but 2 of the benchmarks should have roughly similar performance:
13//
14// LogWithoutDebug should be ~3 orders of magnitude faster, as nothing is logged.
15//
16// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.
17
18static void Logging(benchmark::Bench& bench, const std::vector<const char*>& extra_args, const std::function<void()>& log)
19{
20 // Reset any enabled logging categories from a previous benchmark run.
22
23 TestingSetup test_setup{
25 {.extra_args = extra_args},
26 };
27
28 bench.run([&] { log(); });
29}
30
31static void LogWithDebug(benchmark::Bench& bench)
32{
33 Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
34}
35
37{
38 Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });
39}
40
42{
43 Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); });
44}
45
47{
48 Logging(bench, {"-logthreadnames=0"}, [] { LogInfo("%s\n", "test"); });
49}
50
52{
53 // Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.
54 Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
55 LogInfo("%s\n", "test");
56 LogDebug(BCLog::NET, "%s\n", "test");
57 });
58}
59
static void LogWithThreadNames(benchmark::Bench &bench)
Definition: logging.cpp:41
static void LogWithoutWriteToFile(benchmark::Bench &bench)
Definition: logging.cpp:51
static void LogWithoutDebug(benchmark::Bench &bench)
Definition: logging.cpp:36
static void LogWithDebug(benchmark::Bench &bench)
Definition: logging.cpp:31
BENCHMARK(LogWithDebug, benchmark::PriorityLevel::HIGH)
static void Logging(benchmark::Bench &bench, const std::vector< const char * > &extra_args, const std::function< void()> &log)
Definition: logging.cpp:18
static void LogWithoutThreadNames(benchmark::Bench &bench)
Definition: logging.cpp:46
void DisableCategory(LogFlags flag)
Definition: logging.cpp:134
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
BCLog::Logger & LogInstance()
Definition: logging.cpp:24
#define LogInfo(...)
Definition: logging.h:261
#define LogDebug(category,...)
Definition: logging.h:280
@ ALL
Definition: logging.h:74
@ NET
Definition: logging.h:43
@ HIGH
Definition: bench.h:48
Testing setup that configures a complete environment.
Definition: setup_common.h:120