about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-07-16 12:33:39 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-07-16 12:33:39 +0000
commit448b7a3a12e6e76547c95cd327d83b2c7dff3c65 (patch)
tree02f0085054581806786556e5ea7e5dcebb6ba58a
parentfae8935e3d3e8dec227f51c9ef3621747bb684c7 (diff)
downloadrust-448b7a3a12e6e76547c95cd327d83b2c7dff3c65.tar.gz
rust-448b7a3a12e6e76547c95cd327d83b2c7dff3c65.zip
Record GHA step summaries for benchmarking
-rw-r--r--build_system/bench.rs25
-rw-r--r--build_system/utils.rs3
2 files changed, 28 insertions, 0 deletions
diff --git a/build_system/bench.rs b/build_system/bench.rs
index 2bb11800034..a32b682b9aa 100644
--- a/build_system/bench.rs
+++ b/build_system/bench.rs
@@ -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();
+    }
 }
diff --git a/build_system/utils.rs b/build_system/utils.rs
index 0b6f344453b..c79e801d8ae 100644
--- a/build_system/utils.rs
+++ b/build_system/utils.rs
@@ -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());
     }