Repository navigation
bpo-29237: Create enum for pstats sorting options #5103
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
Changes from 1 commit
c28feaa
5553944
125bfda
d846ba7
9283cb7
259e0f9
6adc715
ef409c2
ad7a395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,20 +32,20 @@ | |
|
|
||
|
|
||
| class SortKey(str, Enum): | ||
| calls = 'calls' | ||
| ncalls = 'ncalls' | ||
| cumtime = 'cumtime' | ||
| cumulative = 'cumulative' | ||
| file = 'file' | ||
| filename = 'filename' | ||
| line = 'line' | ||
| module = 'module' | ||
| name = 'name' | ||
| nfl = 'nfl' | ||
| pcalls = 'pcalls' | ||
| stdname = 'stdname' | ||
| time = 'time' | ||
| tottime = 'tottime' | ||
| CALLS = 'calls' | ||
| NCALLS = 'ncalls' | ||
| CUMULATIVE = 'cumulative' | ||
| CUMTIME = 'cumtime' | ||
| MODULE = 'module' | ||
| FILE = 'file' | ||
| FILENAME = 'filename' | ||
| LINE = 'line' | ||
| NAME = 'name' | ||
| NFL = 'nfl' | ||
| PCALLS = 'pcalls' | ||
| STDNAME = 'stdname' | ||
| TIME = 'time' | ||
| TOTTIME = 'tottime' | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My initial understanding of this was flawed. Since we need to support the old string values we can't just have CUMTIME and CUMULATIVE map to "cumulative" because then "cumtime" is gone (unless we do extra work, which I see you did). What we need here is a The Enum should look like this: Operations like |
||
|
|
||
| class Stats: | ||
|
|
@@ -72,8 +72,8 @@ class Stats: | |
| arbitrary number of quoted strings or SortKey enum to select the sort | ||
| order. | ||
|
|
||
| For example sort_stats('time', 'name') or sort_stats(SortKey.time, | ||
| SortKey.name) sorts on the major key of 'internal function time', and on | ||
| For example sort_stats('time', 'name') or sort_stats(SortKey.TIME, | ||
| SortKey.NAME) sorts on the major key of 'internal function time', and on | ||
| the minor key of 'the name of the function'. Look at the two tables in | ||
| sort_stats() and get_sort_arg_defs(self) for more examples. | ||
|
|
||
|
|
@@ -177,20 +177,20 @@ def dump_stats(self, filename): | |
| # list the tuple indices and directions for sorting, | ||
| # along with some printable description | ||
| sort_arg_dict_default = { | ||
| SortKey.calls : (((1,-1), ), "call count"), | ||
| SortKey.ncalls : (((1,-1), ), "call count"), | ||
| SortKey.cumtime : (((3,-1), ), "cumulative time"), | ||
| SortKey.cumulative: (((3,-1), ), "cumulative time"), | ||
| SortKey.file : (((4, 1), ), "file name"), | ||
| SortKey.filename : (((4, 1), ), "file name"), | ||
| SortKey.line : (((5, 1), ), "line number"), | ||
| SortKey.module : (((4, 1), ), "file name"), | ||
| SortKey.name : (((6, 1), ), "function name"), | ||
| SortKey.nfl : (((6, 1),(4, 1),(5, 1),), "name/file/line"), | ||
| SortKey.pcalls : (((0,-1), ), "primitive call count"), | ||
| SortKey.stdname : (((7, 1), ), "standard name"), | ||
| SortKey.time : (((2,-1), ), "internal time"), | ||
| SortKey.tottime : (((2,-1), ), "internal time"), | ||
| SortKey.CALLS : (((1,-1), ), "call count"), | ||
| SortKey.NCALLS : (((1,-1), ), "call count"), | ||
| SortKey.CUMTIME : (((3,-1), ), "cumulative time"), | ||
| SortKey.CUMULATIVE: (((3,-1), ), "cumulative time"), | ||
| SortKey.FILE : (((4, 1), ), "file name"), | ||
| SortKey.FILENAME : (((4, 1), ), "file name"), | ||
| SortKey.LINE : (((5, 1), ), "line number"), | ||
| SortKey.MODULE : (((4, 1), ), "file name"), | ||
| SortKey.NAME : (((6, 1), ), "function name"), | ||
| SortKey.NFL : (((6, 1),(4, 1),(5, 1),), "name/file/line"), | ||
| SortKey.PCALLS : (((0,-1), ), "primitive call count"), | ||
| SortKey.STDNAME : (((7, 1), ), "standard name"), | ||
| SortKey.TIME : (((2,-1), ), "internal time"), | ||
| SortKey.TOTTIME : (((2,-1), ), "internal time"), | ||
| } | ||
|
|
||
| def get_sort_arg_defs(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello and thanks for the PR!
Here I would recomment keeping only the example with the enum, since it’s the way that we want to recommend.
To match the import style (see
import pstatsin the previous code block), the example would need to bep.sort_stats(pstats.SortKey.NAME)(assuming the upper-case fix asked by the other reviewer is done).I wonder if the enum should be defined on the Stats class, to make code shorter:
p.sort_stats(p.SortKey.NAME). Maybe worth asking on the ticket to get other people’s opinion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the import to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
pstatsmodule is all about stats processing, so there is no need to hideSortKeyinside theStatsclass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment. Re: 'Here I would recomment keeping only the example with the enum, since it’s the way that we want to recommend.' I could do that, but I have also received comment about having both example as the string argument is still valid. Showing only the enum would make the doc incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there is a need to also show an example with a string form, but not all code examples need both forms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mwidjaja
When you make the duplicate
SortKeys actually duplicates, please put the better name first -- something like: