使用qcachegrind处理profilestats输出时如何获取注释python

时间:2015-06-29 06:49:36

标签: python python-2.7 profiling kcachegrind profilestats

Kcachegrind是一个很棒的实用工具,可以在分析代码时直观地表示热点到源代码行级别。在微优化我的C ++代码库时,我发现它非常有用。 对于我最新的python项目,我开始使用Kcachegrind来处理profilestats的输出。 Kcachegrind是一个仅限Linux的实用程序,但可以使用各种非官方端口,我使用的是qcachegrind。 通常它在很大程度上起作用并且对于大多数问题都是足够的,除了我很难获得源注释工作。

在源标签上,我遇到了熟悉的来源缺失消息

There is no source available for the following function:
   'main C:\Projects\module\src\source.py:397'
This is because no debug information is present
Recompile source and redo the profile run.
The function is located in the ELF Object:
  '(unknown)'

使用选项

Settings -> Configure -> Source Annotation 

并添加源基目录无效。

我觉得该实用程序想要一个与Python无关的ELF对象。在这方面的任何帮助都是有用的。

相关信息:

  • Python 2.7
  • profilestats(2.0)
  • QCachegrind 0.7.4
  • Windows 2012R2

1 个答案:

答案 0 :(得分:1)

我第二次@taleniat发表评论。我是OSX用户。我在使qcachegrind工作时遇到了一些麻烦所以我最终使用了pyprof2calltree并且它运行良好,包括源代码选项卡。 YMMV。

首先使用cProfile运行脚本

python -m cProfile -o report.profile report.py

然后你可以使用pyprof2calltree来启动qcachegrind(不需要中间转换)。

pyprof2calltree -k -i report.profile

顺便说一下,在OSX 10.11上通过自制软件安装Python 2.7.10和qcachegrind 0.7.4