Skip to content

Commit 448b7a3

Browse files
committed
Record GHA step summaries for benchmarking
1 parent fae8935 commit 448b7a3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

build_system/bench.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::io::Write;
23
use std::path::Path;
34

45
use super::path::{Dirs, RelPath};
@@ -30,6 +31,12 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
3031

3132
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
3233

34+
let mut gha_step_summary = if let Ok(file) = std::env::var("GITHUB_STEP_SUMMARY") {
35+
Some(std::fs::OpenOptions::new().append(true).open(file).unwrap())
36+
} else {
37+
None
38+
};
39+
3340
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
3441
let cargo_clif = RelPath::DIST
3542
.to_path(dirs)
@@ -60,17 +67,28 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
6067
target_dir = target_dir.display(),
6168
);
6269

70+
let bench_compile_markdown = RelPath::DIST.to_path(dirs).join("bench_compile.md");
71+
6372
let bench_compile = hyperfine_command(
6473
1,
6574
bench_runs,
6675
Some(&clean_cmd),
6776
&[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd],
77+
&bench_compile_markdown,
6878
);
6979

7080
spawn_and_wait(bench_compile);
7181

82+
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
83+
gha_step_summary.write_all(b"# Compilation\n\n").unwrap();
84+
gha_step_summary.write_all(&std::fs::read(bench_compile_markdown).unwrap()).unwrap();
85+
gha_step_summary.write_all(b"\n").unwrap();
86+
}
87+
7288
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
7389

90+
let bench_run_markdown = RelPath::DIST.to_path(dirs).join("bench_run.md");
91+
7492
let mut bench_run = hyperfine_command(
7593
0,
7694
bench_runs,
@@ -89,7 +107,14 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
89107
.to_str()
90108
.unwrap(),
91109
],
110+
&bench_run_markdown,
92111
);
93112
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
94113
spawn_and_wait(bench_run);
114+
115+
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
116+
gha_step_summary.write_all(b"# Execution\n\n").unwrap();
117+
gha_step_summary.write_all(&std::fs::read(bench_run_markdown).unwrap()).unwrap();
118+
gha_step_summary.write_all(b"\n").unwrap();
119+
}
95120
}

build_system/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ pub(crate) fn hyperfine_command(
138138
runs: u64,
139139
prepare: Option<&str>,
140140
cmds: &[&str],
141+
markdown_export: &Path,
141142
) -> Command {
142143
let mut bench = Command::new("hyperfine");
143144

145+
bench.arg("--export-markdown").arg(markdown_export);
146+
144147
if warmup != 0 {
145148
bench.arg("--warmup").arg(warmup.to_string());
146149
}

0 commit comments

Comments
 (0)