Skip to content

Commit

Permalink
-Ztimings: show max jobs/cpus
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Sep 20, 2019
1 parent 7ab4778 commit a6ecbad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 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 @@ -445,7 +445,7 @@ impl<'a, 'cfg> JobQueue<'a, 'cfg> {
if !cx.bcx.build_config.build_plan {
cx.bcx.config.shell().status("Finished", message)?;
}
self.timings.finished()?;
self.timings.finished(cx.bcx)?;
Ok(())
} else {
debug!("queue: {:#?}", self.queue);
Expand Down
26 changes: 15 additions & 11 deletions src/cargo/core/compiler/timings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ pub struct Timings<'a, 'cfg> {
start: Instant,
/// A rendered string of when compilation started.
start_str: String,
/// Some information to display about rustc.
rustc_info: String,
/// A summary of the root units.
///
/// Tuples of `(package_description, target_descrptions)`.
Expand Down Expand Up @@ -118,7 +116,6 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
})
.collect();
let start_str = humantime::format_rfc3339_seconds(SystemTime::now()).to_string();
let rustc_info = render_rustc_info(bcx);
let profile = if bcx.build_config.release {
"release"
} else {
Expand All @@ -134,7 +131,6 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
report_json,
start: bcx.config.creation_time(),
start_str,
rustc_info,
root_targets,
profile,
total_fresh: 0,
Expand Down Expand Up @@ -290,21 +286,21 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
}

/// Call this when all units are finished.
pub fn finished(&mut self) -> CargoResult<()> {
pub fn finished(&mut self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
if !self.enabled {
return Ok(());
}
self.mark_concurrency(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()?;
self.report_html(bcx)?;
}
Ok(())
}

/// Save HTML report to disk.
fn report_html(&self) -> CargoResult<()> {
fn report_html(&self, bcx: &BuildContext<'_, '_>) -> CargoResult<()> {
let duration = self.start.elapsed().as_secs() as u32 + 1;
let timestamp = self.start_str.replace(&['-', ':'][..], "");
let filename = format!("cargo-timing-{}.html", timestamp);
Expand All @@ -315,7 +311,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)?;
self.write_summary_table(&mut f, duration, bcx)?;
f.write_all(HTML_CANVAS.as_bytes())?;
self.write_unit_table(&mut f)?;
writeln!(
Expand Down Expand Up @@ -350,7 +346,12 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
}

/// Render the summary table.
fn write_summary_table(&self, f: &mut impl Write, duration: u32) -> CargoResult<()> {
fn write_summary_table(
&self,
f: &mut impl Write,
duration: u32,
bcx: &BuildContext<'_, '_>,
) -> CargoResult<()> {
let targets: Vec<String> = self
.root_targets
.iter()
Expand All @@ -364,6 +365,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
};
let total_time = format!("{}s{}", duration, time_human);
let max_concurrency = self.concurrency.iter().map(|c| c.active).max().unwrap();
let rustc_info = render_rustc_info(bcx);
write!(
f,
r#"
Expand All @@ -384,7 +386,7 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
<td>Total units:</td><td>{}</td>
</tr>
<tr>
<td>Max concurrency:</td><td>{}</td>
<td>Max concurrency:</td><td>{} (jobs={} ncpu={})</td>
</tr>
<tr>
<td>Build start:</td><td>{}</td>
Expand All @@ -404,9 +406,11 @@ impl<'a, 'cfg> Timings<'a, 'cfg> {
self.total_dirty,
self.total_fresh + self.total_dirty,
max_concurrency,
bcx.build_config.jobs,
num_cpus::get(),
self.start_str,
total_time,
self.rustc_info,
rustc_info,
)?;
Ok(())
}
Expand Down

0 comments on commit a6ecbad

Please sign in to comment.