Skip to content

Commit

Permalink
add CU benching to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 22, 2024
1 parent 6de2d2e commit b03caf1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ jobs:
- name: Test Programs
run: pnpm programs:test

bench_program_compute_units:
name: Benchmark Program Compute Units
runs-on: ubuntu-latest
needs: build_programs # Cargo Bench won't build the SBPF binary...
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup
with:
cargo-cache-key: cargo-program-benches
cargo-cache-fallback-key: cargo-programs
solana: true

- name: Restore Program Builds
uses: actions/cache/restore@v4
with:
path: ./**/*.so
key: ${{ runner.os }}-builds-${{ github.sha }}

- name: Benchmark Compute Units
run: pnpm programs:bench

- name: Check Working Directory
run: |
if [ -n "$(git status --porcelain)" ]; then
test -z "$(git status --porcelain)"
echo "CU usage has changed. Please run `cargo bench` and commit the new results.";
exit 1;
fi
generate_idls:
name: Check IDL Generation
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"scripts": {
"programs:build": "zx ./scripts/program/build.mjs",
"programs:test": "zx ./scripts/program/test.mjs",
"programs:bench": "zx ./scripts/program/bench.mjs",
"programs:clean": "zx ./scripts/program/clean.mjs",
"programs:format": "zx ./scripts/program/format.mjs",
"programs:lint": "zx ./scripts/program/lint.mjs",
Expand Down
33 changes: 33 additions & 0 deletions scripts/program/bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env zx
import 'zx/globals';
import {
cliArguments,
getProgramFolders,
workingDirectory,
} from '../utils.mjs';

// Save external programs binaries to the output directory.
import './dump.mjs';

// Configure additional arguments here, e.g.:
// ['--arg1', '--arg2', ...cliArguments()]
const benchArgs = [
'--features',
'bpf-entrypoint',
...cliArguments(),
];

const hasSolfmt = await which('solfmt', { nothrow: true });

// Test the programs.
await Promise.all(
getProgramFolders().map(async (folder) => {
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');

if (hasSolfmt) {
await $`RUST_LOG=error cargo bench --manifest-path ${manifestPath} ${benchArgs} 2>&1 | solfmt`;
} else {
await $`RUST_LOG=error cargo bench --manifest-path ${manifestPath} ${benchArgs}`;
}
})
);

0 comments on commit b03caf1

Please sign in to comment.