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

Bra*_*rke 61 python profiling 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,我找不到.

Jos*_*son 83

-s仅使用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)
Run Code Online (Sandbox Code Playgroud)

这是一个例子

python -m cProfile -s tottime myscript.py
Run Code Online (Sandbox Code Playgroud)

  • 只是为了清理它,对于像我这样的新手,你不要使用引号:)所以按方法花费的时间对方法进行排序的例子是"python -m cProfile -s tottime myscript.py" (8认同)
  • 使用引号(至少在bash中)没有错,是吗?报价由bash命令预处理吃掉.. (4认同)
  • 就windows而言,不能使用引号。另请注意 - 按时间排序和 tottime 是一回事。 (2认同)