Record GHA step summaries for benchmarking

This commit is contained in:
bjorn3 2023-07-16 12:33:39 +00:00
parent fae8935e3d
commit 448b7a3a12
2 changed files with 28 additions and 0 deletions

View File

@ -1,4 +1,5 @@
use std::env;
use std::io::Write;
use std::path::Path;
use super::path::{Dirs, RelPath};
@ -30,6 +31,12 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
let bench_runs = env::var("BENCH_RUNS").unwrap_or_else(|_| "10".to_string()).parse().unwrap();
let mut gha_step_summary = if let Ok(file) = std::env::var("GITHUB_STEP_SUMMARY") {
Some(std::fs::OpenOptions::new().append(true).open(file).unwrap())
} else {
None
};
eprintln!("[BENCH COMPILE] ebobby/simple-raytracer");
let cargo_clif = RelPath::DIST
.to_path(dirs)
@ -60,17 +67,28 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
target_dir = target_dir.display(),
);
let bench_compile_markdown = RelPath::DIST.to_path(dirs).join("bench_compile.md");
let bench_compile = hyperfine_command(
1,
bench_runs,
Some(&clean_cmd),
&[&llvm_build_cmd, &clif_build_cmd, &clif_build_opt_cmd],
&bench_compile_markdown,
);
spawn_and_wait(bench_compile);
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
gha_step_summary.write_all(b"# Compilation\n\n").unwrap();
gha_step_summary.write_all(&std::fs::read(bench_compile_markdown).unwrap()).unwrap();
gha_step_summary.write_all(b"\n").unwrap();
}
eprintln!("[BENCH RUN] ebobby/simple-raytracer");
let bench_run_markdown = RelPath::DIST.to_path(dirs).join("bench_run.md");
let mut bench_run = hyperfine_command(
0,
bench_runs,
@ -89,7 +107,14 @@ fn benchmark_simple_raytracer(dirs: &Dirs, bootstrap_host_compiler: &Compiler) {
.to_str()
.unwrap(),
],
&bench_run_markdown,
);
bench_run.current_dir(RelPath::BUILD.to_path(dirs));
spawn_and_wait(bench_run);
if let Some(gha_step_summary) = gha_step_summary.as_mut() {
gha_step_summary.write_all(b"# Execution\n\n").unwrap();
gha_step_summary.write_all(&std::fs::read(bench_run_markdown).unwrap()).unwrap();
gha_step_summary.write_all(b"\n").unwrap();
}
}

View File

@ -138,9 +138,12 @@ pub(crate) fn hyperfine_command(
runs: u64,
prepare: Option<&str>,
cmds: &[&str],
markdown_export: &Path,
) -> Command {
let mut bench = Command::new("hyperfine");
bench.arg("--export-markdown").arg(markdown_export);
if warmup != 0 {
bench.arg("--warmup").arg(warmup.to_string());
}