2

I'm currently using cProfile and pstats to profile some Python code.

Is there a way to annotate the source code with the time taken on each line? Ideally this would be a coloured (HTML) version of the source with expensive lines highlighted in red or something.

Tom
  • 42,844
  • 35
  • 95
  • 101
  • If you just want to find the most expensive lines, [try this](http://stackoverflow.com/questions/4295799/how-to-improve-performance-of-this-code/4299378#4299378). – Mike Dunlavey Mar 29 '11 at 15:12

2 Answers2

4

yes, look at line profiler or profilehooks

I think is so simple to render the output to html, with your own codes.

and for graph, take a look at gprof2dot

pylover
  • 7,670
  • 8
  • 51
  • 73
1

Not quite what you ask for but might be helpful:

http://code.google.com/p/jrfonseca/wiki/Gprof2Dot

It draws a graph which makes it really easy to see which functions take up your execution time.

I'm not aware of a python profiler that tracks execution line by line. I suspect that doing so would confuse the results because it would be too much overhead.

Winston Ewert
  • 44,070
  • 10
  • 68
  • 83