Reputation: 33335
I'm using the python hotshot profiler, and it tells me one of my methods foo() is being called N times, where N is a larger number than I was expecting.
Is there a way to get more detail about where foo() is being called from? Ideally, a listing of module names and line numbers?
(I can't just use grep. My codebase contains lots of calls to foo(), but I want to find only the ones that are actually being executed under the particular conditions I've set up in the profiler.)
Upvotes: 0
Views: 260
Reputation: 208475
One option is to add some logging to the top of foo()
to indicate where it was called from, you just need to add these lines:
def foo():
import traceback
print 'foo called from', traceback.extract_stack(limit=2)[0][2]
# previous foo() code
Instead of logging you may find it more useful to maintain a global dictionary where you keep track of a count of how many times foo()
has been called from different places.
Upvotes: 1