Bitcoin ABC 0.34.2
P2P Digital Currency
logging.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 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>
7#include <test/util/setup_common.h>
8
9// All but 2 of the benchmarks should have roughly similar performance:
10//
11// LogPrintWithoutCategory should be ~3 orders of magnitude faster, as nothing
12// is logged.
13//
14// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids
15// disk writes.
16
17static void Logging(benchmark::Bench &bench,
18 const std::vector<const char *> &extra_args,
19 const std::function<void()> &log) {
20 // Reset any enabled logging categories from a previous benchmark run.
21 LogInstance().DisableCategory(BCLog::LogFlags::ALL);
22
23 TestingSetup test_setup{
25 extra_args,
26 };
27
28 bench.run([&] { log(); });
29}
30
31static void LogWithDebug(benchmark::Bench &bench) {
32 Logging(bench, {"-logthreadnames=0", "-debug=net"},
33 [] { LogDebug(BCLog::NET, "%s\n", "test"); });
34}
35
36static void LogWithoutDebug(benchmark::Bench &bench) {
37 Logging(bench, {"-logthreadnames=0", "-debug=0"},
38 [] { LogDebug(BCLog::NET, "%s\n", "test"); });
39}
40
42 Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); });
43}
44
46 Logging(bench, {"-logthreadnames=0"}, [] { LogInfo("%s\n", "test"); });
47}
48
50 // Disable writing the log to a file, as used for unit tests and fuzzing in
51 // `MakeNoLogFileContext`.
52 Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
53 LogPrintf("%s\n", "test");
54 LogInfo("%s\n", "test");
55 LogDebug(BCLog::NET, "%s\n", "test");
56 });
57}
58
static void LogWithThreadNames(benchmark::Bench &bench)
Definition: logging.cpp:41
static void LogWithoutWriteToFile(benchmark::Bench &bench)
Definition: logging.cpp:49
static void LogWithoutDebug(benchmark::Bench &bench)
Definition: logging.cpp:36
static void LogWithDebug(benchmark::Bench &bench)
Definition: logging.cpp:31
BENCHMARK(LogWithDebug)
static void Logging(benchmark::Bench &bench, const std::vector< const char * > &extra_args, const std::function< void()> &log)
Definition: logging.cpp:17
static void LogWithoutThreadNames(benchmark::Bench &bench)
Definition: logging.cpp:45
void DisableCategory(LogFlags category)
Definition: logging.cpp:590
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
BCLog::Logger & LogInstance()
Definition: logging.cpp:28
#define LogInfo(...)
Definition: logging.h:413
#define LogDebug(category,...)
Definition: logging.h:446
#define LogPrintf(...)
Definition: logging.h:424
@ NET
Definition: logging.h:69