A few useful scripts for debugging Python performance on running processes. No code instrumentation required.
Depends on pyrasite.
pip install pyrasite
..which depends on gdb.
sudo apt install gdb
On Ubuntu, you'll also need to enable ptrace.
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
The user running the process needs read access to these scripts.
Write the stacktrace of a running program to $HOME/stacktrace-PID.log
pyrasite PID /path/to/phatstacks.py
Start profiling a running program
pyrasite PID /path/to/profstart.py
End profiling and write cProfile output to $HOME/profile-PID.cprof
pyrasite PID /path/to/profend.py
View profiling output using RunSnakeRun or pstats
python -m pstats $HOME/profile-PID.cprof