NichtJens
NichtJens

Reputation: 1899

Fortran extension to Python via f2py: How to profile?

I'm using an extension to Python (2.7.2) written in Fortran (gfortran 4.4.7) compiled via f2py (Ver. 2).

I can profile the Python part with cProfile, but the result does not give any information about the Fortran functions. Instead the time is attributed to the Python function calling the Fortran function.

I have enabled the "-pg -O" flags for all Fortran objects I build, as well as in the f2py call creating the shared object via: f2py --opt="-pg -O" ...

Any hint on how to get the Fortran informations too is highly appreciated.

If anyone uses a similar set-up, with a different profiler, I'd also be interested.

Upvotes: 7

Views: 869

Answers (3)

Florian
Florian

Reputation: 931

This workflow seems to work pretty well :

    1. Use callgrind to profile your code (this generates a file like callgrind.out.27237) :

valgrind --tool=callgrind python my_python_script_calling_f2py_functions.py arg1 arg2

gprof2dot -f callgrind callgrind.out.27237 > callgrind.dot

dot -Tjpg callgrind.dot -o callgrind.jpg

Upvotes: 0

ilciavo
ilciavo

Reputation: 3494

A Fortran function call appears as:

<ipython-input-51-f4bf36c6a947>:84(<module>). 

I know, you can't identify which module is being called but at least this gives you an idea.

Another way is wrapping it into a Python function and then see timing for the Python function.

Upvotes: 1

Roland Smith
Roland Smith

Reputation: 43513

Have a look at the python extension profiler yep.

Upvotes: 2

Related Questions