Skip to content

Commit c55d363

Browse files
committed
Auto merge of #7872 - ehuss:timings-error, r=Eh2406
Emit report on error with Ztimings. Previously the report was not saved on error. I'm not actually sure this is all that useful. I was using it to gather a picture of what was being built (I wasn't actually interested in the timing data). There might be better ways to accomplish what I wanted, but it's a small change, so probably doesn't hurt. Fixes #7413.
2 parents db0dac5 + 2061e86 commit c55d363

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Diff for: src/cargo/core/compiler/job_queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
676676
}
677677

678678
let time_elapsed = util::elapsed(cx.bcx.config.creation_time().elapsed());
679+
self.timings.finished(cx.bcx, &error)?;
679680

680681
if let Some(e) = error {
681682
Err(e)
@@ -687,7 +688,6 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
687688
if !cx.bcx.build_config.build_plan {
688689
cx.bcx.config.shell().status("Finished", message)?;
689690
}
690-
self.timings.finished(cx.bcx)?;
691691
Ok(())
692692
} else {
693693
debug!("queue: {:#?}", self.queue);

Diff for: src/cargo/core/compiler/timings.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,29 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
293293
}
294294

295295
/// Call this when all units are finished.
296-
pub fn finished(&mut self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
296+
pub fn finished(
297+
&mut self,
298+
bcx: &BuildContext<'_, '_>,
299+
error: &Option<anyhow::Error>,
300+
) -> CargoResult<()> {
297301
if !self.enabled {
298302
return Ok(());
299303
}
300304
self.mark_concurrency(0, 0, 0, 0);
301305
self.unit_times
302306
.sort_unstable_by(|a, b| a.start.partial_cmp(&b.start).unwrap());
303307
if self.report_html {
304-
self.report_html(bcx)?;
308+
self.report_html(bcx, error)?;
305309
}
306310
Ok(())
307311
}
308312

309313
/// Save HTML report to disk.
310-
fn report_html(&self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
314+
fn report_html(
315+
&self,
316+
bcx: &BuildContext<'_, '_>,
317+
error: &Option<anyhow::Error>,
318+
) -> CargoResult<()> {
311319
let duration = d_as_f64(self.start.elapsed());
312320
let timestamp = self.start_str.replace(&['-', ':'][..], "");
313321
let filename = format!("cargo-timing-{}.html", timestamp);
@@ -318,7 +326,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
318326
.map(|(name, _targets)| name.as_str())
319327
.collect();
320328
f.write_all(HTML_TMPL.replace("{ROOTS}", &roots.join(", ")).as_bytes())?;
321-
self.write_summary_table(&mut f, duration, bcx)?;
329+
self.write_summary_table(&mut f, duration, bcx, error)?;
322330
f.write_all(HTML_CANVAS.as_bytes())?;
323331
self.write_unit_table(&mut f)?;
324332
// It helps with pixel alignment to use whole numbers.
@@ -359,6 +367,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
359367
f: &mut impl Write,
360368
duration: f64,
361369
bcx: &BuildContext<'_, '_>,
370+
error: &Option<anyhow::Error>,
362371
) -> CargoResult<()> {
363372
let targets: Vec<String> = self
364373
.root_targets
@@ -380,6 +389,17 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
380389
.max()
381390
.unwrap();
382391
let rustc_info = render_rustc_info(bcx);
392+
let error_msg = match error {
393+
Some(e) => format!(
394+
r#"\
395+
<tr>
396+
<td class="error-text">Error:</td><td>{}</td>
397+
</tr>
398+
"#,
399+
e
400+
),
401+
None => "".to_string(),
402+
};
383403
write!(
384404
f,
385405
r#"
@@ -414,7 +434,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
414434
<tr>
415435
<td>Max (global) rustc threads concurrency:</td><td>{}</td>
416436
</tr>
417-
437+
{}
418438
</table>
419439
"#,
420440
targets,
@@ -429,6 +449,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
429449
total_time,
430450
rustc_info,
431451
max_rustc_concurrency,
452+
error_msg,
432453
)?;
433454
Ok(())
434455
}
@@ -698,6 +719,10 @@ h1 {
698719
text-align: center;
699720
}
700721
722+
.error-text {
723+
color: #e80000;
724+
}
725+
701726
</style>
702727
</head>
703728
<body>

0 commit comments

Comments
 (0)