开发者

Call-graph profilers in 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开发者_如何学Python call chains involved. Is there a tool/module in python which will provide me with these statistics.


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

will give you a list of what's on your system. I've used profile and cProfile.

It's as easy as:


if __name__ == '__main__':
 if PROFILING:
  import cProfile
  cProfile.run("main()")
 else:
  main()


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:

python -m cProfile -o output.pstats path/to/your/script arg1 arg2
gprof2dot.py -f pstats output.pstats | dot -Tpng -o output.png

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜