← Back to DAGDA | Support | Source: https://github.com/python/cpython/pull/5103/commits/6adc715471986efa6748f1489854f9c90203a86b
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
Remove 'file' argument
  • Loading branch information
mwidjaja committed Jan 26, 2018
commit 6adc715471986efa6748f1489854f9c90203a86b
4 changes: 2 additions & 2 deletions Doc/library/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ statistics for the top ten functions.

You might also try::

p.sort_stats(SortKey.FILE).print_stats('__init__')
p.sort_stats(SortKey.MODULE).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
Expand Down Expand Up @@ -421,7 +421,7 @@ Analysis of the profiler data is done using the :class:`~pstats.Stats` class.
the file names were the same) appear in the string order 20, 3 and 40.
In contrast, ``SortKey.NFL`` does a numeric compare of the line numbers.
In fact, ``sort_stats(SortKey.NFL)`` is the same as
``sort_stats(SortKey.NAME, SortKey.FILE, SortKey.LINE)``.
``sort_stats(SortKey.NAME, SortKey.MODULE, SortKey.LINE)``.

For backward-compatibility reasons, the numeric arguments ``-1``, ``0``,
``1``, and ``2`` are permitted. They are interpreted as ``'stdname'``,
Expand Down
3 changes: 1 addition & 2 deletions Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class SortKey(str, Enum):
CALLS = 'calls', 'ncalls'
CUMULATIVE = 'cumulative', 'cumtime'
MODULE = 'module', 'filename', 'file'
MODULE = 'module', 'filename'
LINE = 'line'
NAME = 'name'
NFL = 'nfl'
Expand Down Expand Up @@ -185,7 +185,6 @@ def dump_stats(self, filename):
"ncalls" : (((1,-1), ), "call count"),
"cumtime" : (((3,-1), ), "cumulative time"),
"cumulative": (((3,-1), ), "cumulative time"),
"file" : (((4, 1), ), "file name"),
"filename" : (((4, 1), ), "file name"),
"line" : (((5, 1), ), "line number"),
"module" : (((4, 1), ), "file name"),
Expand Down
16 changes: 10 additions & 6 deletions Lib/test/test_pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ def test_sort_stats_int(self):
self.stats.sort_arg_dict_default[arg_str][-1])

def test_sort_stats_string(self):
for sort_name in ('calls', 'ncalls', 'cumtime', 'cumulative', 'file',
for sort_name in ['calls', 'ncalls', 'cumtime', 'cumulative',
'filename', 'line', 'module', 'name', 'nfl', 'pcalls',
'stdname', 'time', 'tottime'):
# 'file' sorting criteria will not work because it creates
# ambiquity with 'filename'
if sort_name == 'file':
continue
'stdname', 'time', 'tottime']:
self.stats.sort_stats(sort_name)
self.assertEqual(self.stats.sort_type,
self.stats.sort_arg_dict_default[sort_name][-1])

def test_sort_stats_partial(self):
sortkey = 'filename'
for sort_name in ['f', 'fi', 'fil', 'file', 'filen', 'filena',
'filenam', 'filename']:
self.stats.sort_stats(sort_name)
self.assertEqual(self.stats.sort_type,
self.stats.sort_arg_dict_default[sortkey][-1])

def test_sort_stats_enum(self):
for member in SortKey:
self.stats.sort_stats(member)
Expand Down