Skip to content

Print CGU reuse statistics in -Zprint-mono-items #144899

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
Aug 8, 2025

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Aug 4, 2025

I'm trying to expose more information about incremental profiling from rustc (https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Profiling.2Fanalysis.20of.20incremental.20builds/with/531383501). One of the things that would be quite useful to expose is the CGU reuse state, so that when you do a rebuild, you can see all the CGUs (and all the functions) that had to be recompiled.

Currently, we have (AFAIK) two ways of outputting monomorphization statistics:

  1. -Zdump-mono-stats outputs statistics about number of instantiations and expected compilation cost of individual functions in the local crate being compiled. It can be outputted either as Markdown or JSON.
  2. -Zprint-mono-items outputs a pair (item, CGU) for each monomorphized item.

I was thinking about recording CGU statistics in the self-profile output, but I realized that as a simpler step, we could just add CGU reuse data to -Zprint-mono-items, as an additional output. That is what this PR does.

@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@jieyouxu
Copy link
Member

jieyouxu commented Aug 4, 2025

Rerolling a codegen reviewer for vibes on the approach; even though this is an perma-unstable flag.
r? codegen

@rustbot rustbot assigned saethlin and unassigned jieyouxu Aug 4, 2025
@klensy
Copy link
Contributor

klensy commented Aug 4, 2025

-Zdump-mono-stats
-Zprint-mono-items

Will be nice to name it -Zprint-mono-stats :-)

@@ -735,6 +735,11 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
crate::assert_module_sources::assert_module_sources(tcx, &|cgu_reuse_tracker| {
for (i, cgu) in codegen_units.iter().enumerate() {
let cgu_reuse = cgu_reuse[i];

if tcx.sess.opts.unstable_opts.print_mono_items {
println!("CGU_REUSE {} {cgu_reuse}", cgu.name());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe do this inside the cgu_reuse_tracker instead? The current changes in this PR don't apply to cg_clif.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, moved it to assert_module_sources.

@saethlin
Copy link
Member

saethlin commented Aug 7, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 7, 2025

📌 Commit d857d54 has been approved by saethlin

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 Aug 7, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 8, 2025
Print CGU reuse statistics in `-Zprint-mono-items`

I'm trying to expose more information about incremental profiling from rustc (https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Profiling.2Fanalysis.20of.20incremental.20builds/with/531383501). One of the things that would be quite useful to expose is the CGU reuse state, so that when you do a rebuild, you can see all the CGUs (and all the functions) that had to be recompiled.

Currently, we have (AFAIK) two ways of outputting monomorphization statistics:
1) `-Zdump-mono-stats` outputs statistics about number of instantiations and expected compilation cost of individual functions in the local crate being compiled. It can be outputted either as Markdown or JSON.
2) `-Zprint-mono-items` outputs a pair (item, CGU) for each monomorphized item.

I was thinking about recording CGU statistics in the self-profile output, but I realized that as a simpler step, we could just add CGU reuse data to `-Zprint-mono-items`, as an additional output. That is what this PR does.
bors added a commit that referenced this pull request Aug 8, 2025
Rollup of 19 pull requests

Successful merges:

 - #144400 (`tests/ui/issues/`: The Issues Strike Back [3/N])
 - #144764 ([codegen] assume the tag, not the relative discriminant)
 - #144807 (Streamline config in bootstrap)
 - #144899 (Print CGU reuse statistics in `-Zprint-mono-items`)
 - #144909 (Add new `test::print_merged_doctests_times` used by rustdoc to display more detailed time information)
 - #144912 (Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution.)
 - #144914 (Add support for `ty::Instance` path shortening in diagnostics)
 - #144931 ([win][arm64ec] Fix msvc-wholearchive for Arm64EC)
 - #144999 (coverage: Remove all unstable support for MC/DC instrumentation)
 - #145009 (A couple small changes for rust-analyzer next-solver work)
 - #145030 (GVN:  Do not flatten derefs with ProjectionElem::Index. )
 - #145042 (stdarch subtree update)
 - #145047 (move `type_check` out of `compute_regions`)
 - #145051 (Prevent name collisions with internal implementation details)
 - #145053 (Add a lot of NLL `known-bug` tests)
 - #145055 (Move metadata symbol export from exported_non_generic_symbols to exported_symbols)
 - #145057 (Clean up some resolved test regressions of const trait removals in std)
 - #145068 (Readd myself to review queue)
 - #145070 (Add minimal `armv7a-vex-v5` tier three target)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2b7659c into rust-lang:master Aug 8, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 8, 2025
@Kobzol Kobzol deleted the cgu-reuse branch August 8, 2025 09:12
rust-timer added a commit that referenced this pull request Aug 8, 2025
Rollup merge of #144899 - Kobzol:cgu-reuse, r=saethlin

Print CGU reuse statistics in `-Zprint-mono-items`

I'm trying to expose more information about incremental profiling from rustc (https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Profiling.2Fanalysis.20of.20incremental.20builds/with/531383501). One of the things that would be quite useful to expose is the CGU reuse state, so that when you do a rebuild, you can see all the CGUs (and all the functions) that had to be recompiled.

Currently, we have (AFAIK) two ways of outputting monomorphization statistics:
1) `-Zdump-mono-stats` outputs statistics about number of instantiations and expected compilation cost of individual functions in the local crate being compiled. It can be outputted either as Markdown or JSON.
2) `-Zprint-mono-items` outputs a pair (item, CGU) for each monomorphized item.

I was thinking about recording CGU statistics in the self-profile output, but I realized that as a simpler step, we could just add CGU reuse data to `-Zprint-mono-items`, as an additional output. That is what this PR does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants