-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathbenchmarking.sh
executable file
·93 lines (78 loc) · 2.93 KB
/
benchmarking.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# This script can be used for running moonbeam's benchmarks.
#
# The moonbeam binary is required to be compiled with --features=runtime-benchmarks
# in release mode.
set -e
BINARY="./target/release/moonbeam"
STEPS=50
REPEAT=20
if [[ ! -f "${BINARY}" ]]; then
echo "binary '${BINARY}' does not exist."
echo "ensure that the moonbeam binary is compiled with '--features=runtime-benchmarks' and in release mode."
exit 1
fi
function help {
echo "USAGE:"
echo " ${0} [<pallet> <benchmark>] [--check]"
echo ""
echo "EXAMPLES:"
echo " ${0} " "list all benchmarks and provide a selection to choose from"
echo " ${0} --check " "list all benchmarks and provide a selection to choose from, runs in 'check' mode (reduced steps and repetitions)"
echo " ${0} foo bar " "run a benchmark for pallet 'foo' and benchmark 'bar'"
echo " ${0} foo bar --check " "run a benchmark for pallet 'foo' and benchmark 'bar' in 'check' mode (reduced steps and repetitions)"
echo " ${0} foo bar --all " "run a benchmark for all pallets"
echo " ${0} foo bar --all --check " "run a benchmark for all pallets in 'check' mode (reduced steps and repetitions)"
}
function choose_and_bench {
readarray -t options < <(${BINARY} benchmark pallet --list | sed 1d)
options+=('EXIT')
select opt in "${options[@]}"; do
IFS=', ' read -ra parts <<< "${opt}"
[[ "${opt}" == 'EXIT' ]] && exit 0
bench "${parts[0]}" "${parts[1]}" "${1}"
break
done
}
function bench {
OUTPUT=${4:-weights.rs}
echo "benchmarking '${1}::${2}' --check=${3}, writing results to '${OUTPUT}'"
# Check enabled
if [[ "${3}" -eq 1 ]]; then
STEPS=16
REPEAT=1
fi
WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \
--execution=wasm \
--wasm-execution=compiled \
--pallet "${1}" \
--extrinsic "${2}" \
--steps "${STEPS}" \
--repeat "${REPEAT}" \
--header=./file_header.txt \
--template=./benchmarking/frame-weight-template.hbs \
--json-file raw.json \
--output "${OUTPUT}"
}
echo -e "\e[33m**Warning**: The benchmarking script will overwrite the pallet_proxy.rs file in runtime/common/src/weights. This file was manually modified to include an additional DB Read for proxy.proxy. Make sure to add it again after running the benchmarking script.\e[0m"
if [[ "${@}" =~ "--help" ]]; then
help
else
CHECK=0
if [[ "${@}" =~ "--check" ]]; then
CHECK=1
set -o noglob && set -- ${@/'--check'} && set +o noglob
fi
ALL=0
if [[ "${@}" =~ "--all" ]]; then
ALL=1
fi
if [[ "${ALL}" -eq 1 ]]; then
mkdir -p weights/
bench '*' '*' "${CHECK}" "weights/"
elif [[ $# -ne 2 ]]; then
choose_and_bench "${CHECK}"
else
bench "${1}" "${2}" "${CHECK}"
fi
fi