Sort cProfile output by percall when profiling a Python script

PythonProfilingCprofile

Python Problem Overview


I'm using python -m cProfile -s calls myscript.py

python -m cProfile -s percall myscript.py does not work.

The Python documentation says "Look in the Stats documentation for valid sort values.": http://docs.python.org/library/profile.html#module-cProfile, which I cannot find.

Python Solutions


Solution 1 - Python

-s only uses the keys found under sort_stats.

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)

Here's an example

python -m cProfile -s tottime myscript.py

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrandon O'RourkeView Question on Stackoverflow
Solution 1 - PythonJoshua OlsonView Answer on Stackoverflow