Skip to content

Commit d1b7f73

Browse files
committed
add CU benching to CI
1 parent 4104cad commit d1b7f73

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,38 @@ jobs:
109109
- name: Test Programs
110110
run: pnpm programs:test
111111

112+
bench_program_compute_units:
113+
name: Benchmark Program Compute Units
114+
runs-on: ubuntu-latest
115+
needs: build_programs # Cargo Bench won't build the SBPF binary...
116+
steps:
117+
- name: Git Checkout
118+
uses: actions/checkout@v4
119+
120+
- name: Setup Environment
121+
uses: ./.github/actions/setup
122+
with:
123+
cargo-cache-key: cargo-program-benches
124+
cargo-cache-fallback-key: cargo-programs
125+
solana: true
126+
127+
- name: Restore Program Builds
128+
uses: actions/cache/restore@v4
129+
with:
130+
path: ./**/*.so
131+
key: ${{ runner.os }}-builds-${{ github.sha }}
132+
133+
- name: Benchmark Compute Units
134+
run: pnpm programs:bench
135+
136+
- name: Check Working Directory
137+
run: |
138+
if [ -n "$(git status --porcelain)" ]; then
139+
test -z "$(git status --porcelain)"
140+
echo "CU usage has changed. Please run `cargo bench` and commit the new results.";
141+
exit 1;
142+
fi
143+
112144
## SKIP: IDL is hand-cranked here for now.
113145
##
114146
# generate_idls:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"scripts": {
44
"programs:build": "zx ./scripts/program/build.mjs",
55
"programs:test": "zx ./scripts/program/test.mjs",
6+
"programs:bench": "zx ./scripts/program/bench.mjs",
67
"programs:clean": "zx ./scripts/program/clean.mjs",
78
"programs:format": "zx ./scripts/program/format.mjs",
89
"programs:lint": "zx ./scripts/program/lint.mjs",

scripts/program/bench.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env zx
2+
import 'zx/globals';
3+
import {
4+
cliArguments,
5+
getProgramFolders,
6+
workingDirectory,
7+
} from '../utils.mjs';
8+
9+
// Save external programs binaries to the output directory.
10+
import './dump.mjs';
11+
12+
// Configure additional arguments here, e.g.:
13+
// ['--arg1', '--arg2', ...cliArguments()]
14+
const benchArgs = [
15+
'--features',
16+
'bpf-entrypoint',
17+
...cliArguments(),
18+
];
19+
20+
const hasSolfmt = await which('solfmt', { nothrow: true });
21+
22+
// Test the programs.
23+
await Promise.all(
24+
getProgramFolders().map(async (folder) => {
25+
const manifestPath = path.join(workingDirectory, folder, 'Cargo.toml');
26+
27+
if (hasSolfmt) {
28+
await $`RUST_LOG=error cargo bench --manifest-path ${manifestPath} ${benchArgs} 2>&1 | solfmt`;
29+
} else {
30+
await $`RUST_LOG=error cargo bench --manifest-path ${manifestPath} ${benchArgs}`;
31+
}
32+
})
33+
);

scripts/program/build.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import './dump.mjs';
1111

1212
// Configure additional arguments here, e.g.:
1313
// ['--arg1', '--arg2', ...cliArguments()]
14-
const buildArgs = cliArguments();
14+
const buildArgs = [
15+
'--features',
16+
'bpf-entrypoint',
17+
...cliArguments(),
18+
];
1519

1620
// Build the programs.
1721
await Promise.all(

0 commit comments

Comments
 (0)