使用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我可以在J2EE1.4中使用JAXR吗   YouTube数据API超出了未经验证的java每日使用限制   java RED5 RTMPConnManager未设置applicationContext局部变量。这会导致NullPointerException   java多部分/formdata,加载图像(安卓)   java Struts 2<s:select>填充表单中的其他字段   java Eclipse在迁移后不会将邮件属性传递给Spring Boot   java如何检查请求的TLS版本   java如何从包中导入相同的类   如何在java中将BLOB字符串转换为人类可读的格式字符串   java使用Play映射特定的文件路径!框架   java Eclipse重构   在子字符串上使用“预定义字符类”的java   java如何在SeleniumWebDriver中选择li中的锚定标记?   jspjava。木卫一。FileNotFoundException:系统找不到指定的路径   java Hi,在启动cmd\design javafx\cmd eclipse时,我的文件不是删除的,也不是复制的   java Selenium Web驱动程序异常“找不到:taskkill的可执行文件”   java如何获得数组的迭代器?