Recommended procedure for profiling python scripts

Assuming we want to profile myscript.py, run:

python3 -m cProfile -o myscript.profile myscript.py

In order to view it, I strongly recommend runsnakerun:

runsnake myscript.profile

You can install runsnake on Ubuntu using

sudo apt -y install runsnakerun