Add script for profiling self check (Linux only)#19322
Merged
Conversation
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 ```
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) |
Collaborator
There was a problem hiding this comment.
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) |
misc/profile_self_check.py
Outdated
| - 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): |
Collaborator
There was a problem hiding this comment.
Suggested change
| impliciations): | |
| implications): |
misc/profile_self_check.py
Outdated
Comment on lines
+106
to
+108
| target_dir = "." | ||
|
|
||
| target_dir = "mypy.profile.tmpdir" |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The script compiles mypy and profiles self check using the 'perf' profiler.
Example of how to use this: