Skip to content

Commit 0e2cbbc

Browse files
committed
added command bench-all
1 parent a6f3394 commit 0e2cbbc

4 files changed

Lines changed: 210 additions & 0 deletions

File tree

.github/commands-readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The current available command actions are:
1212
- [Command Update UI](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-update-ui.yml)
1313
- [Command Sync](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-sync.yml)
1414
- [Command Bench](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench.yml)
15+
- [Command Bench All](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-all.yml)
1516

1617
**WIP**: Need more actions.
1718

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Command Bench All
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr:
7+
description: Number of the Pull Request
8+
required: true
9+
benchmark:
10+
description: Pallet benchmark
11+
type: choice
12+
required: true
13+
options:
14+
- pallet
15+
- substrate
16+
- polkadot
17+
- cumulus
18+
pallet:
19+
description: Pallet
20+
required: false
21+
type: string
22+
default: pallet_name
23+
target_dir:
24+
description: Target directory
25+
type: choice
26+
options:
27+
- substrate
28+
- polkadot
29+
- cumulus
30+
runtime:
31+
description: Runtime
32+
type: choice
33+
options:
34+
- rococo
35+
- westend
36+
- asset-hub-kusama
37+
- asset-hub-polkadot
38+
- asset-hub-rococo
39+
- asset-hub-westend
40+
- bridge-hub-kusama
41+
- bridge-hub-polkadot
42+
- bridge-hub-rococo
43+
- bridge-hub-westend
44+
- collectives-polkadot
45+
- collectives-westend
46+
- coretime-rococo
47+
- coretime-westend
48+
- contracts-rococo
49+
- glutton-kusama
50+
- glutton-westend
51+
- people-rococo
52+
- people-westend
53+
54+
55+
jobs:
56+
set-image:
57+
runs-on: ubuntu-latest
58+
outputs:
59+
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
- id: set_image
64+
run: cat .github/env >> $GITHUB_OUTPUT
65+
cmd-bench-all:
66+
needs: [set-image]
67+
runs-on: ubuntu-latest
68+
container:
69+
image: ${{ needs.set-image.outputs.IMAGE }}
70+
steps:
71+
- name: Download repo
72+
uses: actions/checkout@v4
73+
- name: Install gh cli
74+
id: gh
75+
uses: ./.github/actions/set-up-gh
76+
with:
77+
pr-number: ${{ inputs.pr }}
78+
GH_TOKEN: ${{ github.token }}
79+
- name: Run bench
80+
run: |
81+
"./scripts/bench-all.sh" "${{ inputs.benchmark }}" --runtime "${{ inputs.runtime }}" --pallet "${{ inputs.pallet }}" --target_dir "${{ inputs.target_dir }}"
82+
- name: Report failure
83+
if: ${{ failure() }}
84+
run: gh pr comment ${{ inputs.pr }} --body "<h2>Command failed ❌</h2> Run by @${{ github.actor }} for <code>${{ github.workflow }}</code> failed. See logs <a href=\"$RUN\">here</a>."
85+
env:
86+
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
87+
GH_TOKEN: ${{ github.token }}
88+
- run: git pull --rebase
89+
- uses: stefanzweifel/git-auto-commit-action@v5
90+
with:
91+
commit_message: cmd-action - ${{ github.workflow }}
92+
branch: ${{ steps.gh.outputs.branch }}
93+
- name: Report succeed
94+
run: gh pr comment ${{ inputs.pr }} --body "<h2>Action completed 🎉🎉</h2> Run by @${{ github.actor }} for <code>${{ github.workflow }}</code> completed 🎉. See logs <a href=\"$RUN\">here</a>."
95+
env:
96+
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
97+
GH_TOKEN: ${{ github.token }}

scripts/bench-all.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
shopt -s inherit_errexit
5+
shopt -s globstar
6+
7+
. "$(realpath "$(dirname "${BASH_SOURCE[0]}")/command-utils.sh")"
8+
9+
get_arg optional --pallet "$@"
10+
PALLET="${out:-""}"
11+
12+
if [[ ! -z "$PALLET" ]]; then
13+
. "$(dirname "${BASH_SOURCE[0]}")/lib/bench-all-pallet.sh" "$@"
14+
else
15+
. "$(dirname "${BASH_SOURCE[0]}")/bench.sh" --subcommand=all "$@"
16+
fi

scripts/lib/bench-all-pallet.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
shopt -s inherit_errexit
5+
shopt -s globstar
6+
7+
. "$(dirname "${BASH_SOURCE[0]}")/../command-utils.sh"
8+
9+
get_arg required --pallet "$@"
10+
PALLET="${out:-""}"
11+
12+
REPO_NAME="$(basename "$PWD")"
13+
BASE_COMMAND="$(dirname "${BASH_SOURCE[0]}")/../../bench/bench.sh --noexit=true --subcommand=pallet"
14+
15+
WEIGHT_FILE_PATHS=( $(find . -type f -name "${PALLET}.rs" -path "**/weights/*" | sed 's|^\./||g') )
16+
17+
# convert pallet_ranked_collective to ranked-collective
18+
CLEAN_PALLET=$(echo $PALLET | sed 's/pallet_//g' | sed 's/_/-/g')
19+
20+
# add substrate pallet weights to a list
21+
SUBSTRATE_PALLET_PATH=$(ls substrate/frame/$CLEAN_PALLET/src/weights.rs || :)
22+
if [ ! -z "${SUBSTRATE_PALLET_PATH}" ]; then
23+
WEIGHT_FILE_PATHS+=("$SUBSTRATE_PALLET_PATH")
24+
fi
25+
26+
# add trappist pallet weights to a list
27+
TRAPPIST_PALLET_PATH=$(ls pallet/$CLEAN_PALLET/src/weights.rs || :)
28+
if [ ! -z "${TRAPPIST_PALLET_PATH}" ]; then
29+
WEIGHT_FILE_PATHS+=("$TRAPPIST_PALLET_PATH")
30+
fi
31+
32+
COMMANDS=()
33+
34+
if [ "${#WEIGHT_FILE_PATHS[@]}" -eq 0 ]; then
35+
echo "No weights files found for pallet: $PALLET"
36+
exit 1
37+
else
38+
echo "Found weights files for pallet: $PALLET"
39+
fi
40+
41+
for f in ${WEIGHT_FILE_PATHS[@]}; do
42+
echo "- $f"
43+
# f examples:
44+
# cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs
45+
# polkadot/runtime/rococo/src/weights/pallet_balances.rs
46+
# runtime/trappist/src/weights/pallet_assets.rs
47+
TARGET_DIR=$(echo $f | cut -d'/' -f 1)
48+
49+
if [ "$REPO_NAME" == "polkadot-sdk" ]; then
50+
case $TARGET_DIR in
51+
cumulus)
52+
TYPE=$(echo $f | cut -d'/' -f 2)
53+
# Example: cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs
54+
if [ "$TYPE" == "parachains" ]; then
55+
RUNTIME=$(echo $f | cut -d'/' -f 5)
56+
RUNTIME_DIR=$(echo $f | cut -d'/' -f 4)
57+
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --runtime_dir=$RUNTIME_DIR --target_dir=$TARGET_DIR --pallet=$PALLET")
58+
fi
59+
;;
60+
polkadot)
61+
# Example: polkadot/runtime/rococo/src/weights/pallet_balances.rs
62+
RUNTIME=$(echo $f | cut -d'/' -f 3)
63+
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --target_dir=$TARGET_DIR --pallet=$PALLET")
64+
;;
65+
substrate)
66+
# Example: substrate/frame/contracts/src/weights.rs
67+
COMMANDS+=("$BASE_COMMAND --target_dir=$TARGET_DIR --runtime=dev --pallet=$PALLET")
68+
;;
69+
*)
70+
echo "Unknown dir: $TARGET_DIR"
71+
exit 1
72+
;;
73+
esac
74+
fi
75+
76+
if [ "$REPO_NAME" == "trappist" ]; then
77+
case $TARGET_DIR in
78+
runtime)
79+
TYPE=$(echo $f | cut -d'/' -f 2)
80+
if [ "$TYPE" == "trappist" || "$TYPE" == "stout" ]; then
81+
# Example: runtime/trappist/src/weights/pallet_assets.rs
82+
COMMANDS+=("$BASE_COMMAND --target_dir=trappist --runtime=$TYPE --pallet=$PALLET")
83+
fi
84+
;;
85+
*)
86+
echo "Unknown dir: $TARGET_DIR"
87+
exit 1
88+
;;
89+
esac
90+
fi
91+
done
92+
93+
for cmd in "${COMMANDS[@]}"; do
94+
echo "Running command: $cmd"
95+
. $cmd
96+
done

0 commit comments

Comments
 (0)