26.5. 热点—高性能日志记录探查器

2.2 版中的新Function。

该模块为_hotshot C 模块提供了更好的接口。 Hotshot 替代了现有的profile模块。由于它主要是用 C 编写的,因此与现有的profile模块相比,它对性能的影响应小得多。

Note

hotshot模块专注于最大程度地减少性能分析过程中的开销,但要花费较长的数据后处理时间。对于一般用法,建议改用cProfilehotshot未得到维护,将来可能会从标准库中删除。

在版本 2.5 中进行了更改:结果应该比过去更有意义:计时核心包含一个严重的错误。

Note

hotshot分析器尚不适用于线程。如果可能的话,使用非线程脚本在您想要测量的代码上运行探查器非常有用。

26.5.1. 配置文件对象

概要文件对象具有以下方法:

26.5.2. 使用热门数据

2.2 版中的新Function。

该模块将热点分析数据加载到标准的pstats Stats 对象中。

See also

26.5.3. 用法示例

请注意,此示例运行 Python“基准”分析。运行可能需要一些时间,并且会产生较大的输出文件。

>>> import hotshot, hotshot.stats, test.pystone
>>> prof = hotshot.Profile("stones.prof")
>>> benchtime, stones = prof.runcall(test.pystone.pystones)
>>> prof.close()
>>> stats = hotshot.stats.load("stones.prof")
>>> stats.strip_dirs()
>>> stats.sort_stats('time', 'calls')
>>> stats.print_stats(20)
         850004 function calls in 10.090 CPU seconds

   Ordered by: internal time, call count

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    3.295    3.295   10.090   10.090 pystone.py:79(Proc0)
   150000    1.315    0.000    1.315    0.000 pystone.py:203(Proc7)
    50000    1.313    0.000    1.463    0.000 pystone.py:229(Func2)
 .
 .
 .
首页