Skip to content

Add script for profiling self check (Linux only) #19322

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

Merged
merged 2 commits into from
Jun 22, 2025
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 21, 2025

The script compiles mypy and profiles self check using the 'perf' profiler.

Example of how to use this:

$ python misc/profile_self_check.py
... [will take several minutes]

CPU profile collected. You can now analyze the profile:
  perf report -i mypy.profile.tmpdir/perf.data

The script compiles mypy and profiles self check using the 'perf'
profiler.

Example of how to use this:
```
$ python misc/profile_self_check.py
... [will take several minutes]

CPU profile collected. You can now analyze the profile:
  perf report -i mypy.profile.tmpdir/perf.data
```
@JukkaL JukkaL requested a review from ilevkivskyi June 21, 2025 15:34
Comment on lines 71 to 75
try:
subprocess.run(["perf", "-h"], capture_output=True)
except subprocess.CalledProcessError:
print("error: The 'perf' profiler is not installed")
sys.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should catch FileNotFoundError to handle perf not being found.

Comment on lines 77 to 81
try:
subprocess.run(["clang", "--version"], capture_output=True)
except subprocess.CalledProcessError:
print("error: The clang compiler is not installed")
sys.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

- The tool prints a command that can be used to analyze the profile afterwards
You may need to adjust kernel parameters temporarily, e.g. this (note that this has security
impliciations):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
impliciations):
implications):

Comment on lines 106 to 108
target_dir = "."

target_dir = "mypy.profile.tmpdir"
Copy link
Collaborator

@brianschubert brianschubert Jun 21, 2025

Choose a reason for hiding this comment

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

this looks off?

JukkaL added a commit that referenced this pull request Jun 21, 2025
This speeds up self check by about 1.5% on my computer, according to
`perf_compare.py`:
```
...
=== Results ===

master                    4.264s (0.0%) | stdev 0.024s 
HEAD                      4.201s (-1.5%) | stdev 0.030s 
```
I noticed this bottleneck when I was looking at a CPU profile generated
using the script from #19322.
@JukkaL JukkaL merged commit dc031c9 into master Jun 22, 2025
13 checks passed
@JukkaL JukkaL deleted the profile-self-script branch June 22, 2025 10:13
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