Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
load_external.cpp
Go to the documentation of this file.
1
// Copyright (c) 2022-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
4
5
#include <
bench/bench.h
>
6
#include <bench/data/block413567.raw.h>
7
#include <chainparams.h>
8
#include <
flatfile.h
>
9
#include <
node/blockstorage.h
>
10
#include <
span.h
>
11
#include <
streams.h
>
12
#include <
test/util/setup_common.h
>
13
#include <
uint256.h
>
14
#include <
util/fs.h
>
15
#include <validation.h>
16
17
#include <cstdint>
18
#include <cstdio>
19
#include <map>
20
#include <memory>
21
#include <stdexcept>
22
#include <vector>
23
36
static
void
LoadExternalBlockFile
(
benchmark::Bench
& bench)
37
{
38
const
auto
testing_setup{
MakeNoLogFileContext<const TestingSetup>
(
ChainType::MAIN
)};
39
40
// Create a single block as in the blocks files (magic bytes, block size,
41
// block data) as a stream object.
42
const
fs::path blkfile{testing_setup.get()->m_path_root /
"blk.dat"
};
43
DataStream
ss
{};
44
auto
params{testing_setup->m_node.chainman->GetParams()};
45
ss
<< params.MessageStart();
46
ss << static_cast<uint32_t>
(benchmark::data::block413567.size());
47
// Use span-serialization to avoid writing the size first.
48
ss
<< std::span{benchmark::data::block413567};
49
50
// Create the test file.
51
{
52
// "wb+" is "binary, O_RDWR | O_CREAT | O_TRUNC".
53
FILE* file{
fsbridge::fopen
(blkfile,
"wb+"
)};
54
// Make the test block file about 128 MB in length.
55
for
(
size_t
i = 0; i <
node::MAX_BLOCKFILE_SIZE
/
ss
.size(); ++i) {
56
if
(fwrite(
ss
.data(), 1,
ss
.size(), file) !=
ss
.size()) {
57
throw
std::runtime_error(
"write to test file failed\n"
);
58
}
59
}
60
fclose(file);
61
}
62
63
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
64
FlatFilePos
pos;
65
bench.
run
([&] {
66
// "rb" is "binary, O_RDONLY", positioned to the start of the file.
67
// The file will be closed by LoadExternalBlockFile().
68
AutoFile
file{
fsbridge::fopen
(blkfile,
"rb"
)};
69
testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
70
});
71
fs::remove(blkfile);
72
}
73
74
BENCHMARK
(
LoadExternalBlockFile
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
blockstorage.h
ChainType::MAIN
@ MAIN
Definition
chaintype.h:12
AutoFile
Non-refcounted RAII wrapper for FILE*.
Definition
streams.h:373
DataStream
Double ended buffer combining vector and stream-like interfaces.
Definition
streams.h:133
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
flatfile.h
fs.h
LoadExternalBlockFile
static void LoadExternalBlockFile(benchmark::Bench &bench)
The LoadExternalBlockFile() function is used during -reindex and -loadblock.
Definition
load_external.cpp:36
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition
fs.cpp:25
node::MAX_BLOCKFILE_SIZE
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?
Definition
blockstorage.h:123
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:250
span.h
streams.h
FlatFilePos
Definition
flatfile.h:15
uint256.h
ss
DataStream ss
Definition
uint256_tests.cpp:181
Generated on
for Bitcoin Core by
1.17.0