Python 中的调用图分析器
在我的 python 程序中,我使用了很多模块,并尝试计算调用的函数和涉及的调用链。 python 中是否有一个工具/模块可以为我提供这些统计数据。
In my python program i have used a lot of modules and am trying to have a count of the functions called and the call chains involved. Is there a tool/module in python which will provide me with these statistics.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我用过这个。它对我的目的不起作用,因为我的应用程序同时运行许多线程,最终我得到了 12000 个链接,而 graphviz 无法编译它。但当我在单线程上运行它时它就起作用了。
http://pycallgraph.slowchop.com/
I've used this. It didn't work for my purposes since my app has many threads running at once and and I ended up with 12000 links and graphviz couldn't compile it. But it worked when I ran it on a single thread.
http://pycallgraph.slowchop.com/
pydoc -k profile
将为您提供系统上的内容列表。我使用过 profile 和 cProfile。
这很简单:
pydoc -k profile
will give you a list of what's on your system. I've used profile and cProfile.
It's as easy as:
六年后我有同样的问题,一些 人们推荐使用 KCachegrind 来可视化调用链。虽然它对于 Linux 用户来说是一个有效的选择,但在 Mac OSX 上安装非常困难,在 Windows 上也可能如此。
最后,我使用 gprof2dot 代替。只需几个命令,您就可以获得富有表现力的调用图:
简单的工具,快速的结果:查看一下:https:// github.com/jrfonseca/gprof2dot
编辑:
现在我发现你也可以通过brew获得KCachegrind:
brew install qcachekrind
Six years later I have the same question, some people recommend to use KCachegrind for visualizing call chains. While it is a valid option for Linux users, it is extremely hard to install on Mac OSX and probably on Windows too.
Finally, I am using gprof2dot instead. With just a few commands you will have your expressive call graph:
Easy tool, fast results: check it out: https://github.com/jrfonseca/gprof2dot
Edit:
Now I found out you can get KCachegrind also via brew:
brew install qcachekrind