views:

54

answers:

1

I want to profile my Python code. I am well-aware of cProfile, and I use it, but it's too low-level. (For example, there isn't even a straightforward way to catch the return value from the function you're profiling.)

One of the things I would like to do: I want to take a function in my program and set it to be profiled on the fly while running the program.

For example, let's say I have a function heavy_func in my program. I want to start the program and have the heavy_func function not profile itself. But sometime during the runtime of my program, I want to change heavy_func to profile itself while it's running. (If you're wondering how I can manipulate stuff while the program is running: I can do it either from the debug probe or from the shell that's integrated into my GUI app.)

Is there a module already written which does stuff like this? I can write it myself but I just wanted to ask before so I won't be reinventing the wheel.

+1  A: 

It may be a little mind-bending, but this technique should help you find the "bottlenecks", it that's what you want to do. You're pretty sure of what routine you want to focus on. If that's the routine you need to focus on, it will prove you right. If the real problem(s) are somewhere else, it will show you where they are.

If you want a tedious list of reasons why, look here.

Mike Dunlavey
That's a useful technique, but not what I'm looking for here.
cool-RR
@cool-RR: That's OK, but it'll blow the socks off cProfile.
Mike Dunlavey