Skip to content

Commit

Permalink
Auto merge of #7872 - ehuss:timings-error, r=Eh2406
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Feb 6, 2020
2 parents db0dac5 + 2061e86 commit c55d363
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
}

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

if let Some(e) = error {
Err(e)
Expand All @@ -687,7 +688,6 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
if !cx.bcx.build_config.build_plan {
cx.bcx.config.shell().status("Finished", message)?;
}
self.timings.finished(cx.bcx)?;
Ok(())
} else {
debug!("queue: {:#?}", self.queue);
Expand Down
35 changes: 30 additions & 5 deletions src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,29 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
}

/// Call this when all units are finished.
pub fn finished(&mut self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
pub fn finished(
&mut self,
bcx: &BuildContext<'_, '_>,
error: &Option<anyhow::Error>,
) -> CargoResult<()> {
if !self.enabled {
return Ok(());
}
self.mark_concurrency(0, 0, 0, 0);
self.unit_times
.sort_unstable_by(|a, b| a.start.partial_cmp(&b.start).unwrap());
if self.report_html {
self.report_html(bcx)?;
self.report_html(bcx, error)?;
}
Ok(())
}

/// Save HTML report to disk.
fn report_html(&self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
fn report_html(
&self,
bcx: &BuildContext<'_, '_>,
error: &Option<anyhow::Error>,
) -> CargoResult<()> {
let duration = d_as_f64(self.start.elapsed());
let timestamp = self.start_str.replace(&['-', ':'][..], "");
let filename = format!("cargo-timing-{}.html", timestamp);
Expand All @@ -318,7 +326,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
.map(|(name, _targets)| name.as_str())
.collect();
f.write_all(HTML_TMPL.replace("{ROOTS}", &roots.join(", ")).as_bytes())?;
self.write_summary_table(&mut f, duration, bcx)?;
self.write_summary_table(&mut f, duration, bcx, error)?;
f.write_all(HTML_CANVAS.as_bytes())?;
self.write_unit_table(&mut f)?;
// It helps with pixel alignment to use whole numbers.
Expand Down Expand Up @@ -359,6 +367,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
f: &mut impl Write,
duration: f64,
bcx: &BuildContext<'_, '_>,
error: &Option<anyhow::Error>,
) -> CargoResult<()> {
let targets: Vec<String> = self
.root_targets
Expand All @@ -380,6 +389,17 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
.max()
.unwrap();
let rustc_info = render_rustc_info(bcx);
let error_msg = match error {
Some(e) => format!(
r#"\
<tr>
<td class="error-text">Error:</td><td>{}</td>
</tr>
"#,
e
),
None => "".to_string(),
};
write!(
f,
r#"
Expand Down Expand Up @@ -414,7 +434,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
<tr>
<td>Max (global) rustc threads concurrency:</td><td>{}</td>
</tr>
{}
</table>
"#,
targets,
Expand All @@ -429,6 +449,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
total_time,
rustc_info,
max_rustc_concurrency,
error_msg,
)?;
Ok(())
}
Expand Down Expand Up @@ -698,6 +719,10 @@ h1 {
text-align: center;
}
.error-text {
color: #e80000;
}
</style>
</head>
<body>
Expand Down

0 comments on commit c55d363

Please sign in to comment.