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

Document and improve (a lot) lintcheck --perf #14194

Merged
merged 4 commits into from
Mar 23, 2025

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Feb 10, 2025

In #14116 we added a benchmarking option for Lintcheck, this commit adds a new chapter to the book AND improves that option into a more usable state.

It's recommended to review one commit at a time.

  • Document how to benchmark with lintcheck --perf

  • Several improvements on lintcheck perf (desc.)

    • Now lintcheck perf deletes target directory after benchmarking,
      benchmarking with a cache isn't very useful or telling of any
      precise outcome.

    • Support for benchmarking several times without having to do
      a cargo clean.

    • Compress perf.data

changelog: none

Introducing a new chapter to the book, known as "Benchmarking Clippy".
It explains the benchmarking capabilities of lintcheck --perf
and gives a concrete example on how benchmark and compare a PR with
master
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2025

r? @flip1995

rustbot has assigned @flip1995.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 10, 2025
@blyxyas blyxyas changed the title book bench Document and improve (a lot) lintcheck --perf Feb 10, 2025
- Now lintcheck perf deletes target directory after benchmarking,
benchmarking with a cache isn't very useful or telling of any
precise outcome.

- Support for benchmarking several times without having to do
a cargo clean. Now we can benchmark a PR and master (or a single
change in the same commit) without having to move the perf.data files
into an external directory.

- Compress perf.data to allow for allowing multiple stacks and
occupy much less space
@samueltardieu
Copy link
Contributor

samueltardieu commented Feb 11, 2025

Maybe we should integrate this into the CI as well. If this is costly (I haven't had a chance to try it yet), we may even be able to watch the comments and react to certain commands, as we would do with a bot.

@flip1995
Copy link
Member

r? @Alexendoo

I won't get to review this any time soon. And I think, Alex is the better reviewer for this anyway.


The first `perf.data` will not have any numbers appended, but any subsequent
benchmark will be written to `perf.data.number` with a number growing for 0.
All benchmarks are compressed so that you can
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the end of this sentence is missing! :)

cmd.args(&[
"record",
"-e",
"instructions", // Only count instructions
"-g", // Enable call-graph, useful for flamegraphs and produces richer reports
"--quiet", // Do not tamper with lintcheck's normal output
"--compression-level=22",
Copy link
Member

Choose a reason for hiding this comment

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

Does this not slow down the capture? zstd 22 is pretty slow

cmd.args(&[
"record",
"-e",
"instructions", // Only count instructions
"-g", // Enable call-graph, useful for flamegraphs and produces richer reports
"--quiet", // Do not tamper with lintcheck's normal output
"--compression-level=22",
"--freq=97", // Slow down program to capture all events
Copy link
Member

Choose a reason for hiding this comment

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

This reduces the sampling frequency considerably meaning fewer captured events

There is no way to capture all the events with perf record as it is a sampling profiler

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmmm I was under the impression that perf would throttle down the program to match the frequency, like it's said in the man page.

      -F, --freq=
           Profile at this frequency. Use max to use the currently maximum
           allowed frequency, i.e. the value in the
           kernel.perf_event_max_sample_rate sysctl. Will throttle down to the
           currently maximum allowed frequency. See --strict-freq.

       --strict-freq
           Fail if the specified frequency can’t be used.

I'm not sure what's the solution, 4000 (the default frequency) loses a lot of the data in my machine, but I'm sure that other machines can handle it fine. (And the same would happen with any other frequency)

Maybe adding a --perf --frequency=<integer> would be the best approach, or an environment variable? What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

It means that the sampling frequency will be clamped to the value of sysctl kernel.perf_event_max_sample_rate, or be an error if --strict-freq is passed

If an reproducible count is desired you would need to use something like cachegrind instead of a sampling profiler

@blyxyas
Copy link
Member Author

blyxyas commented Mar 15, 2025

I've changed the frequency to 3000, as its something that my PC can handle and I think I will be one of the people that most use does of lintcheck --perf. The current state of the feature is very primitive (although technically usable) so I'd love to just get this QOL improvements out of the door.

@Alexendoo Alexendoo added this pull request to the merge queue Mar 23, 2025
@Alexendoo
Copy link
Member

For a follow up, what works well with perf is going to vary by device so it's probably worth having them passed in rather lintcheck having its own defaults

Merged via the queue into rust-lang:master with commit c033a4c Mar 23, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants