- Install KCacheGrind via flatpak
- https://apps.kde.org/kcachegrind/
- https://flathub.org/apps/details/org.kde.kcachegrind
flatpak install flathub org.kde.kcachegrind
- Activate your python venv
- Install pyprof2calltree (python profile to call tree)
- https://github.com/pwaller/pyprof2calltree
apt install pyprof2calltree
- Add cprofile to your code
import cProfile
import pstats
...
...
with cProfile.Profile() as pr:
main()
stats = pstats.Stats(pr)
stats.sort_stats(pstats.SortKey.TIME)
stats.print_stats()
stats.dump_stats(filename="needs_profiling.prof")- Convert to calltree format
pyprof2calltree -i needs_profiling.prof -o callgrind.out.whatever
- Open in KCacheGrind, using the GUI or
flatpak run org.kde.kcachegrind callgrind.out.whatever- KCacheGrind expects filenames as
callgrind.out*
- Other profiling tools