From 4cd0e00655ccb88605c3bc4124edd1d6a5b3f011 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 17 Apr 2023 09:42:45 +0200 Subject: [PATCH] avoid including dry run steps in the build metrics Including steps executed during the dry run will result in a duplication of all the steps in the build metrics, which just adds noise. --- src/bootstrap/builder.rs | 4 ++-- src/bootstrap/metrics.rs | 23 +++++++++++++++++++---- src/bootstrap/render_tests.rs | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index ade8fa4c74dcb..3a50bf5c4dbaf 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -2010,7 +2010,7 @@ impl<'a> Builder<'a> { } #[cfg(feature = "build-metrics")] - self.metrics.enter_step(&step); + self.metrics.enter_step(&step, self); let (out, dur) = { let start = Instant::now(); @@ -2036,7 +2036,7 @@ impl<'a> Builder<'a> { } #[cfg(feature = "build-metrics")] - self.metrics.exit_step(); + self.metrics.exit_step(self); { let mut stack = self.stack.borrow_mut(); diff --git a/src/bootstrap/metrics.rs b/src/bootstrap/metrics.rs index 82b123ec8a5e1..e19d56ccd6adc 100644 --- a/src/bootstrap/metrics.rs +++ b/src/bootstrap/metrics.rs @@ -4,7 +4,7 @@ //! As this module requires additional dependencies not present during local builds, it's cfg'd //! away whenever the `build.metrics` config option is not set to `true`. -use crate::builder::Step; +use crate::builder::{Builder, Step}; use crate::util::t; use crate::Build; use serde_derive::{Deserialize, Serialize}; @@ -33,7 +33,12 @@ impl BuildMetrics { BuildMetrics { state } } - pub(crate) fn enter_step(&self, step: &S) { + pub(crate) fn enter_step(&self, step: &S, builder: &Builder<'_>) { + // Do not record dry runs, as they'd be duplicates of the actual steps. + if builder.config.dry_run() { + return; + } + let mut state = self.state.borrow_mut(); // Consider all the stats gathered so far as the parent's. @@ -56,7 +61,12 @@ impl BuildMetrics { }); } - pub(crate) fn exit_step(&self) { + pub(crate) fn exit_step(&self, builder: &Builder<'_>) { + // Do not record dry runs, as they'd be duplicates of the actual steps. + if builder.config.dry_run() { + return; + } + let mut state = self.state.borrow_mut(); self.collect_stats(&mut *state); @@ -74,7 +84,12 @@ impl BuildMetrics { } } - pub(crate) fn record_test(&self, name: &str, outcome: TestOutcome) { + pub(crate) fn record_test(&self, name: &str, outcome: TestOutcome, builder: &Builder<'_>) { + // Do not record dry runs, as they'd be duplicates of the actual steps. + if builder.config.dry_run() { + return; + } + let mut state = self.state.borrow_mut(); state .running_steps diff --git a/src/bootstrap/render_tests.rs b/src/bootstrap/render_tests.rs index 19019ad2c089d..a56db9cccfe5b 100644 --- a/src/bootstrap/render_tests.rs +++ b/src/bootstrap/render_tests.rs @@ -124,6 +124,7 @@ impl<'a> Renderer<'a> { ignore_reason: reason.map(|s| s.to_string()), }, }, + self.builder, ); if self.builder.config.verbose_tests {