Skip to content

Conversation

@weihanglo
Copy link
Member

@weihanglo weihanglo commented Nov 25, 2025

What does this PR try to resolve?

Convert timing-info log messages from a single aggregated message per unit
to an event-based model that captures the build timings.

New events introduced:

  • unit-started - compilation begins (full metadata + index)
  • unit-rmeta-finished - .rmeta artifact generated (with unlocked units)
  • unit-section-{started,finished} - compilation phases (with section name)
  • unit-finished - completion (with unlocked units)
  • All events use elapsed time instead of duration
  • All events reference units by deterministic index from unit-started

Changes in old events:

  • timing-info — split to five unit-* events
  • rebuild — the target field now use a custom struct to show { name, kind }, which should be good enough to distinguish different units.

Part of #15844.

How to test and review this PR?

Test diffs should reflect the change.
A new test has bee added to showcase -Zsection-timings
(apparently we didn't have any test before).

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-rebuild-detection Area: rebuild detection and fingerprinting A-timings Area: timings S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

r? @epage

rustbot has assigned @epage.
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

@weihanglo weihanglo changed the title fix(log): rename timing-info to unit-finished fix(log): break timing-info message to multiple Nov 25, 2025
@weihanglo weihanglo added the Z-build-analysis Nightly: build-analysis label Nov 25, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Before I dig into this too much, do we need special messages for these or are there existing json messages from cargo we could use if we also log those? If not, are there existing rustc messages that we can translate into cargo messages to handle this?

Copy link
Member Author

Choose a reason for hiding this comment

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

What Cargo --message-format=json emits today:

  • build-finished — for the entire build, not at per unit level
  • build-script-exectued — emitted after build script execution
  • compiler-artifact — emitted when a compiler artifact is produced for each rustc invocation.
  • compiler-message — this is basically rustc diagonstics.
  • timing-info — the unstable aggregated timing info. It is the same as the old timing-info log message before this PR.

None of them has any elapsed time information

What rustc has today:

  • diagnostic — just diagnostics
  • artifact — Notice when an artifact is written to disk. Contains file name and emit-type.
  • future_incompat — for future incompat warnings
  • section_timing — unstable section timing. Looks like
    {
        "event": "start", /* Marks the "start" or "end" of the compilation section */
        "name": "link",  /* The name of the compilation section */
        // Opaque timestamp when the message was emitted, in microseconds
        // The timestamp is currently relative to the beginning of the compilation session
        "time": 12345
    }

I don't feel like there is anything we can directly use. timing-info Cargo message is half-broken. compiler-artifact has too much of information timing tracking doesn't need (but perhaps we'd like to expand to that in the future). We might not want to rely on section_timing's time field, as it is unclear what "beginning of the compilation" refers to.

The current approach gives us a room to iterate on our own at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we view this as a hack and document that we need to consolidate our messages, I'm fine moving forward with this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it is not the final version. I'd love to learn your thoughts on long-term consolidating our JSON messages and logging.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to flesh out our json messages more

From #7614 (comment)

I think we should work to improve our json messages. The build analysis work is one area that will help shine a light on that. Another is the new cargo-fix architecture which would ideally have cargo check like progress while being a wrapper around cargo check, so we'll need json messages to support all of the progress reporting needs

If we log all json messages, we'll have redundancy with this.

From #t-cargo > build analysis log format @ 💬

would love for us to record all --message-format json messages

I also wonder if we should go with a full inverse, all logged messages are also json messages. Of course, we'll likely need to keep them distinct while the feature is unstable and we work through what we want the schema to be.

Comment on lines +140 to +143
"target": {
"kind": "lib",
"name": "bar"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

While this reduces content, it does deviate from our normal structure of json messages

Copy link
Member Author

Choose a reason for hiding this comment

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

I am seeing timings message different from other messages. If users want details information, they should either inspect other messages or cargo metadata. Though if we want to be a bit consistent atm, fine with reusing the detailed Target struct.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this ties into #16303 (comment)

/// Emitted when a compilation unit starts.
UnitStarted {
package_id: PackageIdSpec,
target: Target,
Copy link
Contributor

Choose a reason for hiding this comment

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

This also is being inconsistent

@rustbot rustbot added the A-documenting-cargo-itself Area: Cargo's documentation label Nov 26, 2025
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

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

I've noted schema questions in the tracking issue

View changes since this review

@epage epage added this pull request to the merge queue Nov 26, 2025
Merged via the queue into rust-lang:master with commit 3d20f19 Nov 26, 2025
26 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2025
@weihanglo weihanglo deleted the unit-started branch December 1, 2025 14:47
bors added a commit to rust-lang/rust that referenced this pull request Dec 3, 2025
Update cargo submodule

14 commits in 2a7c4960677971f88458b0f8b461a866836dff59..bd979347d814dfe03bba124165dbce9554d0b4d8
2025-11-25 19:58:07 +0000 to 2025-12-02 16:03:50 +0000
- fix(completion): Put host-tuple before actual tuples (rust-lang/cargo#16327)
- fix(lints): use plural form correctly (rust-lang/cargo#16324)
- fix(completions): include `all` in `cargo tree --target` candidates (rust-lang/cargo#16322)
- fix(lints): show lint error number (rust-lang/cargo#16320)
- chore(deps): update compatible (rust-lang/cargo#16318)
- chore(deps): update crate-ci/typos action to v1.40.0 (rust-lang/cargo#16316)
- Do not lock the artifact-dir for check builds + fix uplifting (rust-lang/cargo#16307)
- Properly validate crate names in `cargo install` (rust-lang/cargo#16314)
- Support --filter-platform=host for cargo metadata rust-lang/cargo#9423 (rust-lang/cargo#16312)
- Update to mdbook 0.5 (rust-lang/cargo#16292)
- refactor(clean): Better divide old / new layout (rust-lang/cargo#16304)
- update: silent failure on non-matching package specs with --breaking (rust-lang/cargo#16276)
- fix(log): break timing-info message to multiple (rust-lang/cargo#16303)
- fix(clean): Clean hosts builds with new layout (rust-lang/cargo#16300)
@rustbot rustbot added this to the 1.93.0 milestone Dec 3, 2025
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 A-documenting-cargo-itself Area: Cargo's documentation A-rebuild-detection Area: rebuild detection and fingerprinting A-timings Area: timings Z-build-analysis Nightly: build-analysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants