-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(benchmark): create workflow for generating benchmark weights (#868)
- Loading branch information
Showing
6 changed files
with
175 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Generate benchmark weights | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
generate-benchmark-weights: | ||
runs-on: [self-hosted, tfchainrunner01] | ||
container: | ||
image: threefolddev/tfchain:4 | ||
env: | ||
DEBIAN_FRONTEND: noninteractive | ||
PATH: /root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin | ||
RUSTUP_HOME: /root/.rustup | ||
CARGO_HOME: /root/.cargo | ||
|
||
steps: | ||
- name: Fail if branch is main | ||
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/development' | ||
run: | | ||
echo "This workflow should not be triggered with workflow_dispatch on main branch" | ||
exit 1 | ||
- name: Checkout the repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Chown user | ||
run: | | ||
chown -R $USER:$USER $GITHUB_WORKSPACE | ||
- name: Cache build | ||
uses: actions/cache@v3 | ||
timeout-minutes: 6 | ||
continue-on-error: true | ||
with: | ||
path: | | ||
/root/.cargo/bin/ | ||
/root/.cargo/registry/index/ | ||
/root/.cargo/registry/cache/ | ||
/root/.cargo/git/db/ | ||
substrate-node/target/ | ||
key: ${{ runner.os }}-tfchain-build-cache-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-tfchain-build-cache | ||
|
||
- name: Build | ||
run: | | ||
cd substrate-node | ||
cargo build --profile=production --features runtime-benchmarks | ||
- name: Run benchmarking | ||
run: | | ||
cd substrate-node | ||
for weights_rs_file in ./pallets/*/src/weights.rs | ||
do | ||
rm $weights_rs_file | ||
pal_name=$(awk -F'pallets/|/src' '{print $2}' <<< $weights_rs_file) | ||
./target/production/tfchain benchmark pallet \ | ||
--chain=dev \ | ||
--wasm-execution=compiled \ | ||
--pallet="$pal_name" \ | ||
--extrinsic="*" \ | ||
--steps=50 \ | ||
--repeat=20 \ | ||
--heap-pages=409 \ | ||
--output ./pallets/"$pal_name"/src/weights.rs \ | ||
--template ./.maintain/frame-weight-template.hbs | ||
done | ||
- name: Commit & Push changes | ||
uses: actions-js/push@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
message: 'chore(pallets): update benchmark `weights.rs` files ${date}' | ||
branch: ${{ github.ref_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Check benchmark weights | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- development | ||
paths: | ||
- '**.rs' | ||
- 'substrate-node/pallets/**' | ||
|
||
jobs: | ||
check-benchmark-weights: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get all rust files that have changed in pallets | ||
id: pallets-changed-rust-files | ||
uses: tj-actions/changed-files@v42 | ||
with: | ||
files: | | ||
substrate-node/pallets/**/src/*.rs | ||
- name: Get all pallets with changes in src dir | ||
id: pallets-changed-src-dir | ||
uses: tj-actions/changed-files@v42 | ||
with: | ||
dir_names: "true" | ||
files: | | ||
substrate-node/pallets/**/src/*.rs | ||
- name: List all changed files | ||
env: | ||
ALL_CHANGED_FILES: ${{ steps.pallets-changed-rust-files.outputs.all_changed_files }} | ||
run: | | ||
for file in ${ALL_CHANGED_FILES}; do | ||
echo "$file file was changed" | ||
done | ||
- name: List all changed dir | ||
env: | ||
ALL_CHANGED_DIR: ${{ steps.pallets-changed-src-dir.outputs.all_changed_files }} | ||
run: | | ||
for dir in ${ALL_CHANGED_DIR}; do | ||
echo "$dir has changes" | ||
done | ||
- name: Run benchmarking | ||
env: | ||
ALL_CHANGED_PALLETS_SRC_DIR: ${{ steps.pallets-changed-src-dir.outputs.all_changed_files }} | ||
ALL_CHANGED_PALLETS_FILES: ${{ steps.pallets-changed-rust-files.outputs.all_changed_files }} | ||
run: | | ||
count=0 | ||
for pallet_src_dir in ${ALL_CHANGED_PALLETS_SRC_DIR}; do | ||
echo "pallet src dir: $pallet_src_dir" | ||
weights_file="$pallet_src_dir"/weights.rs | ||
echo "weights file: $weights_file" | ||
updated_weights=false | ||
for changed_file in ${ALL_CHANGED_PALLETS_FILES}; do | ||
if [ "$changed_file" = "$weights_file" ]; then | ||
updated_weights=true | ||
break | ||
fi | ||
done | ||
if [ "$updated_weights" = false ] ; then | ||
let "count=count+1" | ||
fi | ||
done | ||
if [ "$count" -gt 0 ]; then | ||
echo "Found changes on src rust file(s) for $count pallet(s) and respective weights.rs file(s) was not updated." | ||
echo "Make sure to generate these files again if pallet logic has changed by running generate_benchmark_weights workflow on branch." | ||
exit 1 | ||
else | ||
echo "Found changes on src rust file(s) and respective weights.rs file(s) was updated." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters