diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-07-13 15:16:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-13 15:16:02 +0200 |
| commit | 3ff549f6d33ac15df8307025ee068cada8b1e021 (patch) | |
| tree | 8f9f642edbb629c4961257b8570c4131e28b6d9f | |
| parent | 5284c847254cd06309715b03f032617bd110845b (diff) | |
| parent | a9a238ba5b298857dc2999d8ed5b10e70eafe196 (diff) | |
| download | rust-3ff549f6d33ac15df8307025ee068cada8b1e021.tar.gz rust-3ff549f6d33ac15df8307025ee068cada8b1e021.zip | |
Rollup merge of #143826 - Shourya742:2025-07-12-fix-command-trace, r=Kobzol
Fix command trace With the recent developments in centralization of command execution, we somehow broke the traces for command execution. This PR fixes that and add trace to stream command execution as well. r? ````@Kobzol````
| -rw-r--r-- | src/bootstrap/src/utils/exec.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index ebc18f11a05..209ff393973 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -572,6 +572,8 @@ enum CommandState<'a> { executed_at: &'a Location<'a>, fingerprint: CommandFingerprint, start_time: Instant, + #[cfg(feature = "tracing")] + _span_guard: tracing::span::EnteredSpan, }, } @@ -581,6 +583,8 @@ pub struct StreamingCommand { pub stderr: Option<ChildStderr>, fingerprint: CommandFingerprint, start_time: Instant, + #[cfg(feature = "tracing")] + _span_guard: tracing::span::EnteredSpan, } #[must_use] @@ -672,6 +676,9 @@ impl ExecutionContext { ) -> DeferredCommand<'a> { let fingerprint = command.fingerprint(); + #[cfg(feature = "tracing")] + let span_guard = trace_cmd!(command); + if let Some(cached_output) = self.command_cache.get(&fingerprint) { command.mark_as_executed(); self.verbose(|| println!("Cache hit: {command:?}")); @@ -692,13 +699,12 @@ impl ExecutionContext { executed_at, fingerprint, start_time: Instant::now(), + #[cfg(feature = "tracing")] + _span_guard: span_guard, }, }; } - #[cfg(feature = "tracing")] - let _run_span = trace_cmd!(command); - self.verbose(|| { println!("running: {command:?} (created at {created_at}, executed at {executed_at})") }); @@ -720,6 +726,8 @@ impl ExecutionContext { executed_at, fingerprint, start_time, + #[cfg(feature = "tracing")] + _span_guard: span_guard, }, } } @@ -773,6 +781,10 @@ impl ExecutionContext { if !command.run_in_dry_run && self.dry_run() { return None; } + + #[cfg(feature = "tracing")] + let span_guard = trace_cmd!(command); + let start_time = Instant::now(); let fingerprint = command.fingerprint(); let cmd = &mut command.command; @@ -786,7 +798,15 @@ impl ExecutionContext { let stdout = child.stdout.take(); let stderr = child.stderr.take(); - Some(StreamingCommand { child, stdout, stderr, fingerprint, start_time }) + Some(StreamingCommand { + child, + stdout, + stderr, + fingerprint, + start_time, + #[cfg(feature = "tracing")] + _span_guard: span_guard, + }) } } @@ -820,12 +840,17 @@ impl<'a> DeferredCommand<'a> { executed_at, fingerprint, start_time, + #[cfg(feature = "tracing")] + _span_guard, } => { let exec_ctx = exec_ctx.as_ref(); let output = Self::finish_process(process, command, stdout, stderr, executed_at, exec_ctx); + #[cfg(feature = "tracing")] + drop(_span_guard); + if (!exec_ctx.dry_run() || command.run_in_dry_run) && output.status().is_some() && command.should_cache |
