visualising python profiles with flameprof

April 11, 2020

Tl;DR is a great single-file converter from python’s profile file format to SVG flamegraphs.

profiling emerge

emerge is known to be slow occasionally. I always wondered why exactly but could never quite get to it.

A few years go I tried once with some success. It seems it was not ported to python 3 and I found

Example ebuild for Gentoo is here.

Let’s grab the profile:

$ cd ~/dev/git/portage
$ python -m cProfile -o \
    ./bin/emerge -pvuDN @world @preserved-rebuild --with-bdeps=y --complete-graph \
    --changed-deps --verbose-conflicts --backtrack=10000

# wait 5 minutes
Exiting on signal Signals.SIGINT
$ flameprof > emerge.svg

Generated profile graph is here.


If you spot something odd you can try to tweak it! I’ll try as well.

Have fun!