Skip to content

Commit

Permalink
ci: add new functions to benchmark workflow (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on authored Sep 20, 2023
1 parent 6327b80 commit 607c4f4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ name: Benchmarks
on:
workflow_dispatch:
inputs:
create_pr:
description: Whether to create a pull request after the benchmarks are completed
required: false
type: boolean
change-type:
description: How should changes be made after the benchmarks are completed?
required: true
default: ignore
type: choice
options:
- ignore
- commit
- pull_request

env:
CARGO_TERM_COLOR: always
Expand All @@ -15,6 +20,9 @@ env:
jobs:
benchmarks:
runs-on: bench
permissions:
contents: write
pull-requests: write
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
Expand Down Expand Up @@ -65,11 +73,18 @@ jobs:
run: |
echo "::notice::You can download the artifacts and use script \`./scripts/unpack-weights.sh\` to apply the changes to your branch"
- name: Create Pull Request
if: ${{ inputs.create_pr }}
- name: Create commit
if: ${{ inputs.change-type == 'commit' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: >-
chore(runtime): update weights
file_pattern: "pallets/gear/src/ runtime/gear/src/weights/ runtime/vara/src/weights/"

- name: Create pull Request
if: ${{ inputs.change-type == 'pull_request' }}
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GH_TOKEN_FOR_PR }}
add-paths: |
pallets/gear/src/
runtime/gear/src/weights/
Expand All @@ -78,7 +93,7 @@ jobs:
branch: weights/patch
branch-suffix: short-commit-hash
title: >-
chore: update weights
chore(runtime): update weights
body: |
`run_all_benchmarks.sh` script is applied to update weights (branch: `${{ github.ref_name }}`, commit ${{ github.sha }})
**Note:** If CI fails, try manually updating the heuristic tests: `runtime/{gear, vara}/src/tests.rs`
46 changes: 46 additions & 0 deletions .github/workflows/comparison-table.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Comparison table

on:
workflow_dispatch:
inputs:
runtime:
description: For which runtime generate comparison table?
required: true
type: choice
options:
- gear
- vara

env:
CARGO_TERM_COLOR: always
TERM: xterm-256color

jobs:
comparison-table:
runs-on: [kuberunner]
env:
RUSTUP_HOME: /tmp/rustup_home
steps:
- name: "ACTIONS: Checkout & fetch all history"
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Install: Set cargo path"
run: echo "/tmp/cargo/bin" >> $GITHUB_PATH

- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: "Build: Init"
run: ./scripts/gear.sh init cargo

- name: "Generate comparison tables (${{ inputs.runtime }})"
run: |
./scripts/weight-diff.sh master $(git branch --show-current) ${{ inputs.runtime }} --display-units > ${{ inputs.runtime }}-tables.txt
- name: "ACTIONS: Upload artifact with comparison tables (${{ inputs.runtime }})"
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.runtime }}-tables
path: ${{ inputs.runtime }}-tables.txt
2 changes: 1 addition & 1 deletion .github/workflows/time-consuming-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: "Install: Rust toolchain"
uses: dsherret/rust-toolchain-file@v1

- name: "Buid: Init"
- name: "Build: Init"
run: ./scripts/gear.sh init cargo

- name: "Build: Node"
Expand Down
17 changes: 11 additions & 6 deletions scripts/weight-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@ flag=$4
dump_path="weight-dumps"
mkdir -p "$dump_path"

set -x
if [ -z $CI ] ; then
set -x
CARGO_FLAGS=""
else
CARGO_FLAGS="--quiet"
fi

git checkout "$branch1"
dump_path1="$dump_path/${branch1//\//-}.json"
cargo run --package gear-weight-diff --release -- dump "$dump_path1" --label "$branch1"
cargo run $CARGO_FLAGS --package gear-weight-diff --release -- dump "$dump_path1" --label "$branch1"

git checkout "$branch2"
dump_path2="$dump_path/${branch2//\//-}.json"
cargo run --package gear-weight-diff --release -- dump "$dump_path2" --label "$branch2"
cargo run $CARGO_FLAGS --package gear-weight-diff --release -- dump "$dump_path2" --label "$branch2"

git checkout "$current_branch"

cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag
cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag
cargo run --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag
cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "instruction" $flag
cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "host-fn" $flag
cargo run $CARGO_FLAGS --package gear-weight-diff --release -- diff "$dump_path1" "$dump_path2" "$runtime" "memory" $flag
6 changes: 3 additions & 3 deletions utils/weight-diff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ enum Commands {
},
}

#[derive(Debug, Clone, ValueEnum)]
#[derive(Debug, Copy, Clone, ValueEnum)]
enum Runtime {
Gear,
Vara,
}

#[derive(Debug, Clone, ValueEnum)]
#[derive(Debug, Copy, Clone, ValueEnum)]
enum WeightsKind {
Instruction,
HostFn,
Expand Down Expand Up @@ -247,7 +247,7 @@ fn main() {
}
}

println!("Comparison table for {runtime:?} runtime");
println!("Comparison table for {runtime:?} runtime for {kind:?}");
println!();

let mut builder = Builder::default();
Expand Down

0 comments on commit 607c4f4

Please sign in to comment.