Page MenuHomePhabricator

No OneTemporary

diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include
index dd5fc223e6..ecc6c6a31c 100644
--- a/src/Makefile.bench.include
+++ b/src/Makefile.bench.include
@@ -1,93 +1,95 @@
# Copyright (c) 2015-2016 The Bitcoin 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_bitcoin
BENCH_SRCDIR = bench
BENCH_BINARY = bench/bench_bitcoin$(EXEEXT)
RAW_BENCH_FILES = \
bench/data/block413567.raw
GENERATED_BENCH_FILES = $(RAW_BENCH_FILES:.raw=.raw.h)
bench_bench_bitcoin_SOURCES = \
$(RAW_BENCH_FILES) \
bench/bench_bitcoin.cpp \
bench/bench.cpp \
bench/bench.h \
bench/block_assemble.cpp \
bench/cashaddr.cpp \
bench/checkblock.cpp \
bench/checkqueue.cpp \
+ bench/data.h \
+ bench/data.cpp \
bench/duplicate_inputs.cpp \
bench/examples.cpp \
bench/rollingbloom.cpp \
bench/crypto_aes.cpp \
bench/crypto_hash.cpp \
bench/ccoins_caching.cpp \
bench/gcs_filter.cpp \
bench/merkle_root.cpp \
bench/mempool_eviction.cpp \
bench/rpc_mempool.cpp \
bench/util_time.cpp \
bench/base58.cpp \
bench/lockedpool.cpp \
bench/prevector.cpp \
test/setup_common.h \
test/setup_common.cpp \
test/util.h \
test/util.cpp
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
bench_bench_bitcoin_LDADD = \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_SERVER) \
$(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBLEVELDB) \
$(LIBLEVELDB_SSE42) \
$(LIBMEMENV) \
$(LIBSECP256K1) \
$(LIBUNIVALUE) \
$(EVENT_PTHREADS_LIBS) \
$(EVENT_LIBS)
if ENABLE_ZMQ
bench_bench_bitcoin_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif
if ENABLE_WALLET
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
endif
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
bench_bench_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)
CLEANFILES += $(CLEAN_BITCOIN_BENCH)
-bench/checkblock.cpp: bench/data/block413567.raw.h
+bench/data.cpp: bench/data/block413567.raw.h
bitcoin_bench: $(BENCH_BINARY)
bench: $(BENCH_BINARY) FORCE
$(BENCH_BINARY)
bitcoin_bench_clean : FORCE
rm -f $(CLEAN_BITCOIN_BENCH) $(bench_bench_bitcoin_OBJECTS) $(BENCH_BINARY)
%.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" "$@"
@echo "Generated $@"
diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt
index a702879ba0..e68d1eccd1 100644
--- a/src/bench/CMakeLists.txt
+++ b/src/bench/CMakeLists.txt
@@ -1,74 +1,75 @@
# Copyright (c) 2018 The Bitcoin developers
project(bitcoin-bench)
set(BENCH_DATA_RAW_FILES
data/block413567.raw
)
# Process raw files.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/data")
foreach(_raw_file ${BENCH_DATA_RAW_FILES})
string(APPEND
_generated_header_output
"${CMAKE_CURRENT_BINARY_DIR}/${_raw_file}" ".h"
)
list(APPEND BENCH_DATA_GENERATED_HEADERS ${_generated_header_output})
get_filename_component(_test_name ${_raw_file} NAME_WE)
add_custom_command(
OUTPUT "${_generated_header_output}"
COMMAND
"${Python_EXECUTABLE}"
"data/convert-raw-to-header.py"
"${_test_name}"
"${_raw_file}" > "${_generated_header_output}"
COMMENT "Transforming raw file ${_raw_file} into header"
MAIN_DEPEDENCY "${_raw_file}"
DEPENDS "data/convert-raw-to-header.py"
VERBATIM
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endforeach()
add_executable(bitcoin-bench
base58.cpp
bench.cpp
bench_bitcoin.cpp
block_assemble.cpp
cashaddr.cpp
ccoins_caching.cpp
checkblock.cpp
checkqueue.cpp
crypto_aes.cpp
crypto_hash.cpp
+ data.cpp
duplicate_inputs.cpp
examples.cpp
gcs_filter.cpp
lockedpool.cpp
mempool_eviction.cpp
merkle_root.cpp
prevector.cpp
rollingbloom.cpp
rpc_mempool.cpp
util_time.cpp
# TODO: make a test library
../test/setup_common.cpp
../test/util.cpp
# Add the generated headers to trigger the conversion command
${BENCH_DATA_GENERATED_HEADERS}
)
target_link_libraries(bitcoin-bench common bitcoinconsensus server)
if(BUILD_BITCOIN_WALLET)
target_sources(bitcoin-bench PRIVATE coin_selection.cpp)
target_link_libraries(bitcoin-bench wallet)
endif()
add_custom_target(bench-bitcoin COMMAND bitcoin-bench USES_TERMINAL)
diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp
index c18e6521ad..222b57b304 100644
--- a/src/bench/checkblock.cpp
+++ b/src/bench/checkblock.cpp
@@ -1,63 +1,56 @@
// Copyright (c) 2016 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 <bench/bench.h>
+#include <bench/data.h>
#include <chainparams.h>
#include <config.h>
#include <consensus/validation.h>
#include <streams.h>
#include <validation.h>
-namespace block_bench {
-#include <bench/data/block413567.raw.h>
-} // namespace block_bench
-
// 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::block413567,
- (const char *)block_bench::block413567 +
- sizeof(block_bench::block413567),
- SER_NETWORK, PROTOCOL_VERSION);
+ CDataStream stream(benchmark::data::block413567, SER_NETWORK,
+ PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction
while (state.KeepRunning()) {
CBlock block;
stream >> block;
- bool rewound = stream.Rewind(sizeof(block_bench::block413567));
+ bool rewound = stream.Rewind(benchmark::data::block413567.size());
assert(rewound);
}
}
static void DeserializeAndCheckBlockTest(benchmark::State &state) {
- CDataStream stream((const char *)block_bench::block413567,
- (const char *)block_bench::block413567 +
- sizeof(block_bench::block413567),
- SER_NETWORK, PROTOCOL_VERSION);
+ CDataStream stream(benchmark::data::block413567, SER_NETWORK,
+ PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction
const Config &config = GetConfig();
const Consensus::Params params = config.GetChainParams().GetConsensus();
BlockValidationOptions options(config);
while (state.KeepRunning()) {
// Note that CBlock caches its checked state, so we need to recreate it
// here.
CBlock block;
stream >> block;
- bool rewound = stream.Rewind(sizeof(block_bench::block413567));
+ bool rewound = stream.Rewind(benchmark::data::block413567.size());
assert(rewound);
CValidationState validationState;
bool checked = CheckBlock(block, validationState, params, options);
assert(checked);
}
}
BENCHMARK(DeserializeBlockTest, 130);
BENCHMARK(DeserializeAndCheckBlockTest, 160);
diff --git a/src/bench/data.cpp b/src/bench/data.cpp
new file mode 100644
index 0000000000..cf47b5b0d5
--- /dev/null
+++ b/src/bench/data.cpp
@@ -0,0 +1,16 @@
+// 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 <bench/data.h>
+
+namespace benchmark {
+namespace data {
+
+#include <bench/data/block413567.raw.h>
+ const std::vector<uint8_t> block413567{
+ block413567_raw,
+ block413567_raw + sizeof(block413567_raw) / sizeof(block413567_raw[0])};
+
+} // namespace data
+} // namespace benchmark
diff --git a/src/bench/data.h b/src/bench/data.h
new file mode 100644
index 0000000000..c944c4a884
--- /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 <cstdint>
+#include <vector>
+
+namespace benchmark {
+namespace data {
+
+ extern const std::vector<uint8_t> block413567;
+
+} // namespace data
+} // namespace benchmark
+
+#endif // BITCOIN_BENCH_DATA_H
diff --git a/src/bench/data/convert-raw-to-header.py b/src/bench/data/convert-raw-to-header.py
index b5f9890e3e..6b2e40d331 100755
--- a/src/bench/data/convert-raw-to-header.py
+++ b/src/bench/data/convert-raw-to-header.py
@@ -1,21 +1,21 @@
#!/usr/bin/env python3
# Copyright (c) 2019 The Bitcoin developers
import sys
def main(test_name, input_file):
with open(input_file, "rb") as f:
contents = f.read()
- print("static unsigned const char {}[] = {{".format(test_name))
+ print("static unsigned const char {}_raw[] = {{".format(test_name))
print(", ".join(map(lambda x: "0x{:02x}".format(x), contents)))
print("};")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("We need additional pylons!")
sys.exit(1)
main(sys.argv[1], sys.argv[2])

File Metadata

Mime Type
text/x-diff
Expires
Wed, May 21, 19:05 (22 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5861215
Default Alt Text
(9 KB)

Event Timeline