write-time call tree?

Josiah Carlson jcarlson at uci.edu
Mon Nov 8 20:14:23 CET 2004


Jeremy Jones <zanesdad at bellsouth.net> wrote:
> Does anyone know of a tool that will look at a Python source file 
> (without executing the file - just analyzing it) and generate a report of
> 
>     * functions, classes, methods defined
>     * objects created
>     * method/function calls (I'm really looking for a map of which calls
>       were made from within which functions/methods), preferably with
>       the option of filtering which calls to trace
>     * trace imports if possible, show blank stub if an ImportError is
>       encountered, again, preferably with the option to filter which
>       imports to trace
> 
> I found some tools that worked at runtime (trace.py, maybe PyChecker), 
> but I'm not sure they have the functionality I need even if collecting 
> the data at runtime were what I am looking for.  I would obviously 
> prefer an open souce/free solution, but if anyone knows of a 
> commercially developed tool, I might be able to convince the company to 
> spring for it.

Some scripts have differing behavior depending on what other things
(that you cannot control) are doing at that same time.  An example of
this would be CGI applications, web servers, etc.  So requiring analysis
without running can't happen in the general case.

One can even make the claim that such analysis requires a solution
to the halting problem, which is as of yet unsolved, and believed to be
unsolvable.

Here are two simple scripts that would not be truely analyzable without
running, and even then, it wouldn't do a whole lot of good to attempt to
analyze.

random.seed(int(time.time()))
for i in xrange(random.randrange(1, 65536)):
    #do something that creates objects


h = '217ea9ff0e4add3a51cab9b1f6b56cc5'
for possible_string in universe_of_strings():
    if md5.new(possible_string).hexdigest():
        print possible_string
        break


 - Josiah

P.S.
(h is the hex digest of 'kaukhg98 y243phasd g924h')



More information about the Python-list mailing list