KEMBAR78
Add script for profiling self check (Linux only) by JukkaL · Pull Request #19322 · python/mypy · GitHub
Skip to content

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
Member

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
Member

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
Member

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
Member

@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