Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/timings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,14 @@ impl<'gctx> Timings<'gctx> {
.iter()
.map(|kind| build_runner.bcx.target_data.short_name(kind))
.collect::<Vec<_>>();
let num_cpus = std::thread::available_parallelism()
.ok()
.map(|x| x.get() as u64);

let unit_data = report::to_unit_data(&self.unit_times, &self.unit_to_index);
let concurrency = report::compute_concurrency(&unit_data);

let ctx = report::RenderContext {
start: self.start,
start_str: &self.start_str,
root_units: &self.root_targets,
profile: &self.profile,
Expand All @@ -455,6 +457,7 @@ impl<'gctx> Timings<'gctx> {
host: &build_runner.bcx.rustc().host,
requested_targets,
jobs: build_runner.bcx.jobs(),
num_cpus,
error,
};
report::write_html(ctx, &mut f)?;
Expand Down
17 changes: 9 additions & 8 deletions src/cargo/core/compiler/timings/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::collections::HashSet;
use std::io::Write;
use std::time::Instant;

use itertools::Itertools as _;

Expand Down Expand Up @@ -96,8 +95,6 @@ pub struct Concurrency {
}

pub struct RenderContext<'a> {
/// When Cargo started.
pub start: Instant,
/// A rendered string of when compilation started.
pub start_str: &'a str,
/// A summary of the root units.
Expand Down Expand Up @@ -127,13 +124,16 @@ pub struct RenderContext<'a> {
pub requested_targets: &'a [&'a str],
/// The number of jobs specified for this build.
pub jobs: u32,
/// Available parallelism of the compilation environment.
pub num_cpus: Option<u64>,
/// Fatal error during the build.
pub error: &'a Option<anyhow::Error>,
}

/// Writes an HTML report.
pub(super) fn write_html(ctx: RenderContext<'_>, f: &mut impl Write) -> CargoResult<()> {
let duration = ctx.start.elapsed().as_secs_f64();
// The last concurrency record should equal to the last unit finished time.
let duration = ctx.concurrency.last().map(|c| c.t).unwrap_or(0.0);
let roots: Vec<&str> = ctx
.root_units
.iter()
Expand Down Expand Up @@ -186,10 +186,11 @@ fn write_summary_table(
};
let total_time = format!("{:.1}s{}", duration, time_human);

let max_concurrency = ctx.concurrency.iter().map(|c| c.active).max().unwrap();
let num_cpus = std::thread::available_parallelism()
.map(|x| x.get().to_string())
.unwrap_or_else(|_| "n/a".into());
Comment on lines -190 to -192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, surprised we don't take the config overriding this into account

let max_concurrency = ctx.concurrency.iter().map(|c| c.active).max().unwrap_or(0);
let num_cpus = ctx
.num_cpus
.map(|x| x.to_string())
.unwrap_or_else(|| "n/a".into());

let requested_targets = ctx.requested_targets.join(", ");

Expand Down
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ pub fn compile_ws<'a>(

if let Some(ref logger) = logger {
let rustc = ws.gctx().load_global_rustc(Some(ws))?;
let num_cpus = std::thread::available_parallelism()
.ok()
.map(|x| x.get() as u64);
logger.log(LogMessage::BuildStarted {
cwd: ws.gctx().cwd().to_path_buf(),
host: rustc.host.to_string(),
jobs: options.build_config.jobs,
num_cpus,
profile: options.build_config.requested_profile.to_string(),
rustc_version: rustc.version.to_string(),
rustc_version_verbose: rustc.verbose_version.clone(),
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/log_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum LogMessage {
host: String,
/// Number of parallel jobs.
jobs: u32,
/// Available parallelism of the compilation environment.
num_cpus: Option<u64>,
/// Build profile name (e.g., "dev", "release").
profile: String,
/// The rustc version (`1.23.4-beta.2`).
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/build_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn log_msg_build_started() {
"cwd": "[ROOT]/foo",
"host": "[HOST_TARGET]",
"jobs": "{...}",
"num_cpus": "{...}",
"profile": "dev",
"reason": "build-started",
"run_id": "[..]T[..]Z-[..]",
Expand Down
Loading