如何聚合热点(分析器)结果并在 kcachegrind 中查看

Posted

技术标签:

【中文标题】如何聚合热点(分析器)结果并在 kcachegrind 中查看【英文标题】:How to aggregate hotshot ( profiler ) results and view it in kcachegrind 【发布时间】:2012-03-26 15:55:47 【问题描述】:

我正在使用 hotshot 来分析我的 Python 程序, 有什么方法可以汇总配置文件并在 Kcachegrind 中查看总结果?

经过一些研究,我使用 pstats 以下面给出的方式聚合配置文件,并使用 pyprof2calltree 将结果转换为 kcachegrind 格式

>>> pf = pstats.Stats("profile1.prof")
>>> p2 = pf.add("profile2.prof")
>>> p2.dump_stats("aggregated.prof")

pyprof2calltree 给了我这样的错误。

  File "/usr/local/bin/pyprof2calltree", line 9, in <module>
    load_entry_point('pyprof2calltree==1.1.0', 'console_scripts', 'pyprof2calltree')()
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 240, in main
    kg.output(file(outfile, 'wb'))
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 106, in output
    self._entry(entry)
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 167, in _entry
    self._subentry(lineno, subentry, call_info)
  File "/usr/local/lib/python2.7/dist-packages/pyprof2calltree.py", line 178, in _subentry
    print >> out_file, 'calls=%d %d' % (call_info[0], co_firstlineno)
TypeError: 'int' object is not subscriptable

我在这里做错了什么还是有其他方法可以做到这一点?

【问题讨论】:

【参考方案1】:

我过去也遇到过同样的问题,最后我放弃了 kcachegrind。当我最终得到结果时,它并没有我希望的那么有用。如果您只想以图形方式显示配置文件,那么我建议您查看gprof2dot。它使用 graphviz 来绘制结果,是迄今为止我发现的最好的工具。

【讨论】:

【参考方案2】:

你看过runsnakerun吗?在我看来,它是 python 的最佳分析器,您不必使用 pyprof2calltree 来查看结果。 http://www.vrplumber.com/programming/runsnakerun/

【讨论】:

以上是关于如何聚合热点(分析器)结果并在 kcachegrind 中查看的主要内容,如果未能解决你的问题,请参考以下文章

Mongoose 聚合返回空结果并在 mongo 控制台中工作 [重复]

Mongoose 聚合返回空结果并在 mongo 控制台中工作 [重复]

如何汇总英特尔放大器批处理结果?

数据分析—Pandas 中的分组聚合Groupby 高阶操作

ElasticSearch--aggregations聚合分析

4.elasticsearch聚合分析