Skip to content

Commit 8e63d79

Browse files
committed
1 parent e8288a7 commit 8e63d79

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Track Benchmarks
2+
3+
on:
4+
workflow_run:
5+
workflows: [Run and Cache Benchmarks]
6+
types:
7+
- completed
8+
9+
jobs:
10+
track_with_bencher:
11+
if: github.event.workflow_run.conclusion == 'success'
12+
runs-on: ubuntu-22.04
13+
env:
14+
BENCHER_PROJECT: h264-reader
15+
BENCHER_ADAPTER: rust_iai_callgrind
16+
BENCHER_TESTBED: ubuntu-22.04
17+
BENCHMARK_RESULTS: benchmark_results.txt
18+
PR_EVENT: event.json
19+
steps:
20+
- name: Download Benchmark Results
21+
uses: actions/github-script@v6
22+
with:
23+
script: |
24+
async function downloadArtifact(artifactName) {
25+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
run_id: context.payload.workflow_run.id,
29+
});
30+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
31+
return artifact.name == artifactName
32+
})[0];
33+
if (!matchArtifact) {
34+
core.setFailed(`Failed to find artifact: ${artifactName}`);
35+
}
36+
let download = await github.rest.actions.downloadArtifact({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
artifact_id: matchArtifact.id,
40+
archive_format: 'zip',
41+
});
42+
let fs = require('fs');
43+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
44+
}
45+
await downloadArtifact(process.env.BENCHMARK_RESULTS);
46+
await downloadArtifact(process.env.PR_EVENT);
47+
- name: Unzip Benchmark Results
48+
run: |
49+
unzip $BENCHMARK_RESULTS.zip
50+
unzip $PR_EVENT.zip
51+
- name: Export PR Event Data
52+
uses: actions/github-script@v6
53+
with:
54+
script: |
55+
let fs = require('fs');
56+
let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'}));
57+
core.exportVariable("PR_HEAD", `${prEvent.number}/merge`);
58+
core.exportVariable("PR_BASE", prEvent.pull_request.base.ref);
59+
core.exportVariable("PR_DEFAULT", prEvent.pull_request.base.repo.default_branch);
60+
core.exportVariable("PR_NUMBER", prEvent.number);
61+
- uses: bencherdev/bencher@main
62+
- name: Track Benchmarks with Bencher
63+
run: |
64+
bencher run \
65+
--if-branch '${{ env.PR_HEAD }}' \
66+
--else-if-branch '${{ env.PR_BASE }}' \
67+
--else-if-branch '${{ env.PR_DEFAULT }}' \
68+
--ci-number '${{ env.PR_NUMBER }}' \
69+
--github-actions "${{ secrets.GITHUB_TOKEN }}" \
70+
--token "${{ secrets.BENCHER_API_TOKEN }}" \
71+
--err \
72+
--file "$BENCHMARK_RESULTS"

.github/workflows/pr-benchmark.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run and Cache Benchmarks
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
benchmark:
9+
name: Run Benchmarks
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: cargo-bins/cargo-binstall@main
14+
15+
- run: sudo apt-get install valgrind
16+
- run: cargo binstall --no-confirm [email protected]
17+
- run: |
18+
IAI_CALLGRIND_COLOR=never cargo bench --bench ci_bench > benchmark_results.txt
19+
- name: Upload Benchmark Results
20+
uses: actions/upload-artifact@v4
21+
with:
22+
name: benchmark_results.txt
23+
path: ./benchmark_results.txt
24+
- name: Upload GitHub Pull Request Event
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: event.json
28+
path: ${{ github.event_path }}

benches/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ There are two benchmarks here,
1616
- run using `cargo bench --bench ci_bench`
1717

1818
The latter benchmark is run from a github actions workflow on commits to the main branch and the benchmark results are
19-
uploaded to [bencher.dev](https://bencher.dev/perf/h264-reader).
19+
uploaded to [bencher.dev](https://bencher.dev/perf/h264-reader).
20+
21+
[![h264-reader - Bencher](https://api.bencher.dev/v0/projects/h264-reader/perf/img?branches=a53abf65-ea6e-482e-8c55-cf6726e77864&testbeds=19d2a260-47fc-44ec-b7f8-314d88408ce7&benchmarks=cc26ec97-55ef-43a5-860f-861ae847d8b3&measures=1dc590ca-477f-4477-8295-672b05d33086&start_time=1706605032000&end_time=1709197032000 "h264-reader")](https://bencher.dev/perf/h264-reader?key=true&reports_per_page=4&branches_per_page=8&testbeds_per_page=8&benchmarks_per_page=8&reports_page=1&branches_page=1&testbeds_page=1&benchmarks_page=1)

0 commit comments

Comments
 (0)