Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling C + Python (SWIG)

I have python code with C libraries, I use SWIG to plug it all together. I would like to profile the C libraries.

I compiled them with -pg but no profiling output is generated... Is there method to profile such a mixed code?

like image 896
Jakub M. Avatar asked Oct 24 '22 07:10

Jakub M.


1 Answers

You can use Valgrind with the Callgrind module (built-in). This will produce a file that can be displayed in KCacheGrind, which is avaliable on most Linux distributions.

To limit profiling to just your code, use the limiting collection options, this will allow Python to run at almost full speed, and only profile your code (which will run about 10x slower).

Note: I haven't tried this with Python myself, but it has worked for similar situations.

like image 91
Silas Parker Avatar answered Oct 31 '22 11:10

Silas Parker