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

-Z instrument-xray option #561

Closed
3 tasks done
ilammy opened this issue Oct 2, 2022 · 4 comments
Closed
3 tasks done

-Z instrument-xray option #561

ilammy opened this issue Oct 2, 2022 · 4 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@ilammy
Copy link

ilammy commented Oct 2, 2022

Proposal

Add support for XRay instrumentation, enabled by the -Z instrument-xray option, later to be stabilized subject to bikeshedding.

Motivation

XRay tracing is an alternative to existing -Z instrument-mcount instrumentation. It is superior in capabilities and flexibility, while keeping minimal performance impact when inactive.

Design

See a post on internals for an infodump, here is a summary.

Command line option

Introduce a flag with options:

  • -Z instrument-xray – enable implicit defaults
  • -Z instrument-xray={on|off|yes|no} – explicit enable/disable
  • -Z instrument-xray=<option> – enable with an optional setting
  • -Z instrument-xray=<option1>,<option2>... – enable with multiple comma-separated settings

where supported options are:

  • always – force instrumentation of all functions
  • never – do no instrument any functions
  • ignore-loops – ignore presence of loops, instrument functions based only on instruction count
  • instruction-threshold=10 – set a different instruction threshold for instrumentation
  • skip-entry – do no instrument function entry
  • skip-exit – do no instrument function exit

Codegen support

If -Z instrument-xray is enabled, codegen annotates emitted functions with attributes as appropriate:

  • "xray-instruction-threshold"="100"
  • "function-instrument"="xray-always"
  • etc.

LLVM does the rest, scheduling the appropriate pass which inserts instrumentation into emitted machine code, notes down instrumented locations in xray_instr_map section, etc.

Instrumented binaries are expected to link with an suitable runtime library of their choice which will make use of the instrumentation.

Language changes

Aside from the codegen option, introduce a new attribute #[instrument::xray(...)] allowing to fine-tune instrumented functions, at individual crate/module/impl/function/etc. level.

The attribute would mirror options available on the command line, for example:

#[instrument::xray(ignore_loops)]
mod my_loops {
    fn do_things() {
        loop {
            // ...
        }
    }

    #[instrument::xray(never)]
    fn performance_critical() {
        // ...
    }
}

Detailed design and interaction with language items to be hashed out separately, via the RFC process, I guess.

Prior art

See options provided by Clang for XRay control:

  • -fxray-instrument – enable instrumentation
  • -fno-xray-function-index – inhibit the xray_instr_map section
  • -fxray-attr-list – pass a file with attribute overrides
  • -fxray-function-groups – instrument a random sample of functions
  • -fxray-ignore-loops – control which functions to instrument
  • -fxray-instruction-threshold=N
  • -fxray-instrumentation-bundle={all|none|function-entry|function-exit|function|custom}

Some of those might turn out to be useful, so I'd like to reserve -Z instrument-xray-... namespace for future extensions.

Alternatives

  • Instead of a unified multi-option: -Z insturment-xray=<option>... provide separate ones, like Clang does: -Z instrument-xray, -Z instrument-xray-ignore-loops.

    We have a benefit of not having to maintain compatibility with previously existing flags, thus the new option can be conveniently namespaced. -Z instrument-xray can be passed several times, enabling settings one by one.

Mentors or Reviewers

no idea, please send help

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@ilammy ilammy added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Oct 2, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 2, 2022

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Oct 2, 2022
@nnethercote
Copy link

Presumably the -Z instrument-count mentions in the description should be -Z instrument-xray?

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 18, 2022
@estebank
Copy link

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Jan 19, 2023
@apiraino
Copy link
Contributor

apiraino commented Feb 1, 2023

@rustbot label -final-comment-period +major-change-accepted

@apiraino apiraino closed this as completed Feb 1, 2023
@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Feb 1, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 3, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 10, 2023
Add `-Z instrument-xray` flag

Implement MCP rust-lang/compiler-team#561, adding `-Z instrument-xray` flag which enables XRay instrumentation in LLVM.
RalfJung pushed a commit to RalfJung/miri that referenced this issue Feb 11, 2023
Add `-Z instrument-xray` flag

Implement MCP rust-lang/compiler-team#561, adding `-Z instrument-xray` flag which enables XRay instrumentation in LLVM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

5 participants