是否有适用于Python的可视分析器?[关闭]

问题:是否有适用于Python的可视分析器?[关闭]

我现在使用cProfile,但是我发现编写pstats代码来查询统计数据很繁琐。

我正在寻找一个视觉工具,向我展示Python代码在CPU时间和内存分配方面的工作。

Java世界中的一些示例是visualvmJProfiler

  • 是否存在这样的东西?
  • 是否有执行此操作的IDE?
  • dtrace的帮助吗?

我知道Linux版KCachegrind,但是我希望我可以在Windows / Mac上运行而无需安装KDE。

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.


回答 0

我和一个朋友编写了一个名为SnakeViz的Python配置文件查看器,该查看器在网络浏览器中运行。如果您已经成功使用RunSnakeRun,则 SnakeViz可能不会添加那么多的值,但是SnakeViz的安装要容易得多。

编辑:SnakeViz支持Python 2和3,并且可以在所有主要系统上使用。

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.


回答 1

我只知道RunSnakeRun

前段时间也有关于PyDev(Eclipse)中的集成探查器的讨论,但是我不知道这是否会成为现实。

更新:不幸的是,似乎不再维护RunSnakeRun,并且它不支持Python 3。

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.


回答 2

我使用gprof2dot.py。结果看起来像这样。我使用这些命令:

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

您需要安装graphvizgprof2dot.py。您可能需要一个方便的Shell脚本

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.


回答 3

Spyder还为cProfile提供了一个非常不错的GUI:

Spyder also provides a pretty nice gui for cProfile:


回答 4

适用于Visual Studio的Python工具包含一个做得很好的图形分析器:http : //www.youtube.com/watch?v= VCx7rlPyEzE&hd =1

http://pytools.codeplex.com/

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/


回答 5

此人创造了一个图形化的配置文件,描述在这里。也许您可以将其用作自己工作的起点。

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


回答 6

KCacheGrind包含一个称为QCacheGrind的版本,该版本可在Mac OS XWindows上运行。

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


回答 7

试用Snakeviz。非常容易安装(通过pip),并且基于浏览器。

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

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

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


回答 8

Python Call Graph生成的图片与maxy’s answer中的图片非常相似。它还显示每个功能的总时间,由于某种原因,它没有反映在示例图中。

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.


回答 9

我已经编写了一个基于浏览器的可视化工具profile_eye,它可以对gprof2dot的输出进行操作

gprof2dot非常擅长处理许多分析工具的输出,并且在图形元素放置方面做得很好。最终渲染是静态图形,通常非常混乱。

使用d3.js,可以通过未聚焦的元素,工具提示和鱼眼失真的相对淡入来消除很多杂乱

为了进行比较,请参阅profile_eye对gprof2dot使用规范示例的可视化。特别是对于Python,请参见cProfile输出示例

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.


回答 10

考虑pyflame +火焰图

Pyflame:适用于Python + Flamegraph的跟踪分析器

https://github.com/uber/pyflame

您可以使用pyflame跟踪正在运行的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.


回答 11

我曾经使用过plop,发现它非常轻巧。快速了解性能。

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