Skip to content

Added support for rustc self-profiling#4073

Open
1vipulgupta wants to merge 1 commit into
bazelbuild:mainfrom
1vipulgupta:feat/rustc-self-profile
Open

Added support for rustc self-profiling#4073
1vipulgupta wants to merge 1 commit into
bazelbuild:mainfrom
1vipulgupta:feat/rustc-self-profile

Conversation

@1vipulgupta

@1vipulgupta 1vipulgupta commented Jun 8, 2026

Copy link
Copy Markdown

Introduced a new build setting, --//rust/settings:zself_profile_events, to enable rustc's -Zself-profile and -Zself-profile-events flag. Rust nightly toolchain is required for using this feature.
The setting accepts patterns to match against crate labels or execution paths, allowing fine-grained control over which crates are profiled.
Profiling data is output to a <crate_name>_self-profile directory.

@1vipulgupta 1vipulgupta force-pushed the feat/rustc-self-profile branch from 0b0131c to 846dbe4 Compare June 8, 2026 17:27
@1vipulgupta 1vipulgupta changed the title Add support for rustc self-profiling Added support for rustc self-profiling Jun 9, 2026
@krasimirgg krasimirgg self-requested a review June 9, 2026 11:38
@1vipulgupta 1vipulgupta force-pushed the feat/rustc-self-profile branch from 846dbe4 to d4900c1 Compare June 9, 2026 13:34

@krasimirgg krasimirgg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is very nice!
Let's also add a test (let's chat internally about the mechanics of testing this).

Comment thread rust/private/rustc.bzl
"nightly compiler toolchain. The setting is configured from the command line via " +
"`--@rules_rust//rust/settings:zself_profile_events`." +
"The expected value format is `<prefix_filter>@<events_specification>`. Multiple uses of " +
"this flag are accumulated: " +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: is it intended that this sentence ends in :?

Comment thread rust/private/rustc.bzl
"`--@rules_rust//rust/settings:zself_profile_events`." +
"The expected value format is `<prefix_filter>@<events_specification>`. Multiple uses of " +
"this flag are accumulated: " +
"If the target prefix matches with <prefix_filter>, `-Zself-profile` and `-Zself-profile-events` " +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just confirming something: after reading the setup_zself_profile implementation, the event types are collected from the first matching filter:
For instance, here the event types would be foo:
--@rules_rust//rust/settings:zself_profile_events=//my/project@foo --@rules_rust//rust/settings:zself_profile_events=//my/project@bar
I think this is OK, but could you clarify? Especially in the context of the previous sentence "Multiple uses of this flag are accumulated" -- a user reading this may interpret this as that in the example above, both foo and bar are collected, so there's potential for confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants