From 7b53ac7ee67fbd62cadd883c860a6df263b6a481 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Sun, 2 Mar 2025 18:23:11 +0100 Subject: Record bootstrap step durations into GitHub summary in citool --- src/build_helper/src/metrics.rs | 10 ++++++++-- src/ci/citool/src/metrics.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/build_helper/src/metrics.rs b/src/build_helper/src/metrics.rs index 4b585c15182..eb306550fc4 100644 --- a/src/build_helper/src/metrics.rs +++ b/src/build_helper/src/metrics.rs @@ -175,8 +175,14 @@ pub fn format_build_steps(root: &BuildStep) -> String { let mut output = String::new(); for (level, step) in substeps { - let label = format!("{}{}", ".".repeat(level as usize), step.r#type); - writeln!(output, "{label:<65}{:>8.2}s", step.duration.as_secs_f64()).unwrap(); + let label = format!( + "{}{}", + ".".repeat(level as usize), + // Bootstrap steps can be generic and thus contain angle brackets (<...>). + // However, Markdown interprets these as HTML, so we need to escap ethem. + step.r#type.replace('<', "<").replace('>', ">") + ); + writeln!(output, "{label:.<65}{:>8.2}s", step.duration.as_secs_f64()).unwrap(); } output } diff --git a/src/ci/citool/src/metrics.rs b/src/ci/citool/src/metrics.rs index 9a1c7c4d910..2386413ed6b 100644 --- a/src/ci/citool/src/metrics.rs +++ b/src/ci/citool/src/metrics.rs @@ -4,7 +4,9 @@ use std::io::Write; use std::path::Path; use anyhow::Context; -use build_helper::metrics::{JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata}; +use build_helper::metrics::{ + BuildStep, JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, format_build_steps, +}; pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow::Result<()> { let metrics = load_metrics(metrics_path)?; @@ -15,7 +17,31 @@ pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow:: .open(summary_path) .with_context(|| format!("Cannot open summary file at {summary_path:?}"))?; - record_test_suites(&metrics, &mut file)?; + if !metrics.invocations.is_empty() { + writeln!(file, "# Bootstrap steps")?; + record_bootstrap_step_durations(&metrics, &mut file)?; + record_test_suites(&metrics, &mut file)?; + } + + Ok(()) +} + +fn record_bootstrap_step_durations(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> { + for invocation in &metrics.invocations { + let step = BuildStep::from_invocation(invocation); + let table = format_build_steps(&step); + eprintln!("Step `{}`\n{table}\n", invocation.cmdline); + writeln!( + file, + r"
+{} +
{table}
+
+", + invocation.cmdline + )?; + } + eprintln!("Recorded {} bootstrap invocation(s)", metrics.invocations.len()); Ok(()) } -- cgit 1.4.1-3-g733a5