Skip to content

bpo-34861: Make cumtime the default sorting key for cProfile #31929

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 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 12 additions & 11 deletions Doc/library/profile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,23 @@ your system.)
The above action would run :func:`re.compile` and print profile results like
the following::

197 function calls (192 primitive calls) in 0.002 seconds
214 function calls (207 primitive calls) in 0.002 seconds

Ordered by: standard name
Ordered by: cumulative time

ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.002 0.002 {built-in method builtins.exec}
1 0.000 0.000 0.001 0.001 <string>:1(<module>)
1 0.000 0.000 0.001 0.001 re.py:212(compile)
1 0.000 0.000 0.001 0.001 re.py:268(_compile)
1 0.000 0.000 0.000 0.000 sre_compile.py:172(_compile_charset)
1 0.000 0.000 0.000 0.000 sre_compile.py:201(_optimize_charset)
4 0.000 0.000 0.000 0.000 sre_compile.py:25(_identityfunction)
3/1 0.000 0.000 0.000 0.000 sre_compile.py:33(_compile)

The first line indicates that 197 calls were monitored. Of those calls, 192
1 0.000 0.000 0.001 0.001 re.py:250(compile)
1 0.000 0.000 0.001 0.001 re.py:289(_compile)
1 0.000 0.000 0.000 0.000 sre_compile.py:759(compile)
1 0.000 0.000 0.000 0.000 sre_parse.py:937(parse)
1 0.000 0.000 0.000 0.000 sre_compile.py:598(_code)
1 0.000 0.000 0.000 0.000 sre_parse.py:435(_parse_sub)

The first line indicates that 214 calls were monitored. Of those calls, 207
were :dfn:`primitive`, meaning that the call was not induced via recursion. The
next line: ``Ordered by: standard name``, indicates that the text string in the
next line: ``Ordered by: cumulative name``, indicates that the text string in the
far right column was used to sort the output. The column headings include:

ncalls
Expand Down
2 changes: 1 addition & 1 deletion Lib/cProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def main():
help="Save stats to <outfile>", default=None)
parser.add_option('-s', '--sort', dest="sort",
help="Sort order when printing to stdout, based on pstats.Stats class",
default=-1,
default=2,
choices=sorted(pstats.Stats.sort_arg_dict_default))
parser.add_option('-m', dest="module", action="store_true",
help="Profile a library module", default=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made cumtime the default sorting key for cProfile