Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
logging.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present 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
#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
18
static
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.
21
LogInstance
().
DisableCategory
(
BCLog::LogFlags::ALL
);
22
23
TestingSetup
test_setup{
24
ChainType::REGTEST
,
25
{.extra_args = extra_args},
26
};
27
28
bench.
run
([&] { log(); });
29
}
30
31
static
void
LogWithDebug
(
benchmark::Bench
& bench)
32
{
33
Logging
(bench, {
"-logthreadnames=0"
,
"-debug=net"
}, [] {
LogDebug
(
BCLog::NET
,
"%s\n"
,
"test"
); });
34
}
35
36
static
void
LogWithoutDebug
(
benchmark::Bench
& bench)
37
{
38
Logging
(bench, {
"-logthreadnames=0"
,
"-debug=0"
}, [] {
LogDebug
(
BCLog::NET
,
"%s\n"
,
"test"
); });
39
}
40
41
static
void
LogWithThreadNames
(
benchmark::Bench
& bench)
42
{
43
Logging
(bench, {
"-logthreadnames=1"
}, [] {
LogInfo
(
"%s\n"
,
"test"
); });
44
}
45
46
static
void
LogWithoutThreadNames
(
benchmark::Bench
& bench)
47
{
48
Logging
(bench, {
"-logthreadnames=0"
}, [] {
LogInfo
(
"%s\n"
,
"test"
); });
49
}
50
51
static
void
LogWithoutWriteToFile
(
benchmark::Bench
& bench)
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
60
BENCHMARK
(
LogWithDebug
);
61
BENCHMARK
(
LogWithoutDebug
);
62
BENCHMARK
(
LogWithThreadNames
);
63
BENCHMARK
(
LogWithoutThreadNames
);
64
BENCHMARK
(
LogWithoutWriteToFile
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
LogWithThreadNames
static void LogWithThreadNames(benchmark::Bench &bench)
Definition
logging.cpp:41
LogWithoutWriteToFile
static void LogWithoutWriteToFile(benchmark::Bench &bench)
Definition
logging.cpp:51
LogWithoutDebug
static void LogWithoutDebug(benchmark::Bench &bench)
Definition
logging.cpp:36
LogWithDebug
static void LogWithDebug(benchmark::Bench &bench)
Definition
logging.cpp:31
Logging
static void Logging(benchmark::Bench &bench, const std::vector< const char * > &extra_args, const std::function< void()> &log)
Definition
logging.cpp:18
LogWithoutThreadNames
static void LogWithoutThreadNames(benchmark::Bench &bench)
Definition
logging.cpp:46
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:15
BCLog::Logger::DisableCategory
void DisableCategory(LogFlags flag)
Definition
logging.cpp:136
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
LogInfo
#define LogInfo(...)
Definition
log.h:95
LogDebug
#define LogDebug(category,...)
Definition
log.h:115
LogInstance
BCLog::Logger & LogInstance()
Definition
logging.cpp:26
BCLog::ALL
@ ALL
Definition
categories.h:49
BCLog::NET
@ NET
Definition
categories.h:16
setup_common.h
TestingSetup
Testing setup that configures a complete environment.
Definition
setup_common.h:121
Generated on
for Bitcoin Core by
1.17.0