Skip to content

Fix command trace #143826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2025
Merged
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
33 changes: 29 additions & 4 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ enum CommandState<'a> {
executed_at: &'a Location<'a>,
fingerprint: CommandFingerprint,
start_time: Instant,
#[cfg(feature = "tracing")]
_span_guard: tracing::span::EnteredSpan,
},
}

Expand All @@ -602,6 +604,8 @@ pub struct StreamingCommand {
pub stderr: Option<ChildStderr>,
fingerprint: CommandFingerprint,
start_time: Instant,
#[cfg(feature = "tracing")]
_span_guard: tracing::span::EnteredSpan,
}

#[must_use]
Expand Down Expand Up @@ -693,6 +697,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:?}"));
Expand All @@ -713,13 +720,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})")
});
Expand All @@ -741,6 +747,8 @@ impl ExecutionContext {
executed_at,
fingerprint,
start_time,
#[cfg(feature = "tracing")]
_span_guard: span_guard,
},
}
}
Expand Down Expand Up @@ -794,6 +802,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;
Expand All @@ -807,7 +819,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,
})
}
}

Expand Down Expand Up @@ -841,12 +861,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
Expand Down
Loading