Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Create Script to Run All Benchmarks #11493

Merged
merged 18 commits into from
May 23, 2022
55 changes: 55 additions & 0 deletions scripts/run_all_benchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
ggwpez marked this conversation as resolved.
Show resolved Hide resolved

set -e

# Runs all benchmarks for all pallets, for the Substrate node.
# Should be run on a reference machine to gain accurate benchmarks
# current reference machine: https://github.com/paritytech/substrate/pull/5848

echo "[+] Running all benchmarks for Substrate"

if [ $1 != "skip-build" ]
then
cargo +nightly build --profile production --locked --features=runtime-benchmarks
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
fi

./target/production/substrate benchmark pallet \
--chain=dev \
--list |\
tail -n+2 |\
cut -d',' -f1 |\
uniq > "substrate_pallets"
ggwpez marked this conversation as resolved.
Show resolved Hide resolved

# For each pallet found in the previous command, run benches on each function
while read -r line; do
pallet="$(echo "$line" | cut -d' ' -f1)";
folder_name="$(echo "${pallet#*_}" | tr '_' '-')";
echo "Pallet: $pallet, Folder Name: $folder_name";
# '!' has the side effect of bypassing errexit / set -e
! ./target/production/substrate benchmark pallet \
--chain=dev \
--steps=50 \
--repeat=20 \
--pallet="$pallet" \
--extrinsic="*" \
--execution=wasm \
--wasm-execution=compiled \
--template=./.maintain/frame-weight-template.hbs \
--output="./frame/${folder_name}/src/weights.rs"
done < "substrate_pallets"
rm "substrate_pallets"

# Benchmark base weights
! ./target/production/substrate benchmark overhead \
--chain=dev \
--execution=wasm \
--wasm-execution=compiled \
--weight-path="./frame/support/src/weights/" \
--warmup=10 \
--repeat=100


# This true makes sure that $? is 0 instead of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default exit code should be 0 when nothing failed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to fail if something goes wrong.

Copy link
Member Author

@shawntabrizi shawntabrizi May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want the whole process to fail if something goes wrong (if this is what you did). Want to try and do things best effort.

Copy link
Member

@ggwpez ggwpez May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But otherwise we will have unnoticed failures. In which case would it be an advantage to ignore an error here?
PS: We could also aggregate the errors in a variable and still run everything optimistically. This way we would not immediately fail but still see if something failed in the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be best. some kind of error output file, but it is annoying for the process to quit in the middle of running all benchmarks.

Imagine you start the script and leave it running over night, expecting everything to be done, and instead it stops on the 3rd pallet. You could at least get all the other pallets benchmarked, and come back to fix the broken pallet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It writes the error into a file now, and returns with exit code 1 in the end, if there an error.

# carrying over a failure which would otherwise cause
# the whole CI job to abort.
true