Skip to content

Commit d5bc0a9

Browse files
committed
ci(bench): add benchmark tracking ci
Refs: #599
1 parent 84ce5a5 commit d5bc0a9

File tree

10 files changed

+163
-7
lines changed

10 files changed

+163
-7
lines changed

.cargo/config.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ linker = "rust-lld"
99

1010
[target.'cfg(target_env = "musl")']
1111
rustflags = ["-C", "target-feature=-crt-static"]
12-
13-
[profile.bench]
14-
debug = true
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
push:
3+
branches: main
4+
5+
jobs:
6+
run_benchmarks:
7+
name: Run PR Benchmarks
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Install Valgrind
12+
run: sudo apt update && sudo apt install -y valgrind
13+
- uses: taiki-e/install-action@cargo-binstall
14+
- name: Install gungraun-runner
15+
run: |
16+
version=$(cargo metadata --format-version=1 |\
17+
jq '.packages[] | select(.name == "gungraun").version' |\
18+
tr -d '"'
19+
)
20+
cargo binstall --no-confirm gungraun-runner --version $version
21+
- name: Run Benchmarks
22+
run: cd ./benches && cargo bench -- --output-format json | jq -s > benchmark_results.json
23+
- name: Track Benchmarks with Bencher
24+
run: |
25+
bencher run \
26+
--host 'https://bencher.php.rs/api' \
27+
--project ext-php-rs \
28+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
29+
--branch master \
30+
--testbed ubuntu-latest \
31+
--err \
32+
--adapter rust_gungraun \
33+
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
34+
--file "./benches/benchmark_results.json"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
pull_request_target:
3+
types: [closed]
4+
5+
jobs:
6+
archive_fork_pr_branch:
7+
name: Archive closed PR branch with Bencher
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: bencherdev/bencher@main
12+
- name: Archive closed fork PR branch with Bencher
13+
run: |
14+
bencher archive \
15+
--host 'https://bencher.php.rs/api' \
16+
--project ext-php-rs \
17+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
18+
--branch "$GITHUB_HEAD_REF"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run Benchmarks
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, edited, synchronize]
6+
7+
jobs:
8+
run_benchmarks:
9+
name: Run PR Benchmarks
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Install Valgrind
14+
run: sudo apt update && sudo apt install -y valgrind
15+
- uses: taiki-e/install-action@cargo-binstall
16+
- name: Install gungraun-runner
17+
run: |
18+
version=$(cargo metadata --manifest-path ./benches/Cargo.toml --format-version=1 |\
19+
jq '.packages[] | select(.name == "gungraun").version' |\
20+
tr -d '"'
21+
)
22+
cargo binstall --no-confirm gungraun-runner --version $version
23+
- name: Run Benchmarks
24+
run: cargo bench --manifest-path ./benches/Cargo.toml -- --output-format json | jq -s > benchmark_results.json
25+
- name: Upload Benchmark Results
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: benchmark_results.json
29+
path: ./benchmark_results.json
30+
- name: Upload Pull Request Event
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: event.json
34+
path: ${{ github.event_path }}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Upload PR Benchmark Results
2+
3+
on:
4+
workflow_run:
5+
workflows: [Run Benchmarks]
6+
types: [completed]
7+
8+
jobs:
9+
upload_benchmarks:
10+
if: github.event.workflow_run.conclusion == 'success'
11+
permissions:
12+
pull-requests: write
13+
runs-on: ubuntu-latest
14+
env:
15+
BENCHMARK_RESULTS: benchmark_results.json
16+
PR_EVENT: event.json
17+
steps:
18+
- name: Download Benchmark Results
19+
uses: dawidd6/action-download-artifact@v6
20+
with:
21+
name: ${{ env.BENCHMARK_RESULTS }}
22+
run_id: ${{ github.event.workflow_run.id }}
23+
- name: Download PR Event
24+
uses: dawidd6/action-download-artifact@v6
25+
with:
26+
name: ${{ env.PR_EVENT }}
27+
run_id: ${{ github.event.workflow_run.id }}
28+
- name: Export PR Event Data
29+
uses: actions/github-script@v6
30+
with:
31+
script: |
32+
let fs = require('fs');
33+
let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'}));
34+
core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref);
35+
core.exportVariable("PR_HEAD_SHA", prEvent.pull_request.head.sha);
36+
core.exportVariable("PR_BASE", prEvent.pull_request.base.ref);
37+
core.exportVariable("PR_BASE_SHA", prEvent.pull_request.base.sha);
38+
core.exportVariable("PR_NUMBER", prEvent.number);
39+
- uses: bencherdev/bencher@main
40+
- name: Track Benchmarks with Bencher
41+
run: |
42+
bencher run \
43+
--host 'https://bencher.php.rs/api' \
44+
--project ext-php-rs \
45+
--token '${{ secrets.BENCHER_API_TOKEN }}' \
46+
--branch "$PR_HEAD" \
47+
--hash "$PR_HEAD_SHA" \
48+
--start-point "$PR_BASE" \
49+
--start-point-hash "$PR_BASE_SHA" \
50+
--start-point-clone-thresholds \
51+
--start-point-reset \
52+
--testbed ubuntu-latest \
53+
--err \
54+
--adapter rust_gungraun \
55+
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
56+
--ci-number "$PR_NUMBER" \
57+
--file "$BENCHMARK_RESULTS"

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ runtime = ["bindgen/runtime"]
5454
static = ["bindgen/static"]
5555

5656
[workspace]
57-
members = ["crates/macros", "crates/cli", "tests", "benches"]
57+
members = ["crates/macros", "crates/cli", "tests"]
58+
exclude = ["benches"]
5859

5960
[package.metadata.docs.rs]
6061
rustdoc-args = ["--cfg", "docs"]

benches/.cargo/config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[target.'cfg(not(target_os = "windows"))']
2+
rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]
3+
4+
[target.x86_64-pc-windows-msvc]
5+
linker = "rust-lld"
6+
7+
[target.i686-pc-windows-msvc]
8+
linker = "rust-lld"
9+
10+
[target.'cfg(target_env = "musl")']
11+
rustflags = ["-C", "target-feature=-crt-static"]
12+
13+
[profile.bench]
14+
debug = true

benches/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

benches/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static = ["ext-php-rs/static"]
1818

1919
[lib]
2020
crate-type = ["cdylib"]
21+
bench = false
2122

2223
[[bench]]
2324
name = "binary_bench"

benches/benches/binary_bench.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use std::{
44
};
55

66
use gungraun::{
7-
BinaryBenchmarkConfig, Callgrind, FlamegraphConfig, binary_benchmark, binary_benchmark_group,
8-
main,
7+
binary_benchmark, binary_benchmark_group, main, BinaryBenchmarkConfig, Callgrind,
8+
FlamegraphConfig,
99
};
1010

1111
static BUILD: Once = Once::new();
1212
static EXT_TARGET_DIR: LazyLock<String> = LazyLock::new(|| {
1313
let mut dir = std::env::current_dir().expect("Could not get cwd");
14-
dir.pop();
1514
dir.push("target");
1615
dir.push("release");
1716
dir.display().to_string()

0 commit comments

Comments
 (0)