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

feat(cli): Allow logging to chrome traces #13399

Merged
merged 4 commits into from Mar 5, 2024
Merged

Conversation

epage
Copy link
Contributor

@epage epage commented Feb 5, 2024

What does this PR try to resolve?

The time from executing cargo to executing rustc is 230 ms. I wonder if there’s scope for caching whatever expensive computations cargo is doing here.

Source: https://davidlattimore.github.io/working-on-rust-iteration-time.html

This made me curious where the time was going. I've been meaning to try out tracing-chrome for a while and this gave me the opportunity.

This adds CARGO_LOG_PROFILE=<bool> and CARGO_LOG_PROFILE_CAPTURE_ARGS=<bool> for enabling and controlling these trace files. These are perma-unstable env variables.

Traces can be viewed at https://ui.perfetto.dev or chrome://tracing.

Example: no-op cargo check run on cargo-nextest:

image

TODO

How should we test and review this PR?

I looked in config/ and didn't see a env variable parser to reuse (get_cv_with_env is too specialized).

Additional information

In past projects, I've been able to use features like this to better understand code bases, bugs, etc. Hopefully this can evolve to help on-board people one day.

Most of the implementation was inspired by https://github.com/arxanas/git-branchless/blob/2923924dfbff07faa61d50771b6604cb18e64bc8/git-branchless-invoke/src/lib.rs#L55

tracing-chrome hasn't received updates recently, but it is also fairly quiet on Issues and PRs, so this might just be "maturity". It does have over a million downloads. It also is only enabled if explicitly opted into.

rustup added trace visualization in rust-lang/rustup#3287 using open telemetry but it is behind a feature flag and and requires running a server to receive the traces.

@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2024

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-dependency-resolution Area: dependency resolution and the resolver A-features2 Area: issues specifically related to the v2 feature resolver A-lockfile Area: Cargo.lock issues A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 5, 2024
@epage epage force-pushed the timing branch 2 times, most recently from 1736c61 to a8b6087 Compare February 5, 2024 20:46
@weihanglo
Copy link
Member

What's the difference between tracing-chrome and samply, and maybe other old school dtrace flamgraph approaches?

@epage epage force-pushed the timing branch 2 times, most recently from 58d9112 to 8ff0399 Compare February 5, 2024 20:55
@epage
Copy link
Contributor Author

epage commented Feb 5, 2024

What's the difference between tracing-chrome and samply, and maybe other old school dtrace flamgraph approaches?

This builds on tracing

  • Limited to what you trace
  • But doesn't require any other special binary setup
  • But can show argument values and other information
  • The new instrument calls would hopefully improve the overall quality of our tracing

Overall, I'd say this is a lot more approachable solution for users asking the question "where is my build time going?", like those using --timings or Ztime-passes

@arxanas
Copy link

arxanas commented Feb 6, 2024

Incidentally, cargo was a hotspot when I measured it a while back, as per https://lobste.rs/s/ktyp2q/improving_incremental_test_times_rust#c_ukhulp

src/bin/cargo/main.rs Outdated Show resolved Hide resolved
src/bin/cargo/main.rs Outdated Show resolved Hide resolved
src/bin/cargo/main.rs Show resolved Hide resolved
Comment on lines 307 to 308
#[tracing::instrument(skip_all)]
fn init_git(config: &Config) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aside: @Byron do you know if there should be or will be an equivalent to this in gitoxide? In the PR description is a trace that shows that this operation is 20% of the no-op cargo check time. Wondering if this is something that is worth hacking around or if its a "this will go away with git2".

Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting case as its unclear to me how much 20% actually represent in absolute terms of time.
With that said, I looked at what init_git is doing and I was surprised it takes time at all - it felt like it's loading some code dynamically (which is probably wrong).

gitoxide isn't comparable with git2 as there are no globals, and everything is lazy, so I'd guess that the timing is going to be more favourable. For one, there is no equivalent to init_git - configuration is done only when opening the repository.

I hope that helps.

@bors
Copy link
Collaborator

bors commented Feb 20, 2024

☔ The latest upstream changes (presumably #13409) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added A-build-scripts Area: build.rs scripts A-cache-messages Area: caching of compiler messages A-documenting-cargo-itself Area: Cargo's documentation labels Mar 5, 2024
@rustbot rustbot added the A-rebuild-detection Area: rebuild detection and fingerprinting label Mar 5, 2024
@epage epage marked this pull request as ready for review March 5, 2024 16:19
src/cargo/core/compiler/fingerprint/mod.rs Show resolved Hide resolved
src/cargo/ops/resolve.rs Show resolved Hide resolved
src/cargo/core/global_cache_tracker.rs Show resolved Hide resolved
src/doc/contrib/src/tests/profiling.md Show resolved Hide resolved
epage added a commit to epage/cargo that referenced this pull request Mar 5, 2024
epage added a commit to epage/cargo that referenced this pull request Mar 5, 2024
bors added a commit that referenced this pull request Mar 5, 2024
fix(log): Trace parameters to align with profile

This is a follow up to #13532 and prep for #13399
@weihanglo
Copy link
Member

@bors r+

Thanks and really looking forward to this!

@bors
Copy link
Collaborator

bors commented Mar 5, 2024

📌 Commit 6d8708a has been approved by weihanglo

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 Mar 5, 2024
@bors
Copy link
Collaborator

bors commented Mar 5, 2024

⌛ Testing commit 6d8708a with merge 00b9882...

@bors
Copy link
Collaborator

bors commented Mar 5, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 00b9882 to master...

@bors bors merged commit 00b9882 into rust-lang:master Mar 5, 2024
23 checks passed
@epage epage deleted the timing branch March 5, 2024 20:54
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 6, 2024
Update cargo

11 commits in f772ec0224d3755ce52ac5128a80319fb2eb45d0..c3c417b85e01a1de1633317fa55e4f1a31e346d4
2024-03-01 22:57:35 +0000 to 2024-03-06 01:16:08 +0000
- fix(rustdoc-map): dedup `--extern-html-too-url` for same unit (rust-lang/cargo#13544)
- test: Add test for packaging a public dependency (rust-lang/cargo#13536)
- doc: Edits for git/path dependency sections (rust-lang/cargo#13341)
- feat(cli): Allow logging to chrome traces (rust-lang/cargo#13399)
- fix(log): Trace parameters to align with profile (rust-lang/cargo#13538)
- fix(toml): Don't warn on unset Edition if only 2015 is compatible (rust-lang/cargo#13533)
- fix(cli): Trace core cargo operations (rust-lang/cargo#13532)
- chore: update pulldown-cmark to 0.10.0 (rust-lang/cargo#13517)
- feat(add): Fallback to `rustc -v` when no MSRV is set (rust-lang/cargo#13516)
- chore(ci): Ensure lockfile is respected during MSRV testing (rust-lang/cargo#13523)
- feat: Use consistent colors when testing (rust-lang/cargo#13520)

r? ghost
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 7, 2024
Update cargo

14 commits in f772ec0224d3755ce52ac5128a80319fb2eb45d0..a4c63fe5388beaa09e5f91196c86addab0a03580
2024-03-01 22:57:35 +0000 to 2024-03-06 22:15:17 +0000
- fix(cli): Skip tracing-chrome for platforms without 64bit atomics (rust-lang/cargo#13551)
- chore: downgrade to openssl v1.1.1 (again) (rust-lang/cargo#13550)
- fix(cli): Add traces to clarify where time is going (rust-lang/cargo#13545)
- fix(rustdoc-map): dedup `--extern-html-too-url` for same unit (rust-lang/cargo#13544)
- test: Add test for packaging a public dependency (rust-lang/cargo#13536)
- doc: Edits for git/path dependency sections (rust-lang/cargo#13341)
- feat(cli): Allow logging to chrome traces (rust-lang/cargo#13399)
- fix(log): Trace parameters to align with profile (rust-lang/cargo#13538)
- fix(toml): Don't warn on unset Edition if only 2015 is compatible (rust-lang/cargo#13533)
- fix(cli): Trace core cargo operations (rust-lang/cargo#13532)
- chore: update pulldown-cmark to 0.10.0 (rust-lang/cargo#13517)
- feat(add): Fallback to `rustc -v` when no MSRV is set (rust-lang/cargo#13516)
- chore(ci): Ensure lockfile is respected during MSRV testing (rust-lang/cargo#13523)
- feat: Use consistent colors when testing (rust-lang/cargo#13520)
@rustbot rustbot added this to the 1.78.0 milestone Mar 7, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
Update cargo

14 commits in f772ec0224d3755ce52ac5128a80319fb2eb45d0..a4c63fe5388beaa09e5f91196c86addab0a03580
2024-03-01 22:57:35 +0000 to 2024-03-06 22:15:17 +0000
- fix(cli): Skip tracing-chrome for platforms without 64bit atomics (rust-lang/cargo#13551)
- chore: downgrade to openssl v1.1.1 (again) (rust-lang/cargo#13550)
- fix(cli): Add traces to clarify where time is going (rust-lang/cargo#13545)
- fix(rustdoc-map): dedup `--extern-html-too-url` for same unit (rust-lang/cargo#13544)
- test: Add test for packaging a public dependency (rust-lang/cargo#13536)
- doc: Edits for git/path dependency sections (rust-lang/cargo#13341)
- feat(cli): Allow logging to chrome traces (rust-lang/cargo#13399)
- fix(log): Trace parameters to align with profile (rust-lang/cargo#13538)
- fix(toml): Don't warn on unset Edition if only 2015 is compatible (rust-lang/cargo#13533)
- fix(cli): Trace core cargo operations (rust-lang/cargo#13532)
- chore: update pulldown-cmark to 0.10.0 (rust-lang/cargo#13517)
- feat(add): Fallback to `rustc -v` when no MSRV is set (rust-lang/cargo#13516)
- chore(ci): Ensure lockfile is respected during MSRV testing (rust-lang/cargo#13523)
- feat: Use consistent colors when testing (rust-lang/cargo#13520)
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Update cargo

14 commits in f772ec0224d3755ce52ac5128a80319fb2eb45d0..a4c63fe5388beaa09e5f91196c86addab0a03580
2024-03-01 22:57:35 +0000 to 2024-03-06 22:15:17 +0000
- fix(cli): Skip tracing-chrome for platforms without 64bit atomics (rust-lang/cargo#13551)
- chore: downgrade to openssl v1.1.1 (again) (rust-lang/cargo#13550)
- fix(cli): Add traces to clarify where time is going (rust-lang/cargo#13545)
- fix(rustdoc-map): dedup `--extern-html-too-url` for same unit (rust-lang/cargo#13544)
- test: Add test for packaging a public dependency (rust-lang/cargo#13536)
- doc: Edits for git/path dependency sections (rust-lang/cargo#13341)
- feat(cli): Allow logging to chrome traces (rust-lang/cargo#13399)
- fix(log): Trace parameters to align with profile (rust-lang/cargo#13538)
- fix(toml): Don't warn on unset Edition if only 2015 is compatible (rust-lang/cargo#13533)
- fix(cli): Trace core cargo operations (rust-lang/cargo#13532)
- chore: update pulldown-cmark to 0.10.0 (rust-lang/cargo#13517)
- feat(add): Fallback to `rustc -v` when no MSRV is set (rust-lang/cargo#13516)
- chore(ci): Ensure lockfile is respected during MSRV testing (rust-lang/cargo#13523)
- feat: Use consistent colors when testing (rust-lang/cargo#13520)
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-build-scripts Area: build.rs scripts A-cache-messages Area: caching of compiler messages A-cli Area: Command-line interface, option parsing, etc. A-configuration Area: cargo config files and env vars A-dependency-resolution Area: dependency resolution and the resolver A-documenting-cargo-itself Area: Cargo's documentation A-features2 Area: issues specifically related to the v2 feature resolver A-lockfile Area: Cargo.lock issues A-manifest Area: Cargo.toml issues A-rebuild-detection Area: rebuild detection and fingerprinting S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants