← Back to DAGDA | Support | Source: https://github.com/python/cpython/pull/5103/commits/d846ba70c371bbc485f323e006ed2be4b8e0d5d1
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Further Doc updates/changes
  • Loading branch information
mwidjaja committed Jan 26, 2018
commit d846ba70c371bbc485f323e006ed2be4b8e0d5d1
4 changes: 0 additions & 4 deletions Doc/library/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ The first call will actually sort the list by function name, and the second call
will print out the statistics. The following are some interesting calls to
experiment with::

p.sort_stats('cumulative').print_stats(10)
p.sort_stats(SortKey.cumulative).print_stats(10)

This sorts the profile by cumulative time in a function, and then only prints
Expand All @@ -165,22 +164,19 @@ taking time, the above line is what you would use.
If you were looking to see what functions were looping a lot, and taking a lot
of time, you would do::

p.sort_stats('time').print_stats(10)
p.sort_stats(SortKey.time).print_stats(10)

to sort according to time spent within each function, and then print the
statistics for the top ten functions.

You might also try::

p.sort_stats('file').print_stats('__init__')
p.sort_stats(SortKey.file).print_stats('__init__')

This will sort all the statistics by file name, and then print out statistics
for only the class init methods (since they are spelled with ``__init__`` in
them). As one final example, you could try::

p.sort_stats('time', 'cumulative').print_stats(.5, 'init')
p.sort_stats(SortKey.time, SortKey.cumulative).print_stats(.5, 'init')

This line sorts statistics with a primary key of time, and a secondary key of
Expand Down
5 changes: 4 additions & 1 deletion Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SortKey(str, Enum):
CALLS = 'calls'
NCALLS = 'ncalls'
CUMULATIVE = 'cumulative'
CUMTIME = 'cumtime'
CUMTIME = 'cumulative'
MODULE = 'module'
FILE = 'file'
FILENAME = 'filename'
Expand Down Expand Up @@ -230,6 +230,9 @@ def sort_stats(self, *field):
if isinstance(field[0], SortKey):
sort_arg_defs = self.sort_arg_dict_default
else:
for word in field:
if isinstance(word, str) and word == 'cumtime':
word = 'cumulative'
sort_arg_defs = self.get_sort_arg_defs()

sort_tuple = ()
Expand Down