You can use Valgrind using the Callgrind module (built-in). This will create a file that can appear in KCacheGrind, which is available on most Linux distributions.
To limit profiling only to your code, use the collection parameter restriction , this will allow Python to work at almost full speed, and only your code will profile (which will run about 10x slower).
Note. I have not tried this with Python myself, but it worked in similar situations.
source share