Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ pub fn create_bcx<'a, 'gctx>(
let root_unit_indexes: HashSet<_> =
root_units.iter().map(|unit| unit_to_index[&unit]).collect();

for (index, unit) in units.into_iter().enumerate() {
logger.log_batch(units.into_iter().enumerate().map(|(index, unit)| {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not usually a fan of big map functions and tend to prefer explicit loops for them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

shell holds a mutex lock and stdout lock, which are a bit expensive to work with. Other alternatives are having a buffer for shell print, or just eating the cost

let index = index as u64;
logger.log(LogMessage::UnitRegistered {
LogMessage::UnitRegistered {
package_id: unit.pkg.package_id().to_spec(),
target: (&unit.target).into(),
mode: unit.mode,
Expand All @@ -547,8 +547,8 @@ pub fn create_bcx<'a, 'gctx>(
.map(|s| s.as_str().to_owned())
.collect(),
requested: root_unit_indexes.contains(&index),
});
}
}
}));
let elapsed = ws.gctx().creation_time().elapsed().as_secs_f64();
logger.log(LogMessage::UnitGraphFinished { elapsed });
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/util/context/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ pub struct CargoBuildConfig {
}

/// Metrics collection for build analysis.
#[derive(Debug, Deserialize, Default)]
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CargoBuildAnalysis {
pub enabled: bool,
pub enabled: Option<bool>,
}

/// Whether warnings should warn, be allowed, or cause an error.
Expand Down
13 changes: 12 additions & 1 deletion src/cargo/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ impl BuildLogger {
pub fn maybe_new(ws: &Workspace<'_>) -> CargoResult<Option<Self>> {
let analysis = ws.gctx().build_config()?.analysis.as_ref();
match (analysis, ws.gctx().cli_unstable().build_analysis) {
(Some(analysis), true) if analysis.enabled => Ok(Some(Self::new(ws)?)),
(Some(analysis), true) if analysis.enabled.unwrap_or_default() => {
Ok(Some(Self::new(ws)?))
}
(Some(_), false) => {
ws.gctx().shell().warn(
"ignoring 'build.analysis' config, pass `-Zbuild-analysis` to enable it",
Expand Down Expand Up @@ -84,6 +86,15 @@ impl BuildLogger {
pub fn log(&self, msg: LogMessage) {
let _ = self.tx.send(msg);
}

/// Batch-Logs multiple messages.
///
/// This should be used when logging many messages in a tight loop.
pub fn log_batch(&self, messages: impl IntoIterator<Item = LogMessage>) {
for msg in messages {
let _ = self.tx.send(msg);
}
}
}

impl Drop for BuildLogger {
Expand Down