在分析 Python 脚本时,通过 percall 对 cProfile 输出进行排序

我用的是 python -m cProfile -s calls myscript.py

python -m cProfile -s percall myscript.py不工作。

Python 文档说“在 Stats 文档中查找有效的排序值”: http://docs.python.org/library/profile.html#module-cProfile,我找不到它。

56545 次浏览

-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