跳转到主要内容

帮助可视化使用kcachegrind和qcachegrind从cProfile收集的配置文件数据

项目描述

概述

脚本,用于帮助使用kcachegrind图形调用树分析器可视化使用cProfile Python模块收集的配置文件数据。

这是一个对David Allouche等人所写的备受推崇的http://www.gnome.org/~johan/lsprofcalltree.py脚本的重新品牌化。它的目标是使其更容易分发(例如通过PyPI)并更像debian kcachegrind-converters包的脚本。最终目标是使其成为官方上游kdesdk包的一部分。

命令行用法

安装后,你应该在你的路径中有pyprof2calltree脚本

$ pyprof2calltree --help
usage: pyprof2calltree [-h] [-o output_file_path] [-i input_file_path] [-k]
                       [-r scriptfile [args ...]]

optional arguments:
  -h, --help            show this help message and exit
  -o output_file_path, --outfile output_file_path
                        Save calltree stats to <outfile>
  -i input_file_path, --infile input_file_path
                        Read Python stats from <infile>
  -k, --kcachegrind     Run the kcachegrind tool on the converted data
  -r scriptfile [args ...], --run-script scriptfile [args ...]
                        Name of the Python script to run to collect profiling
                        data

Python shell用法

pyprof2calltree最好在交互式Python shell中如默认shell中使用。例如,让我们来分析XML解析

>>> from xml.etree import ElementTree
>>> from cProfile import Profile
>>> xml_content = '<a>\n' + '\t<b/><c><d>text</d></c>\n' * 100 + '</a>'
>>> profiler = Profile()
>>> profiler.runctx(
...     "ElementTree.fromstring(xml_content)",
...     locals(), globals())

>>> from pyprof2calltree import convert, visualize
>>> visualize(profiler.getstats())                            # run kcachegrind
>>> convert(profiler.getstats(), 'profiling_results.kgrind')  # save for later

或者使用ipython

In [1]: %doctest_mode
Exception reporting mode: Plain
Doctest mode is: ON

>>> from xml.etree import ElementTree
>>> xml_content = '<a>\n' + '\t<b/><c><d>text</d></c>\n' * 100 + '</a>'
>>> %prun -D out.stats ElementTree.fromstring(xml_content)

*** Profile stats marshalled to file 'out.stats'

>>> from pyprof2calltree import convert, visualize
>>> visualize('out.stats')
>>> convert('out.stats', 'out.kgrind')

>>> results = %prun -r ElementTree.fromstring(xml_content)
>>> visualize(results)

变更日志

  • 1.4.5 - 2020-04-19:没有面向用户的更改 - 对测试的更改和移除已弃用的eggecutable

  • 1.4.4 - 2018-10-19:许多小的改进,放弃对EOL python版本的支持

  • 1.4.3 - 2017-07-28:Windows支持(修复is_installed检查 - #21)

  • 1.4.2 - 2017-07-19:没有功能或错误修复,只是澄清许可(#20)

  • 1.4.1 - 2017-05-20:没有功能或错误修复,只是测试分发(#17)

  • 1.4.0 - 2016-09-03:支持具有相同名称的多个函数,单位从毫秒到纳秒,增加了测试(#15)

  • 1.3.2 - 2014-07-05:错误修复:正确源文件路径(#12)

  • 1.3.1 - 2013-11-27:错误修复:Python 3上的损坏输出写入(#8)

  • 1.3.0 - 2013-11-19:qcachegrind支持

  • 1.2.0 - 2013-11-09:Python 3支持

  • 1.1.1 - 2013-09-25:各种错误修复

  • 1.1.0 - 2008-12-21:整合David Glick的转换修复

  • 1.0.3 - 2008-10-16:修复1.0版本中的拼写错误

  • 1.0 - 2008-10-16:以pyprof2calltree名称的初始发布

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源代码分发

pyprof2calltree-1.4.5.tar.gz (10.1 kB 查看散列

上传时间 源代码

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页