Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract the call graph of a function from Python source files?

Do you know an integrated tool that will generate the call graph of a function from Python sources? I need one that is consistent and can run on Windows OS.

like image 668
citn Avatar asked Jul 10 '09 07:07

citn


3 Answers

You could try with PyCallGraph
From its documentation:

Python Call Graph works with Linux, Windows and Mac OS X.

Otherwise, you can directly do it on your own, using the traceback module:

import traceback
traceback.print_stack()
like image 100
rob Avatar answered Oct 07 '22 15:10

rob


PyCallGraph produces the dynamic graph resulting from the specific execution of a Python program and not the static graph extracted from the source code. Does anybody know of a tool which produces the static graph?

like image 29
Tsf Avatar answered Oct 07 '22 15:10

Tsf


What about pycallgraph, it's a Python module that creates call graphs for Python programs. It works on windows. Just download graphviz and pycallgraph, pycallgraphs's source tarball has some examples.
Hope this helps

like image 32
sunqiang Avatar answered Oct 07 '22 14:10

sunqiang