Skip to content

Commit

Permalink
Dump bench weights
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNacked committed May 24, 2024
1 parent dbc7f79 commit f954115
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 26 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,15 @@ jobs:
tar xzf wasm-opt-linux-x64.tar.gz && sudo mv binaryen-version_*/bin/* /usr/local/bin/
wasm-opt --version
- name: print cpu flags
run: |
echo "CPU cores: $(nproc)"
cat /proc/cpuinfo | grep flags | head -n 1
sleep 1
- name: Run all benchmarks
run: |
./scripts/benchmarking/run_all_benchmarks.sh -c vara-dev -m
cp ./scripts/benchmarking/weights-output/* runtime/vara/src/weights
# apply some patches for `pallets/gear/src/weights.rs`
cp runtime/vara/src/weights/pallet_gear.rs pallets/gear/src/weights.rs
sed -i -E 's/\w+::WeightInfo for SubstrateWeight/WeightInfo for SubstrateWeight/' pallets/gear/src/weights.rs
# apply some patches for `pallets/gear-builtin/src/weights.rs`
cp runtime/vara/src/weights/pallet_gear_builtin.rs pallets/gear-builtin/src/weights.rs
sed -i -E 's/\w+::WeightInfo for SubstrateWeight/WeightInfo for SubstrateWeight/' pallets/gear-builtin/src/weights.rs
# generate code for lightweight scheduler that is used in gtest and other crates
./scripts/weight-dump.sh
- name: "ACTIONS: Upload artifact with benchmarking errors (if exist)"
if: ${{ always() }}
Expand All @@ -157,8 +154,8 @@ jobs:
with:
name: weights-vara
path: |
runtime/vara/src/weights/
utils/wasm-instrument/src/gas_metering/
scripts/benchmarking/weights-output
- name: "TIP: download the artifacts and use `./scripts/unpack-weights.sh`"
run: |
Expand Down
12 changes: 12 additions & 0 deletions .maintain/dump_weights.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
{{#each benchmarks as |benchmark|}}
"{{benchmark.name}}": {
"base": {{benchmark.base_weight}},
{{#each benchmark.component_weight as |cw|}}
"cw_slope": {{cw.slope}}
{{~#unless @last}},{{/unless}}
{{/each}}
}
{{~#unless @last}},{{/unless}}
{{/each}}
}
62 changes: 47 additions & 15 deletions scripts/benchmarking/run_all_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Steps and repeats for main benchmark.
BENCHMARK_STEPS=50
BENCHMARK_REPEAT=20
BENCHMARK_REPEAT=5

# Steps and repeats for benchmarking so called "one-time extrinsics",
# which may be called only once and require a different benchmarking approach with more repeats.
Expand Down Expand Up @@ -83,13 +83,7 @@ EXCLUDED_PALLETS=(
)

# Load all pallet names in an array.
ALL_PALLETS=($(
$GEAR benchmark pallet --list --chain=$chain_spec |\
tail -n+2 |\
cut -d',' -f1 |\
sort |\
uniq
))
ALL_PALLETS=(pallet_gear_builtin)

# Filter out the excluded pallets by concatenating the arrays and discarding duplicates.
PALLETS=($({ printf '%s\n' "${ALL_PALLETS[@]}" "${EXCLUDED_PALLETS[@]}"; } | sort | uniq -u))
Expand Down Expand Up @@ -151,19 +145,57 @@ for PALLET in "${PALLETS[@]}"; do
EXTRINSICS=("*")
fi

WEIGHT_FILE="./${WEIGHTS_OUTPUT}/${PALLET}.rs"
WEIGHT_FILE="./${WEIGHTS_OUTPUT}/${PALLET}.json"
echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE";

OUTPUT=$(
$GEAR benchmark pallet \
taskset -c 8 $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS \
--repeat=$BENCHMARK_REPEAT \
--pallet="$PALLET" \
--extrinsic="$(IFS=, ; echo "${EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="$WEIGHT_FILE" \
--template=.maintain/frame-weight-template.hbs 2>&1
--output="./${WEIGHTS_OUTPUT}/${PALLET}_1_cores.json" \
--template=.maintain/dump_weights.hbs 2>&1
)

if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
fi

echo "[+] Benchmarking $PALLET 3-8 with weight file $WEIGHT_FILE";

OUTPUT=$(
taskset -c 3-8 $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS \
--repeat=$BENCHMARK_REPEAT \
--pallet="$PALLET" \
--extrinsic="$(IFS=, ; echo "${EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="./${WEIGHTS_OUTPUT}/${PALLET}_6_cores.json" \
--template=.maintain/dump_weights.hbs 2>&1
)

if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
fi

echo "[+] Benchmarking $PALLET 3-10 with weight file $WEIGHT_FILE";

OUTPUT=$(
taskset -c 3-10 $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS \
--repeat=$BENCHMARK_REPEAT \
--pallet="$PALLET" \
--extrinsic="$(IFS=, ; echo "${EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="./${WEIGHTS_OUTPUT}/${PALLET}_8_cores.json" \
--template=.maintain/dump_weights.hbs 2>&1
)

if [ $? -ne 0 ]; then
Expand All @@ -183,8 +215,8 @@ for PALLET in "${PALLETS[@]}"; do
--pallet="$PALLET" \
--extrinsic="$(IFS=', '; echo "${ONE_TIME_EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="./${WEIGHTS_OUTPUT}/${PALLET}_onetime.rs" \
--template=.maintain/frame-weight-template.hbs 2>&1
--output="./${WEIGHTS_OUTPUT}/${PALLET}_onetime.json" \
--template=.maintain/dump_weights.hbs 2>&1
)

if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -224,7 +256,7 @@ else
fi

# Merge pallet_gear weights.
./scripts/benchmarking/merge_outputs.sh
#./scripts/benchmarking/merge_outputs.sh

# Check if the error file exists.
if [ -f "$ERR_FILE" ]; then
Expand Down

0 comments on commit f954115

Please sign in to comment.