Skip to content

Commit 4a7e881

Browse files
authored
Added tracing spans for rustc invocations (#15464)
### What does this PR try to resolve? While doing some investigation on the theoretical performance implications of #4282 (and #15010 by extension) I was profiling cargo with some experimental changes. (Still a work in progress) But in the mean time, noticed that we do not have spans for rustc invocations. I think these would be useful when profiling `cargo build`. (`cargo build --timing` exists but is more geared towards debugging a slow building project, not cargo itself) For reference below is an example before/after of a profile run of a dummy crate with a few random dependencies. #### Before ![image](https://github.com/user-attachments/assets/710d1b93-133d-4826-9e7a-2deed876dbfa) #### After ![image](https://github.com/user-attachments/assets/0f0ccad4-82b5-42ad-8762-6bd1dacecab4)
2 parents 2887f07 + addc570 commit 4a7e881

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/cargo/core/compiler/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use std::sync::Arc;
6767

6868
use anyhow::{Context as _, Error};
6969
use lazycell::LazyCell;
70-
use tracing::{debug, trace};
70+
use tracing::{debug, instrument, trace};
7171

7272
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat, TimingOutput};
7373
pub use self::build_context::{
@@ -140,10 +140,11 @@ pub trait Executor: Send + Sync + 'static {
140140
pub struct DefaultExecutor;
141141

142142
impl Executor for DefaultExecutor {
143+
#[instrument(name = "rustc", skip_all, fields(package = id.name().as_str(), process = cmd.to_string()))]
143144
fn exec(
144145
&self,
145146
cmd: &ProcessBuilder,
146-
_id: PackageId,
147+
id: PackageId,
147148
_target: &Target,
148149
_mode: CompileMode,
149150
on_stdout_line: &mut dyn FnMut(&str) -> CargoResult<()>,

0 commit comments

Comments
 (0)