Skip to content

Commit

Permalink
Add test local pallets benchmarking shell (#1087)
Browse files Browse the repository at this point in the history
* add local benchmark testing shell

* fix benmarking scripts

* fix some syntax

* fix some syntax

* fix some syntax

Co-authored-by: SCC <chengcheng@litentry.com>
  • Loading branch information
Marky-Shi and SCC authored Dec 13, 2022
1 parent 6f01999 commit 1c1ee63
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions scripts/local-pallets-benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash

# This script can be used for running litentry's benchmarks.
#
# The litentry binary is required to be compiled with make build-node-benchmarks
# in release mode.

set -e

BINARY="./target/release/litentry-collator"


if [[ ! -f "${BINARY}" ]]; then
echo "binary '${BINARY}' does not exist."
echo "ensure that the litentry binary is compiled with 'make build-node-benchmarks' and in release mode."
exit 1
fi

function help {
echo "USAGE:"
echo " ${0} litentry|litmuts|rococo pallet_name benchmark_method [--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 all " "run the pallet all benchmark method"
}

WEIGHTS_PATH="$(pwd)/weights"
if [ ! -d $WEIGHTS_PATH ];then
mkdir -p weights/

fi

CHAIN_TYPE="--chain=${1}-dev"
PALLET=${2//-/_}

EXTRINSIC=

if [[ ${3} == 'all' ]];then
EXTRINSIC=*
else
EXTRINSIC=${3//-/_}
fi

function choose_and_bench {
readarray -t options < <(${BINARY} benchmark pallet --list $CHAIN_TYPE | sed 1d)
options+=('EXIT')

select opt in "${options[@]}"; do
IFS=', ' read -ra parts <<< "${opt}"
[[ "${opt}" == 'EXIT' ]] && exit 0

bench "${parts[0]}" "${parts[1]}" "${2}"
break
done
}

function bench {
echo "pallet ${1}-weights.rs"
OUTPUT="--output=$(pwd)/weights/${1}_weights.rs"

echo "benchmarking '${1}::${2}' --check=${3}, writing results to '${OUTPUT}'"

if [[ $PALLET == *"parachain_staking"* ]]; then
echo "will run ${1} benchmark code"
STEPS=25
REPEAT=20
else
echo "will run other pallet (${1}) benchmark code"
STEPS=20
REPEAT=50
fi

WASMTIME_BACKTRACE_DETAILS=1 ${BINARY} benchmark pallet \
$CHAIN_TYPE \
--execution=wasm \
--db-cache=20 \
--wasm-execution=compiled \
--pallet="$PALLET" \
--extrinsic="$EXTRINSIC" \
--heap-pages=4096 \
--steps="$STEPS" \
--repeat="$REPEAT" \
--header=./LICENSE_HEADER \
$TEMPLATE \
$OUTPUT

}

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
bench '*' '*' "${CHECK}" "weights/"
elif [[ $# -ne 2 ]]; then
choose_and_bench "${CHECK}"
else
bench "${2}" "${3}" "${CHECK}"
fi
fi

0 comments on commit 1c1ee63

Please sign in to comment.