【问题标题】:How to source annotate python when using qcachegrind to process profilestats output使用 qcachegrind 处理 profilestats 输出时如何对 python 进行源注释
【发布时间】:2015-09-15 13:06:49
【问题描述】:

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

【问题讨论】:

  • 似乎profilestats 可能未在其输出中包含相关数据。您是否尝试过将分析输出保存为“Python 格式”并使用pyprof2calltree 进行转换?

标签: python python-2.7 profiling kcachegrind profilestats


【解决方案1】:

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

首先使用 cProfile 运行您的脚本

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

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

pyprof2calltree -k -i report.profile

顺便说一下,Python 2.7.10 和 qcachegrind 0.7.4 在 OSX 10.11 上通过 homebrew 安装

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-23
    • 2017-03-21
    • 1970-01-01
    • 2016-11-08
    • 2011-02-21
    • 1970-01-01
    • 2011-02-07
    • 2021-02-05
    相关资源
    最近更新 更多