Py-spy
Sampling profiler for Python programs
Usage
py-spy works from the command line and takes either the PID of the program you want to sample from or the command line of the python program you want to run. py-spy has three subcommands record, top and dump:
record
py-spy supports recording profiles to a file using the record command. For example, you can generate a flame graph of your python process by going: