有 Python 的可视化分析器吗?

我现在使用 CProfile,但是我发现仅仅为了查询统计数据而编写 pstats 代码非常繁琐。

我正在寻找一个可视化工具,它向我展示了我的 Python 代码在 CPU 时间和内存分配方面正在做什么。

一些来自 Java 世界的例子是 视觉影像JProfiler

  • 这种东西真的存在吗?
  • 有什么 IDE 可以做到这一点吗?
  • Dtrace有用吗?

我知道用于 Linux 的 KCache碾,但是我更喜欢那些不用安装 KDE 就可以在 Windows/Mac 上运行的东西。

48580 次浏览

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.

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

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.

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

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.

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.

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/

Spyder also provides a pretty nice gui for cProfile:

enter image description here

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.

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

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

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

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.