aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-09-26 13:46:19 +0100
committerfanquake <fanquake@gmail.com>2023-09-26 14:01:44 +0100
commitc9f288244b8d183e09a917025922b99e3368ef78 (patch)
tree564eb028ffe4a696d0463768051c85cb0a50cf51 /src/bench
parentdcfbf3c2107c3cb9d343ebfa0eee78278dea8d66 (diff)
parentfa56c421be04af846f479c30749b17e6663ab418 (diff)
Merge bitcoin/bitcoin#28483: refactor: Return CAutoFile from BlockManager::Open*File()
fa56c421be04af846f479c30749b17e6663ab418 Return CAutoFile from BlockManager::Open*File() (MarcoFalke) 9999b89cd37fb2a23c5ebcd91d9cb31d69375933 Make BufferedFile to be a CAutoFile wrapper (MarcoFalke) fa389d902fbf5fac19fba8c5d0c5e0a25f15ca63 refactor: Drop unused fclose() from BufferedFile (MarcoFalke) Pull request description: This is required for https://github.com/bitcoin/bitcoin/pull/28052, but makes sense on its own, because offloading logic to `CAutoFile` instead of re-implementing it allows to delete code and complexity. ACKs for top commit: TheCharlatan: Re-ACK fa56c421be04af846f479c30749b17e6663ab418 willcl-ark: tACK fa56c421be Tree-SHA512: fe4638f3a6bd3f9d968cfb9ae3259c9d6cd278fe2912cbc90289851311c8c781099db4c160e775960975c4739098d9af801a8d2d12603f371f8edfe134d8f85a
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/load_external.cpp3
-rw-r--r--src/bench/streams_findbyte.cpp16
2 files changed, 12 insertions, 7 deletions
diff --git a/src/bench/load_external.cpp b/src/bench/load_external.cpp
index 252cbb163b..3b100d97b0 100644
--- a/src/bench/load_external.cpp
+++ b/src/bench/load_external.cpp
@@ -5,6 +5,7 @@
#include <bench/bench.h>
#include <bench/data.h>
#include <chainparams.h>
+#include <clientversion.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <validation.h>
@@ -54,7 +55,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
bench.run([&] {
// "rb" is "binary, O_RDONLY", positioned to the start of the file.
// The file will be closed by LoadExternalBlockFile().
- FILE* file{fsbridge::fopen(blkfile, "rb")};
+ CAutoFile file{fsbridge::fopen(blkfile, "rb"), CLIENT_VERSION};
testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
});
fs::remove(blkfile);
diff --git a/src/bench/streams_findbyte.cpp b/src/bench/streams_findbyte.cpp
index 22b8f1b356..4aaccb2af8 100644
--- a/src/bench/streams_findbyte.cpp
+++ b/src/bench/streams_findbyte.cpp
@@ -4,19 +4,23 @@
#include <bench/bench.h>
-#include <util/fs.h>
#include <streams.h>
+#include <util/fs.h>
+
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
static void FindByte(benchmark::Bench& bench)
{
// Setup
- FILE* file = fsbridge::fopen("streams_tmp", "w+b");
+ CAutoFile file{fsbridge::fopen("streams_tmp", "w+b"), 0};
const size_t file_size = 200;
uint8_t data[file_size] = {0};
data[file_size-1] = 1;
- fwrite(&data, sizeof(uint8_t), file_size, file);
- rewind(file);
- BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, 0};
+ file << data;
+ std::rewind(file.Get());
+ BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size};
bench.run([&] {
bf.SetPos(0);
@@ -24,7 +28,7 @@ static void FindByte(benchmark::Bench& bench)
});
// Cleanup
- bf.fclose();
+ file.fclose();
fs::remove("streams_tmp");
}