See also
Given a python program main.py:
python -m cProfile -o main.py.profile main.py- If you need to pass args to
main.py, do so after its appearance in this command
- If you need to pass args to
gprof2dot -f pstats main.py.profile -o main.py.dotdot -Tpng main.py.dot
Open main.py.png and viola!
Call-graph profiling in unit tests
Using pytest-profiling, you can automate this process as part of your (pytest-driven) unit tests:
- Install the plugin either as part of the normal dependency process or directly
python -m pip install pytest-profiling - Run unit tests with the
--profile-svgargument to enable the plugin:python -m pytest --profile-svg ...
Your unit tests should output a file named prof/combined.svg. This is the same heat-graph diagram.