Is there a visual profiler for Python?

PythonUser InterfaceProfilingProfiler

Python Problem Overview


I use cProfile now but I find it tedious to write pstats code just to query the statistics data.

I'm looking for a visual tool that shows me what my Python code is doing in terms of CPU time and memory allocation.

Some examples from the Java world are visualvm and JProfiler.

  • Does something like this exist?
  • Is there an IDE that does this?
  • Would dtrace help?

I know about KCachegrind for Linux, but I would prefer something that I can run on Windows/Mac without installing KDE.

Python Solutions


Solution 1 - Python

A friend and I have written a Python profile viewer called SnakeViz that runs in a web browser. If you are already successfully using RunSnakeRun SnakeViz may not add that much value, but SnakeViz is much easier to install.

Edit: SnakeViz supports Python 2 and 3 and works on all major systems.

Solution 2 - Python

I'm only aware of RunSnakeRun.

There was also some talk some time ago about an integrated profiler in PyDev (Eclipse), but I don't know if that will ever see the light of day.

Update: Unfortunately it seems that RunSnakeRun is no longer maintained, and it does not support Python 3.

Solution 3 - Python

I use gprof2dot.py. The result looks like this. I use those commands:

  python -m cProfile -o profile.dat my_program.py
  gprof2dot.py -f pstats profile.dat | dot -Tpng -o profile.png

You need graphviz and gprof2dot.py installed. You might like a convenience shell script.

Solution 4 - Python

Spyder also provides a pretty nice gui for cProfile:

enter image description here

Solution 5 - Python

This person created a graphical profile, described here. Maybe you could use that as a starting point for your own work.

Solution 6 - Python

Python Tools for Visual Studio contains a very well done graphical profiler: http://www.youtube.com/watch?v=VCx7rlPyEzE&hd=1

http://pytools.codeplex.com/

Solution 7 - Python

KCacheGrind includes a version called QCacheGrind which does run on Mac OS X and on Windows.

Solution 8 - Python

Try out Snakeviz. Very easy to install (via pip) and it's browser based.

https://jiffyclub.github.io/snakeviz/

Solution 9 - Python

Python Call Graph generates pics very similar to those in maxy's answer. It also shows total time for each function, for some reason it's not reflected in the example graphs.

Solution 10 - Python

I've written a browser-based visualization tool, profile_eye, which operates on the output of gprof2dot.

gprof2dot is great at grokking many profiling-tool outputs, and does a great job at graph-element placement. The final rendering is a static graphic, which is often very cluttered.

Using d3.js it's possible to remove much of that clutter, through relative fading of unfocused elements, tooltips, and a fisheye distortion.

For comparison, see profile_eye's visualization of the canonical example used by gprof2dot. For Python in particular, see a cProfile output example.

Solution 11 - Python

Consider pyflame + flamegraph

Pyflame: A Ptracing Profiler For Python + flamegraph

https://github.com/uber/pyflame

You can trace towards a running python process using pyflame.

Solution 12 - Python

I have used plop and found it to be very light-weight. Gives a quick insight into the perf.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrederikView Question on Stackoverflow
Solution 1 - PythonjiffyclubView Answer on Stackoverflow
Solution 2 - PythonnikowView Answer on Stackoverflow
Solution 3 - PythonmaxyView Answer on Stackoverflow
Solution 4 - PythonjsexauerView Answer on Stackoverflow
Solution 5 - PythonPaulMcGView Answer on Stackoverflow
Solution 6 - PythonJakeView Answer on Stackoverflow
Solution 7 - PythonakaiholaView Answer on Stackoverflow
Solution 8 - PythonBangTheBankView Answer on Stackoverflow
Solution 9 - PythonLev LevitskyView Answer on Stackoverflow
Solution 10 - PythonAmi TavoryView Answer on Stackoverflow
Solution 11 - PythonmckelvinView Answer on Stackoverflow
Solution 12 - PythonaunyView Answer on Stackoverflow