-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add documentation about profiling and performance analysis #5597
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f2fc7cf
Add documentation about profiling and performance analysis
DanielNoord 2eb384d
Update doc/development_guide/profiling.rst
DanielNoord 223b8af
Update doc/development_guide/profiling.rst
DanielNoord a4ec4ad
Added new section
DanielNoord 627ebda
Merge branch 'profiler-docs' of https://github.com/DanielNoord/pylintβ¦
DanielNoord e593e61
Fix layout
DanielNoord c784cce
Add visualization section
DanielNoord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ Development | |
|
|
||
| contribute | ||
| testing | ||
| profiling | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| .. -*- coding: utf-8 -*- | ||
| .. _profiling: | ||
|
|
||
| =================================== | ||
| Profiling and performance analysis | ||
| =================================== | ||
|
|
||
| Performance analysis for Pylint | ||
| ------------------------------- | ||
|
|
||
| To analysis the performance of Pylint we recommend to use the ``cProfile`` module | ||
| from ``stdlib``. Together with the ``pstats`` module this should give you all the tools | ||
| you need to profile a Pylint run and see which functions take how long to run. | ||
|
|
||
| The documentation for both modules can be found at cProfile_. | ||
|
|
||
| To profile a run of Pylint over itself you can use the following code and run it from the base directory. | ||
| It will store the profiling data in ``./profiler_stats``:: | ||
|
|
||
| import cProfile | ||
| import pstats | ||
| import sys | ||
| from pstats import SortKey | ||
|
|
||
| sys.argv = ["pylint", "pylint"] | ||
| cProfile.run("from pylint import __main__", "stats") | ||
|
|
||
| with open("profiler_stats", "w", encoding="utf-8") as file: | ||
| stats = pstats.Stats("stats", stream=file) | ||
| stats.print_stats() | ||
DanielNoord marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| You can also interact with the stats object by sorting or restricting the output. | ||
| For example, to only print functions from the ``pylint`` module and sort by cumulative time you could | ||
| use:: | ||
|
|
||
| import cProfile | ||
| import pstats | ||
| import sys | ||
| from pstats import SortKey | ||
|
|
||
| sys.argv = ["pylint", "pylint"] | ||
| cProfile.run("from pylint import __main__", "stats") | ||
|
|
||
| with open("profiler_stats", "w", encoding="utf-8") as file: | ||
| stats = pstats.Stats("stats", stream=file) | ||
| stats.sort_stats("cumtime") | ||
| stats.print_stats("pylint/pylint") | ||
|
|
||
| Lastly, the profile a run over your own module or code you can use:: | ||
DanielNoord marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import cProfile | ||
| import pstats | ||
| import sys | ||
| from pstats import SortKey | ||
|
|
||
| sys.argv = ["pylint", "your_dir/your_file"] | ||
| cProfile.run("from pylint import __main__", "stats") | ||
|
|
||
| with open("profiler_stats", "w", encoding="utf-8") as file: | ||
| stats = pstats.Stats("stats", stream=file) | ||
| stats.print_stats() | ||
|
|
||
| The documentation of the ``pstats`` module discusses other possibilites to interact with | ||
| the profiling output. | ||
|
|
||
|
|
||
| .. _cProfile: https://docs.python.org/3/library/profile.html | ||
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.
Uh oh!
There was an error while loading. Please reload this page.