Skip to content
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

Add profiling of bootstrap commands using Chrome events #136924

Merged
merged 3 commits into from
Feb 14, 2025

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Feb 12, 2025

Since we now have support for tracing in bootstrap, and the execution of most commands is centralized within a few functions, it's quite trivial to also trace command execution, and visualize it using the Chrome profiler. This can be helpful both to profile what takes time in bootstrap and also to get a visual idea of what happens in a given bootstrap invocation (since the execution of external commands is usually the most interesting thing).

This is how it looks:
image

I first tried to use tracing-flame, but the output wasn't very useful, because the event/stackframe names were bootstrap code locations, instead of the command contents.

r? @jieyouxu

@rustbot rustbot added A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Feb 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2025

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol

@jieyouxu
Copy link
Member

omg

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Looks very cool (and impl looks good in general), I'll play around with this tmrw

@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

Clippy lint failures look likely genuine, maybe the span guards aren't actually being returned?

@Kobzol
Copy link
Contributor Author

Kobzol commented Feb 12, 2025

Sigh, this is annoying. I need the let binding to have a guard if tracing is enabled, and nothing if not. But storing () into a variable apparently upsets Clippy. Anyway, fixed it.

@jieyouxu
Copy link
Member

Played around with this a bit locally, seems to work

Screenshot 2025-02-13 192116

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Impl looks good, can you squash the bootstrap changes into one commit? r=me after

@jieyouxu
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2025
@jieyouxu jieyouxu added A-bootstrap-tracing Area: bootstrap tracing A-bootstrap-profiling Area: bootstrap profiling labels Feb 13, 2025
@Kobzol
Copy link
Contributor Author

Kobzol commented Feb 13, 2025

I squashed the Clippy change, I assume that's what you meant (?). I think that keeping the command tracing commit separate makes sense, it could be useful even without the profiling.

@Kobzol
Copy link
Contributor Author

Kobzol commented Feb 13, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2025
@jieyouxu
Copy link
Member

Yeah that's fine, thanks
@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 13, 2025

📌 Commit 521cbd3 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 14, 2025
Add profiling of bootstrap commands using Chrome events

Since we now have support for tracing in bootstrap, and the execution of most commands is centralized within a few functions, it's quite trivial to also trace command execution, and visualize it using the Chrome profiler. This can be helpful both to profile what takes time in bootstrap and also to get a visual idea of what happens in a given bootstrap invocation (since the execution of external commands is usually the most interesting thing).

This is how it looks:
![image](https://github.com/user-attachments/assets/3351489e-3a0f-4729-9082-5bf40c586d4b)

I first tried to use [tracing-flame](https://github.com/tokio-rs/tracing/tree/master/tracing-flame), but the output wasn't very useful, because the event/stackframe names were bootstrap code locations, instead of the command contents.

r? `@jieyouxu`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
…kingjubilee

Rollup of 13 pull requests

Successful merges:

 - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`)
 - rust-lang#136460 (Simplify `rustc_span` `analyze_source_file`)
 - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package)
 - rust-lang#136904 (add `IntoBounds` trait)
 - rust-lang#136908 ([AIX] expect `EINVAL` for `pthread_mutex_destroy`)
 - rust-lang#136924 (Add profiling of bootstrap commands using Chrome events)
 - rust-lang#136951 (Use the right binder for rebinding `PolyTraitRef`)
 - rust-lang#136956 (add vendor directory to .gitignore)
 - rust-lang#136967 (Use `slice::fill` in `io::Repeat` implementation)
 - rust-lang#136976 (alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr)
 - rust-lang#136981 (ci: switch loongarch jobs to free runners)
 - rust-lang#136992 (Update backtrace)
 - rust-lang#136993 ([cg_llvm] Remove dead error message)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`)
 - rust-lang#136460 (Simplify `rustc_span` `analyze_source_file`)
 - rust-lang#136904 (add `IntoBounds` trait)
 - rust-lang#136908 ([AIX] expect `EINVAL` for `pthread_mutex_destroy`)
 - rust-lang#136924 (Add profiling of bootstrap commands using Chrome events)
 - rust-lang#136951 (Use the right binder for rebinding `PolyTraitRef`)
 - rust-lang#136981 (ci: switch loongarch jobs to free runners)
 - rust-lang#136992 (Update backtrace)
 - rust-lang#136993 ([cg_llvm] Remove dead error message)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6c1768e into rust-lang:master Feb 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
Rollup merge of rust-lang#136924 - Kobzol:bootstrap-tracing, r=jieyouxu

Add profiling of bootstrap commands using Chrome events

Since we now have support for tracing in bootstrap, and the execution of most commands is centralized within a few functions, it's quite trivial to also trace command execution, and visualize it using the Chrome profiler. This can be helpful both to profile what takes time in bootstrap and also to get a visual idea of what happens in a given bootstrap invocation (since the execution of external commands is usually the most interesting thing).

This is how it looks:
![image](https://github.com/user-attachments/assets/3351489e-3a0f-4729-9082-5bf40c586d4b)

I first tried to use [tracing-flame](https://github.com/tokio-rs/tracing/tree/master/tracing-flame), but the output wasn't very useful, because the event/stackframe names were bootstrap code locations, instead of the command contents.

r? ``@jieyouxu``
@Kobzol Kobzol deleted the bootstrap-tracing branch February 14, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bootstrap-profiling Area: bootstrap profiling A-bootstrap-tracing Area: bootstrap tracing A-rustc-dev-guide Area: rustc-dev-guide S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants