Skip to main content

Help visualize profiling data from cProfile with kcachegrind

Project description

Overview

Script to help visualize profiling data collected with the cProfile python module with the kcachegrind (screenshots) graphical calltree analyser.

This is a rebranding of the venerable http://www.gnome.org/~johan/lsprofcalltree.py script by David Allouche et Al. It aims at making it easier to distribute (e.g. through pypi) and behave more like the scripts of the debian kcachegrind-converters package. The final goal is to make it part of the official upstream kdesdk package.

Authors

  • David Allouche (original author)

  • Jp Calderone

  • Itamar Shtull-Trauring

  • Johan Dahlin

  • Olivier Grisel (repackaging and pstats support)

Command line usage

Upon installation you shoould have a pyprof2calltree script in your path:

$ pyprof2calltree --help
Usage: /usr/bin/pyprof2calltree [-k] [-o output_file_path] [-i input_file_path] [-r scriptfile [args]]

Options:
  -h, --help            show this help message and exit
  -o OUTFILE, --outfile=OUTFILE
                        Save calltree stats to <outfile>
  -i INFILE, --infile=INFILE
                        Read python stats from <infile>
  -r SCRIPT, --run-script=SCRIPT
                        Name of the python script to run to collect profiling
                        data
  -k, --kcachegrind     Run the kcachegrind tool on the converted data

Python shell usage

pyprof2calltree is also best used from an interactive python shell such as the defaulft shell. For instance let us profile XML parsing:

>>> 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

or with the 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)

Change log

  • 1.0.1 - 2008-10-16: fix typos in 1.0 release

  • 1.0 - 2008-10-16: initial release under the pyprof2calltree name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyprof2calltree-1.0.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

pyprof2calltree-1.0.1-py2.5.egg (3.0 kB view details)

Uploaded Source

File details

Details for the file pyprof2calltree-1.0.1.tar.gz.

File metadata

File hashes

Hashes for pyprof2calltree-1.0.1.tar.gz
Algorithm Hash digest
SHA256 00591a30da912971f42ab411d5d0eafdd7be908ca6ec036dc4cb54c64ec8002c
MD5 a67a23b582fbf3a760aa90bbb0fb89e2
BLAKE2b-256 0fc31b1d2c815eb2da5dd6cbb99a6791a4fda3efe598ba9334557286fed34975

See more details on using hashes here.

File details

Details for the file pyprof2calltree-1.0.1-py2.5.egg.

File metadata

File hashes

Hashes for pyprof2calltree-1.0.1-py2.5.egg
Algorithm Hash digest
SHA256 d05fdf072f55017188f40ae13cd8819133ba1f6dd5944a22a28aebb07f310396
MD5 3487ffda6b5ef5c4863c9a5ec6a10707
BLAKE2b-256 40779f24ffc8990acc89eb792d167d99fe62f7167fd744535f50a0ec1023b335

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page