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.)
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: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.