我正在使用Python的热门分析器:http://docs.python.org/2/library/hotshot.html
它显示了如何打印统计数据:
stats.print_stats(20)
Run Code Online (Sandbox Code Playgroud)
但是我怎么把它变成文件呢?我不知道如何获取信息,因此我可以使用write()将其写入文件.
编辑:
我喜欢与以这种方式打印时相同的易读性结果:
stats = hotshot.stats.load("stones.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
Run Code Online (Sandbox Code Playgroud)
所以它看起来像这样:
ncalls tottime percall cumtime percall filename:lineno(function)
1 3.295 3.295 10.090 10.090 pystone.py:79(Proc0)
Run Code Online (Sandbox Code Playgroud)
(所以当我打开stones.prof时它看起来不像)
我正在尝试对一个相当复杂的Python程序进行一些高级概要分析。但是,使用cProfile时,几乎所有时间的度量单位为:
{method 'enable' of '_lsProf.Profiler' objects}
如果我分析整个程序python -m cProfile ...以及在Python代码(使用profile.enable()/.disable()/.create_stats...)中进行性能分析时,都会发生这种情况
有任何指向我可能做错事情的指示吗?