使用kCacheGrind和qCacheGrind帮助可视化来自cprofile的剖面数据

pyprof2calltree的Python项目详细描述


概述

帮助可视化使用cProfile收集的分析数据的脚本 带有kcachegrindscreenshots)图形化调用树的Python模块 分析员

这是尊者的更名 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中使用,例如 默认外壳。例如,让我们分析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.4 - 2018-10-19: Numerous small improvements, drop support for EOL python versions
  • 1.4.3 - 2017-07-28: Windows support (fixed is_installed check - #21)
  • 1.4.2 - 2017-07-19: No feature or bug fixes, just license clarification (#20)
  • 1.4.1 - 2017-05-20: No feature or bug fixes, just test distribution (#17)
  • 1.4.0 - 2016-09-03: Support multiple functions with the same name, tick unit from millis to nanos, tests added (#15)
  • 1.3.2 - 2014-07-05: Bugfix: correct source file paths (#12)
  • 1.3.1 - 2013-11-27: Bugfix for broken output writing on Python 3 (#8)
  • 1.3.0 - 2013-11-19: qcachegrind support
  • 1.2.0 - 2013-11-09: Python 3 support
  • 1.1.1 - 2013-09-25: Miscellaneous bugfixes
  • 1.1.0 - 2008-12-21: integrate fix in conversion by David Glick
  • 1.0.3 - 2008-10-16: fix typos in 1.0 release
  • 1.0 - 2008-10-16: initial release under the pyprof2calltree name

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java GridBagLayout不填充区域   java Memozied Fibonacci未运行与常规Fibonacci解决方案   Java Web启动未启动问题   Java中异常和if-then的区别   java从命令提示符运行批处理文件获取错误   socket在Java中验证SSL证书的公共名称   如何在JAVA中检查字符串数组中的相等字   用java语言将音频文件转换成文本文件的语音识别   java为什么foo(1,2,3)没有传递给varargs方法foo(对象…)作为整数[]   java通过蓝牙将奇怪的数据从Arduino传输到Android   java ContainerRequestFilter获取空entitystream   java如何从安卓 studio中删除不兼容类型错误   基本Java错误   在Spring引导中使用REST API时发生java错误   javascript通过从SQL查询派生的URL打开页面