Python call tree tool?

Robin Becker robin at jessikat.fsnet.co.uk
Tue Apr 23 13:37:03 EDT 2002


In article <lkd6wqpe6m.fsf at pc150.maths.bris.ac.uk>, Michael Hudson
<mwh at python.net> writes
>Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>
>> I searched in vain for a tool that can create a call tree or  inverted
>> call tree for python modules/packages. It seems inconceivable that the
>> Python community hasn't created such a tool so I must be looking in the
>> wrong places. 
>> 
>> Any one know where such a beast is?
>
>There's Tools/script/trace.py which might or might not do what you
>want.  Apparently it's in a bit of a sorry state, but I don't really
>know how/why.
>
>Cheers,
>M.
>
trace.py seems to trace the execution of code. What I want is the call
graph/inverted call graph a la CFlow so that I can determine which
functions/classes are not called or referred to in some set of modules.

This seems harder in Python as we can dynamically create references
using eval/exec etc, but it would help to narrow the search for dead
code if even a static analysis could be done. My present effort uses a
file system walk and an re match for the names declared in a fixed
module. That gives me stuff referenced in comments etc and is a bit
limited.

I guess I can use inspect to figure out the functions/classes that are
declared in an arbitrary module, but it seems harder to determine if
these things are actually referenced in other modules. For that I assume
I will have to do some code analysis. 
-- 
Robin Becker



More information about the Python-list mailing list