Skip to content

Commit

Permalink
added command bench-all
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Jun 17, 2024
1 parent a6f3394 commit 0e2cbbc
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/commands-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The current available command actions are:
- [Command Update UI](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-update-ui.yml)
- [Command Sync](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-sync.yml)
- [Command Bench](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench.yml)
- [Command Bench All](https://github.com/paritytech/polkadot-sdk/actions/workflows/command-bench-all.yml)

**WIP**: Need more actions.

Expand Down
97 changes: 97 additions & 0 deletions .github/workflows/command-bench-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Command Bench All

on:
workflow_dispatch:
inputs:
pr:
description: Number of the Pull Request
required: true
benchmark:
description: Pallet benchmark
type: choice
required: true
options:
- pallet
- substrate
- polkadot
- cumulus
pallet:
description: Pallet
required: false
type: string
default: pallet_name
target_dir:
description: Target directory
type: choice
options:
- substrate
- polkadot
- cumulus
runtime:
description: Runtime
type: choice
options:
- rococo
- westend
- asset-hub-kusama
- asset-hub-polkadot
- asset-hub-rococo
- asset-hub-westend
- bridge-hub-kusama
- bridge-hub-polkadot
- bridge-hub-rococo
- bridge-hub-westend
- collectives-polkadot
- collectives-westend
- coretime-rococo
- coretime-westend
- contracts-rococo
- glutton-kusama
- glutton-westend
- people-rococo
- people-westend


jobs:
set-image:
runs-on: ubuntu-latest
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set_image
run: cat .github/env >> $GITHUB_OUTPUT
cmd-bench-all:
needs: [set-image]
runs-on: ubuntu-latest
container:
image: ${{ needs.set-image.outputs.IMAGE }}
steps:
- name: Download repo
uses: actions/checkout@v4
- name: Install gh cli
id: gh
uses: ./.github/actions/set-up-gh
with:
pr-number: ${{ inputs.pr }}
GH_TOKEN: ${{ github.token }}
- name: Run bench
run: |
"./scripts/bench-all.sh" "${{ inputs.benchmark }}" --runtime "${{ inputs.runtime }}" --pallet "${{ inputs.pallet }}" --target_dir "${{ inputs.target_dir }}"
- name: Report failure
if: ${{ failure() }}
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>."
env:
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
GH_TOKEN: ${{ github.token }}
- run: git pull --rebase
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: cmd-action - ${{ github.workflow }}
branch: ${{ steps.gh.outputs.branch }}
- name: Report succeed
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>."
env:
RUN: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
GH_TOKEN: ${{ github.token }}
16 changes: 16 additions & 0 deletions scripts/bench-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -eu -o pipefail
shopt -s inherit_errexit
shopt -s globstar

. "$(realpath "$(dirname "${BASH_SOURCE[0]}")/command-utils.sh")"

get_arg optional --pallet "$@"
PALLET="${out:-""}"

if [[ ! -z "$PALLET" ]]; then
. "$(dirname "${BASH_SOURCE[0]}")/lib/bench-all-pallet.sh" "$@"
else
. "$(dirname "${BASH_SOURCE[0]}")/bench.sh" --subcommand=all "$@"
fi
96 changes: 96 additions & 0 deletions scripts/lib/bench-all-pallet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash

set -eu -o pipefail
shopt -s inherit_errexit
shopt -s globstar

. "$(dirname "${BASH_SOURCE[0]}")/../command-utils.sh"

get_arg required --pallet "$@"
PALLET="${out:-""}"

REPO_NAME="$(basename "$PWD")"
BASE_COMMAND="$(dirname "${BASH_SOURCE[0]}")/../../bench/bench.sh --noexit=true --subcommand=pallet"

WEIGHT_FILE_PATHS=( $(find . -type f -name "${PALLET}.rs" -path "**/weights/*" | sed 's|^\./||g') )

# convert pallet_ranked_collective to ranked-collective
CLEAN_PALLET=$(echo $PALLET | sed 's/pallet_//g' | sed 's/_/-/g')

# add substrate pallet weights to a list
SUBSTRATE_PALLET_PATH=$(ls substrate/frame/$CLEAN_PALLET/src/weights.rs || :)
if [ ! -z "${SUBSTRATE_PALLET_PATH}" ]; then
WEIGHT_FILE_PATHS+=("$SUBSTRATE_PALLET_PATH")
fi

# add trappist pallet weights to a list
TRAPPIST_PALLET_PATH=$(ls pallet/$CLEAN_PALLET/src/weights.rs || :)
if [ ! -z "${TRAPPIST_PALLET_PATH}" ]; then
WEIGHT_FILE_PATHS+=("$TRAPPIST_PALLET_PATH")
fi

COMMANDS=()

if [ "${#WEIGHT_FILE_PATHS[@]}" -eq 0 ]; then
echo "No weights files found for pallet: $PALLET"
exit 1
else
echo "Found weights files for pallet: $PALLET"
fi

for f in ${WEIGHT_FILE_PATHS[@]}; do
echo "- $f"
# f examples:
# cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs
# polkadot/runtime/rococo/src/weights/pallet_balances.rs
# runtime/trappist/src/weights/pallet_assets.rs
TARGET_DIR=$(echo $f | cut -d'/' -f 1)

if [ "$REPO_NAME" == "polkadot-sdk" ]; then
case $TARGET_DIR in
cumulus)
TYPE=$(echo $f | cut -d'/' -f 2)
# Example: cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_balances.rs
if [ "$TYPE" == "parachains" ]; then
RUNTIME=$(echo $f | cut -d'/' -f 5)
RUNTIME_DIR=$(echo $f | cut -d'/' -f 4)
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --runtime_dir=$RUNTIME_DIR --target_dir=$TARGET_DIR --pallet=$PALLET")
fi
;;
polkadot)
# Example: polkadot/runtime/rococo/src/weights/pallet_balances.rs
RUNTIME=$(echo $f | cut -d'/' -f 3)
COMMANDS+=("$BASE_COMMAND --runtime=$RUNTIME --target_dir=$TARGET_DIR --pallet=$PALLET")
;;
substrate)
# Example: substrate/frame/contracts/src/weights.rs
COMMANDS+=("$BASE_COMMAND --target_dir=$TARGET_DIR --runtime=dev --pallet=$PALLET")
;;
*)
echo "Unknown dir: $TARGET_DIR"
exit 1
;;
esac
fi

if [ "$REPO_NAME" == "trappist" ]; then
case $TARGET_DIR in
runtime)
TYPE=$(echo $f | cut -d'/' -f 2)
if [ "$TYPE" == "trappist" || "$TYPE" == "stout" ]; then
# Example: runtime/trappist/src/weights/pallet_assets.rs
COMMANDS+=("$BASE_COMMAND --target_dir=trappist --runtime=$TYPE --pallet=$PALLET")
fi
;;
*)
echo "Unknown dir: $TARGET_DIR"
exit 1
;;
esac
fi
done

for cmd in "${COMMANDS[@]}"; do
echo "Running command: $cmd"
. $cmd
done

0 comments on commit 0e2cbbc

Please # to comment.