19

How can I do profiling by line in Python 3? The standard profilers have only function-level precision.

5
  • 1
    If you have the profiles of all of the functions, doesn't that mean that you have all of the lines??? Commented 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. Commented 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. Commented Jun 8, 2011 at 4:53
  • 1
    Have you tried, CProfile or hotshot? Commented 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. Commented Aug 2, 2012 at 5:08

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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...
5

There's a nice Pull Request that implements Python 3 support very well

https://bitbucket.org/robertkern/line_profiler/pull-request/2/python-25-33-compatibility-using-a-single/

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.