PYPROF2CALLTREE(1)
π PYPROF2CALLTREE π
okay bestie, welcome to the glow-up of Pyprof2calltree (that's the title, that's the name, that's the whole vibe) β it's a General Commands Manual girly and she lives in section 1. Let's get into it β¨
πΈ NAME πΈ
Pyprof2calltree β visualize Python cProfile data in kcachegrind π¦
β¨ DESCRIPTION β¨
So like, this is a script that helps you visualize profiling data that you collected with the cProfile Python module, using the kcachegrind graphical calltree analyser. That's the whole point of her existence and she's serving it π
This is a rebranding of the venerable http://www.gnome.org/~johan/lsprofcalltree.py script by David Allouche et Al. She's giving it a whole new era because:
- she wants to be easier to distribute (like, e.g. through PyPI, no big deal π)
- she wants to behave more like the scripts of the debian
kcachegrind-converterspackage
And the final goal? Making her part of the official upstream kdesdk package. Main character energy, honestly π
π OPTIONS π
Upon installation you should have a pyprof2calltree script in your path, and she will literally tell you all about herself:
$ 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
and here's the breakdown, one by one, no skips, we don't do that here π«Ά
-h,--helpβ show this help message and exit. the classic, the icon, the "wait what does this do again" button π-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 thekcachegrindtool on the converted data π-r scriptfile [args ...],--run-script scriptfile [args ...]β name of the Python script to run to collect profiling data. yes she will run it for you, and yes you can passargs ...π
π PYTHON SHELL USAGE π
ngl, pyprof2calltree is also best used from an interactive Python shell, like the default shell. for instance, let's profile XML parsing, because why not π
>>> 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)
ok that's the whole page bestie, go profile something and make it pretty π
and that's a wrap!! this whole thing is from the General Commands Manual, she's PYPROF2CALLTREE(1) and she ate, no crumbs, periodt πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- debian bookworm: pyprof2calltree 1.4.5-1 Β· MIT
- debian trixie: pyprof2calltree 1.4.5-1 Β· MIT
- ubuntu jammy: pyprof2calltree 1.4.5-1 Β· MIT
- ubuntu noble: pyprof2calltree 1.4.5-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms