|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# This script can be used for running litentry's benchmarks. |
| 4 | +# |
| 5 | +# The litentry binary is required to be compiled with make build-node-benchmarks |
| 6 | +# in release mode. |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +BINARY="./target/release/litentry-collator" |
| 11 | + |
| 12 | + |
| 13 | +if [[ ! -f "${BINARY}" ]]; then |
| 14 | + echo "binary '${BINARY}' does not exist." |
| 15 | + echo "ensure that the litentry binary is compiled with 'make build-node-benchmarks' and in release mode." |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +function help { |
| 20 | + echo "USAGE:" |
| 21 | + echo " ${0} litentry|litmuts|rococo pallet_name benchmark_method [--check]" |
| 22 | + echo "" |
| 23 | + echo "EXAMPLES:" |
| 24 | + echo " ${0} " "list all benchmarks and provide a selection to choose from" |
| 25 | + echo " ${0} --check " "list all benchmarks and provide a selection to choose from, runs in 'check' mode (reduced steps and repetitions)" |
| 26 | + echo " ${0} foo bar " "run a benchmark for pallet 'foo' and benchmark 'bar'" |
| 27 | + echo " ${0} foo bar all " "run the pallet all benchmark method" |
| 28 | +} |
| 29 | + |
| 30 | +WEIGHTS_PATH="$(pwd)/weights" |
| 31 | +if [ ! -d $WEIGHTS_PATH ];then |
| 32 | + mkdir -p weights/ |
| 33 | + |
| 34 | +fi |
| 35 | + |
| 36 | +CHAIN_TYPE="--chain=${1}-dev" |
| 37 | +PALLET=${2//-/_} |
| 38 | + |
| 39 | +EXTRINSIC= |
| 40 | + |
| 41 | +if [[ ${3} == 'all' ]];then |
| 42 | + EXTRINSIC=* |
| 43 | +else |
| 44 | + EXTRINSIC=${3//-/_} |
| 45 | +fi |
| 46 | + |
| 47 | +function choose_and_bench { |
| 48 | + readarray -t options < <(${BINARY} benchmark pallet --list $CHAIN_TYPE | sed 1d) |
| 49 | + options+=('EXIT') |
| 50 | + |
| 51 | + select opt in "${options[@]}"; do |
| 52 | + IFS=', ' read -ra parts <<< "${opt}" |
| 53 | + [[ "${opt}" == 'EXIT' ]] && exit 0 |
| 54 | + |
| 55 | + bench "${parts[0]}" "${parts[1]}" "${2}" |
| 56 | + break |
| 57 | + done |
| 58 | +} |
| 59 | + |
| 60 | +function bench { |
| 61 | + echo "pallet ${1}-weights.rs" |
| 62 | + OUTPUT="--output=$(pwd)/weights/${1}_weights.rs" |
| 63 | + |
| 64 | + echo "benchmarking '${1}::${2}' --check=${3}, writing results to '${OUTPUT}'" |
| 65 | + |
| 66 | + if [[ $PALLET == *"parachain_staking"* ]]; then |
| 67 | + echo "will run ${1} benchmark code" |
| 68 | + STEPS=25 |
| 69 | + REPEAT=20 |
| 70 | + else |
| 71 | + echo "will run other pallet (${1}) benchmark code" |
| 72 | + STEPS=20 |
| 73 | + REPEAT=50 |
| 74 | + fi |
| 75 | + |
| 76 | + WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \ |
| 77 | + $CHAIN_TYPE \ |
| 78 | + --execution=wasm \ |
| 79 | + --db-cache=20 \ |
| 80 | + --wasm-execution=compiled \ |
| 81 | + --pallet="$PALLET" \ |
| 82 | + --extrinsic="$EXTRINSIC" \ |
| 83 | + --heap-pages=4096 \ |
| 84 | + --steps="$STEPS" \ |
| 85 | + --repeat="$REPEAT" \ |
| 86 | + --header=./LICENSE_HEADER \ |
| 87 | + $TEMPLATE \ |
| 88 | + $OUTPUT |
| 89 | + |
| 90 | +} |
| 91 | + |
| 92 | +if [[ "${@}" =~ "--help" ]]; then |
| 93 | + help |
| 94 | +else |
| 95 | + CHECK=0 |
| 96 | + if [[ "${@}" =~ "--check" ]]; then |
| 97 | + CHECK=1 |
| 98 | + set -o noglob && set -- ${@/'--check'} && set +o noglob |
| 99 | + fi |
| 100 | + |
| 101 | + ALL=0 |
| 102 | + if [[ "${@}" =~ "--all" ]]; then |
| 103 | + ALL=1 |
| 104 | + fi |
| 105 | + |
| 106 | + if [[ "${ALL}" -eq 1 ]]; then |
| 107 | + bench '*' '*' "${CHECK}" "weights/" |
| 108 | + elif [[ $# -ne 2 ]]; then |
| 109 | + choose_and_bench "${CHECK}" |
| 110 | + else |
| 111 | + bench "${2}" "${3}" "${CHECK}" |
| 112 | + fi |
| 113 | +fi |
0 commit comments