Skip to content

Commit 7b53ac7

Browse files
committed
Record bootstrap step durations into GitHub summary in citool
1 parent ead58ea commit 7b53ac7

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/build_helper/src/metrics.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,14 @@ pub fn format_build_steps(root: &BuildStep) -> String {
175175

176176
let mut output = String::new();
177177
for (level, step) in substeps {
178-
let label = format!("{}{}", ".".repeat(level as usize), step.r#type);
179-
writeln!(output, "{label:<65}{:>8.2}s", step.duration.as_secs_f64()).unwrap();
178+
let label = format!(
179+
"{}{}",
180+
".".repeat(level as usize),
181+
// Bootstrap steps can be generic and thus contain angle brackets (<...>).
182+
// However, Markdown interprets these as HTML, so we need to escap ethem.
183+
step.r#type.replace('<', "&lt;").replace('>', "&gt;")
184+
);
185+
writeln!(output, "{label:.<65}{:>8.2}s", step.duration.as_secs_f64()).unwrap();
180186
}
181187
output
182188
}

src/ci/citool/src/metrics.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::io::Write;
44
use std::path::Path;
55

66
use anyhow::Context;
7-
use build_helper::metrics::{JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata};
7+
use build_helper::metrics::{
8+
BuildStep, JsonNode, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, format_build_steps,
9+
};
810

911
pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow::Result<()> {
1012
let metrics = load_metrics(metrics_path)?;
@@ -15,7 +17,31 @@ pub fn postprocess_metrics(metrics_path: &Path, summary_path: &Path) -> anyhow::
1517
.open(summary_path)
1618
.with_context(|| format!("Cannot open summary file at {summary_path:?}"))?;
1719

18-
record_test_suites(&metrics, &mut file)?;
20+
if !metrics.invocations.is_empty() {
21+
writeln!(file, "# Bootstrap steps")?;
22+
record_bootstrap_step_durations(&metrics, &mut file)?;
23+
record_test_suites(&metrics, &mut file)?;
24+
}
25+
26+
Ok(())
27+
}
28+
29+
fn record_bootstrap_step_durations(metrics: &JsonRoot, file: &mut File) -> anyhow::Result<()> {
30+
for invocation in &metrics.invocations {
31+
let step = BuildStep::from_invocation(invocation);
32+
let table = format_build_steps(&step);
33+
eprintln!("Step `{}`\n{table}\n", invocation.cmdline);
34+
writeln!(
35+
file,
36+
r"<details>
37+
<summary>{}</summary>
38+
<pre><code>{table}</code></pre>
39+
</details>
40+
",
41+
invocation.cmdline
42+
)?;
43+
}
44+
eprintln!("Recorded {} bootstrap invocation(s)", metrics.invocations.len());
1945

2046
Ok(())
2147
}

0 commit comments

Comments
 (0)