7

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.

4
  • FWIW, I stopped using f2py for this reason... it is difficult to go in and see what is happening in the Fortran code. The issue is that the Fortran code is wrapped with C code, further muddying the situation. Commented May 14, 2013 at 18:23
  • Maybe you should try it the pythonic way: it is good practice to put test routines in the if __name__=="__main__": part of python modules. So I suggest to write a separate Fortran program to profile this part separately.
    – Stefan
    Commented May 15, 2013 at 6:39
  • A Fortran function call appears as <ipython-input-51-f4bf36c6a947>:84(<module>). It's true you can't identify which module is being called but it gives you an idea. Another way is to wrap it into a Python function and then see timing for the Python function.
    – ilciavo
    Commented Jun 23, 2015 at 16:42
  • @ilciavo this is probably the best possible answer. Do you care to make it an answer? I'd probably accept it (considering the time this question has been open ;-)).
    – NichtJens
    Commented Jun 24, 2016 at 16:50

3 Answers 3

2

Have a look at the python extension profiler yep.

3
  • The manual says use ppref to read the file.prof. Could you please explain briefly how to do that?
    – ilciavo
    Commented Jun 23, 2015 at 16:46
  • I suspect that the name pperf is a typo. It whould probably say pprof (from Google's perftools) Commented Jun 24, 2015 at 18:47
  • yep depends on google-perftools which has issue with 64 bits systems. From its doc : "The glibc built-in stack-unwinder on 64-bit systems has some problems with the perftools libraries". For this reason, I could not use it.
    – Florian
    Commented Jul 10, 2017 at 9:10
1

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.

0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.