Sorry, I am not familiar with Python, but there the general method works if you can manually interrupt execution at any time.
Just do it and display the call stack. He will tell you, with a high probability, what you want to know. If you want to be more confident, just do it a few times.
This works because the guilty caller must be in the call stack for a fraction of the time wasted, which during this time gives it interruptions, whether it extends to many short calls or to several long ones.
NOTE. This process is more like a diagnosis than a measurement. Suppose a bad call spends 90% of the time. Then every time you stop it, the probability of 90% is that the bad call operator is right on the call stack so you can see and you will see that it is bad. However, if you want to accurately measure the loss, this is another problem. To do this, you will need a lot more samples to find out which% of them contain this call. Or, alternatively, just correct the culprit's call, note the acceleration, and that will tell you exactly what happened.
Mike Dunlavey May 10 '09 at 18:45 2009-05-10 18:45
source share