Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I profile Python code line-by-line?
    text
    copied!<p>I've been using cProfile to profile my code, and it's been working great. I also use <a href="http://code.google.com/p/jrfonseca/wiki/Gprof2Dot" rel="nofollow noreferrer">gprof2dot.py</a> to visualize the results (makes it a little clearer).</p> <p>However, cProfile (and most other Python profilers I've seen so far) seem to only profile at the function-call level. This causes confusion when certain functions are called from different places - I have no idea if call #1 or call #2 is taking up the majority of the time. This gets even worse when the function in question is six levels deep, called from seven other places.</p> <p>How do I get a line-by-line profiling?</p> <p>Instead of this:</p> <pre><code>function #12, total time: 2.0s </code></pre> <p>I'd like to see something like this:</p> <pre><code>function #12 (called from somefile.py:102) 0.5s function #12 (called from main.py:12) 1.5s </code></pre> <p>cProfile does show how much of the total time "transfers" to the parent, but again this connection is lost when you have a bunch of layers and interconnected calls.</p> <p>Ideally, I'd love to have a GUI that would parse through the data, then show me my source file with a total time given to each line. Something like this:</p> <pre><code>main.py: a = 1 # 0.0s result = func(a) # 0.4s c = 1000 # 0.0s result = func(c) # 5.0s </code></pre> <p>Then I'd be able to click on the second "func(c)" call to see what's taking up time in that call, separate from the "func(a)" call.</p> <p>Does that make sense? Is there any profiling library that collects this type of information? Is there some awesome tool I've missed?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload