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.
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 - 2008-10-16: initial release under the pyprof2calltree name
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyprof2calltree-1.0.tar.gz.
File metadata
- Download URL: pyprof2calltree-1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
299a78cbe7083200ae8f1593c25d6e1e865e98c9a4c76f1296ed354944a29e1b
|
|
| MD5 |
b07d19d4149e82b57a73e409ecca0125
|
|
| BLAKE2b-256 |
ef1fa5b54e3fffd8d7114a3d8bf5446ed7f44f15978c70effa33e86754a68c58
|
File details
Details for the file pyprof2calltree-1.0-py2.5.egg.
File metadata
- Download URL: pyprof2calltree-1.0-py2.5.egg
- Upload date:
- Size: 3.0 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
452604aa60c3b0a7e0ba98ffb0d21687bd49e9158d65a1d30ce35453e9d7125e
|
|
| MD5 |
98bafeb9986c3083802da397d580f75c
|
|
| BLAKE2b-256 |
344dbb0ced4497eb0ae0847267352302853b8f690dd19578f5ae98f6e67ed3ca
|