-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da13f21
commit 42f5aa1
Showing
4 changed files
with
166 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Rust Profiling with iai-callgrind | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
profile: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
|
||
- name: Install Valgrind | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y valgrind | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/registry | ||
~/.cargo/git | ||
target | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
|
||
- name: Install iai-callgrind | ||
run: | | ||
cargo install [email protected] | ||
cargo add --dev [email protected] | ||
- name: Checkout main branch | ||
run: | | ||
git fetch origin main:main | ||
git checkout main | ||
- name: Run baseline benchmarks | ||
run: | | ||
cargo bench --bench compile_demo_art --features=iai -- --save-baseline=main | ||
- name: Checkout PR branch | ||
run: | | ||
git checkout ${{ github.event.pull_request.head.sha }} | ||
- name: Run PR benchmarks | ||
run: | | ||
cargo bench --bench compile_demo_art --features=iai -- --baseline main > benchmark_results.txt | ||
- name: Parse benchmark results | ||
id: parse_results | ||
run: | | ||
COMMENT="## Performance Benchmark Results\n\n" | ||
while IFS= read -r line; do | ||
if [[ $line == *"Comparison with"* ]]; then | ||
COMMENT+="### $line\n" | ||
elif [[ $line == *"Instructions:"* || $line == *"L1 Hits:"* || $line == *"Estimated Cycles:"* ]]; then | ||
COMMENT+="$line\n" | ||
fi | ||
done < benchmark_results.txt | ||
echo "comment<<EOF" >> $GITHUB_OUTPUT | ||
echo -e "$COMMENT" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: Comment PR | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.name, | ||
body: ${{steps.parse_results.outputs.comment}} | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,55 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use graph_craft::{document::NodeNetwork, graphene_compiler::Compiler, proto::ProtoNetwork}; | ||
use std::path::PathBuf; | ||
|
||
pub fn compile_to_proto(c: &mut Criterion) { | ||
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern"); | ||
for path in artworks { | ||
let Ok(path) = path else { continue }; | ||
let content = std::fs::read(&path).expect("failed to read file"); | ||
let network = load_network(std::str::from_utf8(&content).unwrap()); | ||
let name = path.file_stem().unwrap().to_str().unwrap(); | ||
#[cfg(feature = "criterion")] | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput)); | ||
} | ||
} | ||
#[cfg(feature = "iai")] | ||
use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main}; | ||
|
||
fn load_network(document_string: &str) -> NodeNetwork { | ||
let document: serde_json::Value = serde_json::from_str(&document_string).expect("Failed to parse document"); | ||
let network = serde_json::from_value::<NodeNetwork>(document["network_interface"]["network"].clone()).expect("Failed to parse document"); | ||
network | ||
let document: serde_json::Value = serde_json::from_str(document_string).expect("Failed to parse document"); | ||
serde_json::from_value::<NodeNetwork>(document["network_interface"]["network"].clone()).expect("Failed to parse document") | ||
} | ||
|
||
fn compile(network: NodeNetwork) -> ProtoNetwork { | ||
let compiler = Compiler {}; | ||
compiler.compile_single(network).unwrap() | ||
} | ||
|
||
fn bench_compile(path: PathBuf) { | ||
let content = std::fs::read(&path).expect("failed to read file"); | ||
let network = load_network(std::str::from_utf8(&content).unwrap()); | ||
black_box(compile(black_box(network))); | ||
} | ||
|
||
#[cfg(feature = "criterion")] | ||
fn compile_to_proto(c: &mut Criterion) { | ||
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern"); | ||
for path in artworks { | ||
let Ok(path) = path else { continue }; | ||
let name = path.file_stem().unwrap().to_str().unwrap(); | ||
c.bench_function(name, |b| b.iter(|| bench_compile(path.clone()))); | ||
} | ||
} | ||
|
||
#[cfg_attr(feature = "iai", library_benchmark)] | ||
fn iai_compile_to_proto() { | ||
let artworks = glob::glob("../../demo-artwork/*.graphite").expect("failed to read glob pattern"); | ||
for path in artworks { | ||
let Ok(path) = path else { continue }; | ||
bench_compile(path); | ||
} | ||
} | ||
|
||
#[cfg(feature = "criterion")] | ||
criterion_group!(benches, compile_to_proto); | ||
|
||
#[cfg(feature = "criterion")] | ||
criterion_main!(benches); | ||
|
||
#[cfg(feature = "iai")] | ||
library_benchmark_group!(name = compile_group; benchmarks = iai_compile_to_proto); | ||
|
||
#[cfg(feature = "iai")] | ||
main!(library_benchmark_groups = compile_group); |