My question is very similar to that of Brice Thomas : Python getting meaningful results from cProfile However I could not find a satisfying answer. I'll explain :
I get similar results, ie the majority of the time is spent on the functions I use (prox.py, rawprox.py and position.py).
I could optimize the time spent on other operations but now I really want to understand what takes the most time within my functions.
I followed arbarnert's answer but it looks like it only works because the whole code is written between pr.enable() and pr.disable(). I mean that the cProfile results are limited to the functions written between those lines. This means that to make it work, I should not call any of the functions I want to have details of even a single time, because I don't want these functions to appear in the cProfile results. I want their subfunctions to appear.
Example :
import cProfile
pr = profile.Profile()
pr.enable()
any_operations_without_my_functions_called
pr.disable()
pr.print_stats(sort='time')
will work and tell me what operations take the most time.
Contrarily,
import cProfile
pr = profile.Profile()
pr.enable()
call_prox.py
call_rawprox.py
call_position.py
pr.disable()
pr.print_stats(sort='time')
will only result in telling me that prox.py took x seconds, rawprox.py took y seconds and position.py took z seconds, while I want to know what operations took the most time within them.
I clearly do not want to report the whole code inside these functions between the profiler lines, because the functions are called inside loops and it would be an incredible mess (actually, it would be totally undoable and I believe someone must have thought of a way of doing this).
Is there any solution you would recommend?