From b82d08a7416921596f54560e9388ea3ff117a820 Mon Sep 17 00:00:00 2001 From: furszy Date: Wed, 2 Jun 2021 19:19:08 -0300 Subject: [PATCH 1/3] Bugfix: bench framework, correct raw generated files name. --- src/Makefile.bench.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index 9b7d1855ceec..33f7833d42b1 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -68,7 +68,7 @@ bitcoin_bench_clean : FORCE %.raw.h: %.raw @$(MKDIR_P) $(@D) @{ \ - echo "static unsigned const char $(*F)[] = {" && \ + echo "static unsigned const char $(*F)_raw[] = {" && \ $(HEXDUMP) -v -e '8/1 "0x%02x, "' -e '"\n"' $< | $(SED) -e 's/0x ,//g' && \ echo "};"; \ } > "$@.new" && mv -f "$@.new" "$@" From 295e2d45435eb4affb88aee62ad7cb6b683314d9 Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 11 Jun 2021 14:37:57 -0300 Subject: [PATCH 2/3] bench: Move generated data to a dedicated translation unit Idea coming from btc@3d60a03a7cfb2d46b5f10633e9f6a9a36b8cb76f --- src/Makefile.bench.include | 4 +++- src/bench/checkblock.cpp | 25 ++++++++++--------------- src/bench/data.cpp | 14 ++++++++++++++ src/bench/data.h | 19 +++++++++++++++++++ 4 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 src/bench/data.cpp create mode 100644 src/bench/data.h diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index 33f7833d42b1..b6a0b8c80190 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -15,6 +15,8 @@ bench_bench_pivx_SOURCES = \ bench/base58.cpp \ bench/checkblock.cpp \ bench/checkqueue.cpp \ + bench/data.h \ + bench/data.cpp \ bench/chacha20.cpp \ bench/crypto_hash.cpp \ bench/lockedpool.cpp \ @@ -55,7 +57,7 @@ CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_TEST_FILES) CLEANFILES += $(CLEAN_BITCOIN_BENCH) -bench/checkblock.cpp: bench/data/block2680960.raw.h +bench/data.cpp: bench/data/block2680960.raw.h bitcoin_bench: $(BENCH_BINARY) diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 13f672bd21e7..2516eabdcd89 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -2,39 +2,33 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "bench.h" +#include "bench/bench.h" +#include "bench/data.h" #include "validation.h" -namespace block_bench { -#include "bench/data/block2680960.raw.h" -} - // These are the two major time-sinks which happen after we have fully received // a block off the wire, but before we can relay the block on to peers using // compact block relay. static void DeserializeBlockTest(benchmark::State& state) { - CDataStream stream((const char*)block_bench::block2680960, - (const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)], - SER_NETWORK, PROTOCOL_VERSION); - char a; + CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION); + char a = '\0'; stream.write(&a, 1); // Prevent compaction while (state.KeepRunning()) { CBlock block; stream >> block; - assert(stream.Rewind(sizeof(block_bench::block2680960))); + bool rewound = stream.Rewind(benchmark::data::block2680960.size()); + assert(rewound); } } static void DeserializeAndCheckBlockTest(benchmark::State& state) { - CDataStream stream((const char*)block_bench::block2680960, - (const char*)&block_bench::block2680960[sizeof(block_bench::block2680960)], - SER_NETWORK, PROTOCOL_VERSION); - char a; + CDataStream stream(benchmark::data::block2680960, SER_NETWORK, PROTOCOL_VERSION); + char a = '\0'; stream.write(&a, 1); // Prevent compaction SelectParams(CBaseChainParams::MAIN); @@ -42,7 +36,8 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here stream >> block; - assert(stream.Rewind(sizeof(block_bench::block2680960))); + bool rewound = stream.Rewind(benchmark::data::block2680960.size()); + assert(rewound); CValidationState state; assert(CheckBlock(block, state)); diff --git a/src/bench/data.cpp b/src/bench/data.cpp new file mode 100644 index 000000000000..e2eb827fa837 --- /dev/null +++ b/src/bench/data.cpp @@ -0,0 +1,14 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +namespace benchmark { +namespace data { + +#include +const std::vector block2680960{block2680960_raw, block2680960_raw + sizeof(block2680960_raw) / sizeof(block2680960_raw[0])}; + +} // namespace data +} // namespace benchmark diff --git a/src/bench/data.h b/src/bench/data.h new file mode 100644 index 000000000000..3e0524fe2856 --- /dev/null +++ b/src/bench/data.h @@ -0,0 +1,19 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_BENCH_DATA_H +#define BITCOIN_BENCH_DATA_H + +#include +#include + +namespace benchmark { +namespace data { + +extern const std::vector block2680960; + +} // namespace data +} // namespace benchmark + +#endif // BITCOIN_BENCH_DATA_H From f5d4727c6b7169d69a612c4514acfede6f098cc5 Mon Sep 17 00:00:00 2001 From: furszy Date: Thu, 15 Jul 2021 11:35:31 -0300 Subject: [PATCH 3/3] [Bench] Fix .raw.h generated files not being removed with make clean. --- src/Makefile.bench.include | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index b6a0b8c80190..c48539d12a53 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -1,13 +1,18 @@ +# Copyright (c) 2015-2021 The Bitcoin Core developers +# Copyright (c) 2020-2021 The PIVX Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + bin_PROGRAMS += bench/bench_pivx BENCH_SRCDIR = bench BENCH_BINARY = bench/bench_pivx$(EXEEXT) -RAW_TEST_FILES = \ +RAW_BENCH_FILES = \ bench/data/block2680960.raw - -GENERATED_TEST_FILES = $(RAW_TEST_FILES:.raw=.raw.h) +GENERATED_BENCH_FILES = $(RAW_BENCH_FILES:.raw=.raw.h) bench_bench_pivx_SOURCES = \ + $(RAW_BENCH_FILES) \ bench/bench_pivx.cpp \ bench/bench.cpp \ bench/bench.h \ @@ -25,7 +30,7 @@ bench_bench_pivx_SOURCES = \ bench/prevector.cpp \ bench/util_time.cpp -nodist_bench_bench_pivx_SOURCES = $(GENERATED_TEST_FILES) +nodist_bench_bench_pivx_SOURCES = $(GENERATED_BENCH_FILES) bench_bench_pivx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/ bench_bench_pivx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -52,8 +57,7 @@ endif bench_bench_pivx_LDADD += $(LIBBITCOIN_CONSENSUS) $(BOOST_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) bench_bench_pivx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -# !TODO: .raw.h generated test files are not removed with make clean -CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_TEST_FILES) +CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES) CLEANFILES += $(CLEAN_BITCOIN_BENCH)