是否有适用于 Python 的可视化分析器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3378953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a visual profiler for Python?
提问by Frederik
I use cProfilenow but I find it tedious to write pstats code just to query the statistics data.
我现在使用cProfile,但我发现编写 pstats 代码只是为了查询统计数据很乏味。
I'm looking for a visual tool that shows me what my Python code is doing in terms of CPU time and memory allocation.
我正在寻找一种可视化工具,它可以向我展示我的 Python 代码在 CPU 时间和内存分配方面的作用。
Some examples from the Java world are visualvmand JProfiler.
Java 世界的一些例子是visualvm和JProfiler。
- Does something like this exist?
- Is there an IDE that does this?
- Would dtracehelp?
- 这样的东西存在吗?
- 有没有这样做的IDE?
- 将dtrace的帮助吗?
I know about KCachegrindfor Linux, but I would prefer something that I can run on Windows/Mac without installing KDE.
我知道KCachegrindfor Linux,但我更喜欢可以在 Windows/Mac 上运行而无需安装 KDE 的东西。
回答by nikow
I'm only aware of RunSnakeRun.
我只知道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.
前段时间也有一些关于 PyDev (Eclipse) 中的集成分析器的讨论,但我不知道这是否会成为现实。
Update: Unfortunately it seems that RunSnakeRun is no longer maintained, and it does not support Python 3.
更新:不幸的是,似乎不再维护 RunSnakeRun,并且它不支持 Python 3。
回答by PaulMcG
回答by maxy
I use gprof2dot.py. The result looks like this. I use those commands:
我使用 gprof2dot.py。结果看起来像这样。我使用这些命令:
python -m cProfile -o profile.dat my_program.py
gprof2dot.py -f pstats profile.dat | dot -Tpng -o profile.png
You need graphvizand gprof2dot.pyinstalled. You might like a convenience shell script.
您需要安装graphviz和gprof2dot.py。您可能喜欢方便的 shell 脚本。
回答by auny
回答by Lev Levitsky
Python Call Graphgenerates 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.
Python Call Graph生成的图片与maxy's answer 中的图片非常相似。它还显示了每个函数的总时间,出于某种原因,它没有反映在示例图中。
回答by jiffyclub
A friend and I have written a Python profile viewer called SnakeVizthat runs in a web browser. If you are already successfully using RunSnakeRunSnakeViz may not add that much value, but SnakeViz is much easier to install.
我和一个朋友编写了一个名为SnakeViz的 Python 配置文件查看器,它在 Web 浏览器中运行。如果您已经成功使用RunSnakeRunSnakeViz 可能不会增加那么多的价值,但 SnakeViz 更容易安装。
Edit: SnakeViz supports Python 2 and 3 and works on all major systems.
编辑:SnakeViz 支持 Python 2 和 3,适用于所有主要系统。
回答by Jake
Python Tools for Visual Studio contains a very well done graphical profiler: http://www.youtube.com/watch?v=VCx7rlPyEzE&hd=1
Visual Studio 的 Python 工具包含一个非常出色的图形分析器:http: //www.youtube.com/watch?v=VCx7rlPyEzE&hd =1
回答by Ami Tavory
I've written a browser-based visualization tool, profile_eye, which operates on the output of gprof2dot.
我编写了一个基于浏览器的可视化工具profile_eye,它对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.
gprof2dot 非常擅长处理许多分析工具的输出,并且在图形元素放置方面做得很好。最终的渲染是静态的图形,通常非常杂乱。
Using d3.jsit's possible to remove much of that clutter, through relative fading of unfocused elements, tooltips, and a fisheye distortion.
使用d3.js可以通过相对淡化未聚焦的元素、工具提示和鱼眼失真来消除大部分混乱。
For comparison, see profile_eye's visualizationof the canonical example used by gprof2dot. For Python in particular, see a cProfile output example.
为了进行比较,请参阅profile_eye 对gprof2dot 使用的规范示例的可视化。特别是对于 Python,请参阅cProfile 输出示例。
回答by BangTheBank
Try out Snakeviz. Very easy to install (via pip) and it's browser based.
试试 Snakeviz。非常容易安装(通过 pip)并且它是基于浏览器的。


