How can I do profiling by line in Python 3? The standard profilers have only function-level precision.
-
1If you have the profiles of all of the functions, doesn't that mean that you have all of the lines???cwallenpoole– cwallenpoole2011-06-08 00:52:43 +00:00Commented Jun 8, 2011 at 0:52
-
1@cwallenpoole: No it does not. But if you had the profile of all the lines, you would probably have the profile of all the functions.Matt Joiner– Matt Joiner2011-06-08 03:40:06 +00:00Commented Jun 8, 2011 at 3:40
-
Hi Matt. FWIW, I'm pretty sure we've discussed this before. It gives you approximate cost and exact location of the heaviest lines, whether exclusive or inclusive.Mike Dunlavey– Mike Dunlavey2011-06-08 04:53:34 +00:00Commented Jun 8, 2011 at 4:53
-
1Have you tried, CProfile or hotshot?user1538709– user15387092012-08-02 02:11:13 +00:00Commented Aug 2, 2012 at 2:11
-
1@cwallenpoole: No. But if the lines of a function are disjoint from any other function's lines as they are in Python, then having the profile of all lines means you can calculate the profile all functions. I'm not aware of cprofile fitting this criterion.Matt Joiner– Matt Joiner2012-08-02 05:08:13 +00:00Commented Aug 2, 2012 at 5:08
Add a comment
|
3 Answers
While line_profiler only works for Python 2.x, it doesn't seem too hard to make the necessary changes to get it to work with 3.x.
I've done this myself here. It's quick and dirty and pretty much untested, so use it at your peril, but it's possibly a start.
1 Comment
Dubslow
Nice! You answered just in time for me to see it :) Any chance of getting your 3.x update into the "main" version? Or better yet, get line_profiler into the Python stdlib...
There's a nice Pull Request that implements Python 3 support very well
Comments
As for the line_profiler, a recent working pull request is here waiting for an inclusion. The fork can be installed via:
pip install cython
pip install -e hg+https://bitbucket.org/kmike/line_profiler@7999f21#egg=line_profiler
It works for me at least on Python 3.4.1 with IPython magic functions.