3

I'm used to sampling C-based apps, which every few milliseconds sees what function stack is being called at that moment.

This allows me to see where most of the time is spent in an app so I can optimize it.

When using python, however, sample isn't so helpful, since it's sampling the C functions of the python interpreter, not the python code itself.

Is there a useful sampling tool for python?

1 Answer 1

4

Python includes a built-in set of profiling tools. In particular, you can run cProfile on an arbitrary python script from the command-line:

$ python -m cProfile myscript.py

Much more elaborate usage is available by calling the API directly. Note that the cProfile module was added in Python 2.5. In earlier versions, you can use the pure-Python, but slower "profile" module.

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

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.