This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
run_benches_for_runtime.sh
executable file
·78 lines (67 loc) · 2.14 KB
/
run_benches_for_runtime.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Runs all benchmarks for all pallets, for a given runtime, provided by $1
# Should be run on a reference machine to gain accurate benchmarks
# current reference machine: https://github.com/paritytech/substrate/pull/5848
runtime="$1"
echo "[+] Compiling benchmarks..."
cargo build --profile production --locked --features=runtime-benchmarks
# Load all pallet names in an array.
PALLETS=($(
./target/production/polkadot benchmark pallet --list --chain="${runtime}-dev" |\
tail -n+2 |\
cut -d',' -f1 |\
sort |\
uniq
))
echo "[+] Benchmarking ${#PALLETS[@]} pallets for runtime $runtime"
# Define the error file.
ERR_FILE="benchmarking_errors.txt"
# Delete the error file before each run.
rm -f $ERR_FILE
# Benchmark each pallet.
for PALLET in "${PALLETS[@]}"; do
echo "[+] Benchmarking $PALLET for $runtime";
output_file=""
if [[ $PALLET == *"::"* ]]; then
# translates e.g. "pallet_foo::bar" to "pallet_foo_bar"
output_file="${PALLET//::/_}.rs"
fi
OUTPUT=$(
./target/production/polkadot benchmark pallet \
--chain="${runtime}-dev" \
--steps=50 \
--repeat=20 \
--pallet="$PALLET" \
--extrinsic="*" \
--execution=wasm \
--wasm-execution=compiled \
--header=./file_header.txt \
--output="./runtime/${runtime}/src/weights/${output_file}" 2>&1
)
if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
fi
done
# Update the block and extrinsic overhead weights.
echo "[+] Benchmarking block and extrinsic overheads..."
OUTPUT=$(
./target/production/polkadot benchmark overhead \
--chain="${runtime}-dev" \
--execution=wasm \
--wasm-execution=compiled \
--weight-path="runtime/${runtime}/constants/src/weights/" \
--warmup=10 \
--repeat=100 \
--header=./file_header.txt
)
if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark the block and extrinsic overheads. Error written to $ERR_FILE; continuing..."
fi
# Check if the error file exists.
if [ -f "$ERR_FILE" ]; then
echo "[-] Some benchmarks failed. See: $ERR_FILE"
else
echo "[+] All benchmarks passed."
fi