Install pyprof2calltree
masterOn Debian-based systems (Debian ≥ 11 or Ubuntu ≥ 20.04), you can install pyprof2calltree and its dependency kcachegrind using apt.
sudo apt install kcachegrind pyprof2calltreerepository·master·Indexed 41 days ago
https://github.com/pwaller/pyprof2calltreeA tool and API for converting Python cProfile profiling data into a format compatible with the KCacheGrind graphical calltree analyser.
On Debian-based systems (Debian ≥ 11 or Ubuntu ≥ 20.04), you can install pyprof2calltree and its dependency kcachegrind using apt.
sudo apt install kcachegrind pyprof2calltreeIn an IPython environment, you can use magic commands to profile code and then use the pyprof2calltree API to view the results. You can pass either the raw stats object returned by %prun or a path to a saved stats file.
# 1. Profile and visualize from the returned object
results = %prun -r ElementTree.fromstring(xml_content)
visualize(results)
# 2. Profile to a file and then convert/visualize that file
%prun -D out.stats ElementTree.fromstring(xml_content)
visualize('out.stats')
convert('out.stats', 'out.kgrind')You can use the pyprof2calltree API directly in a Python script or interactive shell to visualize cProfile results. The library provides visualize() to open the data in KCacheGrind and convert() to save the results to a file.
from pyprof2calltree import convert, visualize
# If you have a profiler object from cProfile
visualize(profiler.getstats())
# To save the results to a file for later use
convert(profiler.getstats(), 'profiling_results.kgrind')The pyprof2calltree CLI tool allows you to convert Python cProfile data into a format compatible with KCacheGrind. You can run a script directly to collect profiling data or provide an existing stats file.
# Basic help command
pyprof2calltree --help
# Example: Run a script and immediately open the results in kcachegrind
pyprof2calltree -r my_script.py [args]