Skip to content

Added tracing spans for rustc invocations #15464

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 1 commit into from
Apr 29, 2025

Conversation

ranger-ross
Copy link
Contributor

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

After

image

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
package = name.as_str(),
process = rustc.to_string()
)
.entered();

let result = exec
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, trace all execs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think that also works.
I put it outside since Executor seems a bit generic, but looking at the function signatures it is very much designed to run rustc.

I went ahead and moved it inside of the Executor in addc570 since I think its a bit nicer to use the #[instrument] macro :)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@@ -140,10 +140,11 @@ pub trait Executor: Send + Sync + 'static {
pub struct DefaultExecutor;

impl Executor for DefaultExecutor {
#[instrument(name = "rustc", skip_all, fields(package = id.name().as_str(), process = cmd.to_string()))]
Copy link
Member

Choose a reason for hiding this comment

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

Just note that this is at INFO log level.

Our instruments are all like this, but I feel like we might want to downgrade to debug or trace. Not a blocker though.

@weihanglo weihanglo added this pull request to the merge queue Apr 29, 2025
Merged via the queue into rust-lang:master with commit 4a7e881 Apr 29, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants