sort_stats(*keys)
This method modifies the Stats
object by sorting it according to the supplied criteria. The argument is typically a string identifying the basis of a sort (example: 'time'
or 'name'
).
When more than one key is provided, then additional keys are used as secondary criteria when there is equality in all keys selected before them. For example, sort_stats('name', 'file')
will sort all the entries according to their function name, and resolve all ties (identical function names) by sorting by file name.
Abbreviations can be used for any key names, as long as the abbreviation is unambiguous. The following are the keys currently defined:
Valid Arg | Meaning |
---|---|
'calls' | call count |
'cumulative' | cumulative time |
'cumtime' | cumulative time |
'file' | file name |
'filename' | file name |
'module' | file name |
'ncalls' | call count |
'pcalls' | primitive call count |
'line' | line number |
'name' | function name |
'nfl' | name/file/line |
'stdname' | standard name |
'time' | internal time |
'tottime' | internal time |
Note that all sorts on statistics are in descending order (placing most time consuming items first), where as name, file, and line number searches are in ascending order (alphabetical). The subtle distinction between 'nfl'
and 'stdname'
is that the standard name is a sort of the name as printed, which means that the embedded line numbers get compared in an odd way. For example, lines 3, 20, and 40 would (if the file names were the same) appear in the string order 20, 3 and 40. In contrast, 'nfl'
does a numeric compare of the line numbers. In fact, sort_stats('nfl')
is the same as sort_stats('name', 'file',
'line')
.
For backward-compatibility reasons, the numeric arguments -1
, 0
, 1
, and 2
are permitted. They are interpreted as 'stdname'
, 'calls'
, 'time'
, and 'cumulative'
respectively. If this old style format (numeric) is used, only one sort key (the numeric key) will be used, and additional arguments will be silently ignored.
Please login to continue.