CProfile and Python: finding a specific line number in which code spends more time on

I use cProfile, pstats and Gprof2dot to profile a fairly long python script.

The results tell me that most of the time is spent calling the method in the object that I defined. However, I would like to know exactly what line number inside this function is time.

Any idea how to get this additional information?

(By the way, I'm using Python 2.6 on the OSX snow leopard if that helps ...)

+5
source share
3 answers

In python, written by Robert Kern, there is a string profiler .

+3

cProfile ; , .

cProfile profile ( Python). profile pstats , pstats , Python.

, , .

+2

Suppose that the amount of time "eaten" is a certain amount, for example 40%. Then, if you simply interrupt the program or pause it at a random time, the probability is 40%, which you will see, exactly exposed in the call stack. Do this 10 times, and on 4 samples +/- you will see it.

This suggests why this works. This is an example.

+1
source

All Articles