instrumenting Python code

Peter Hansen peter at engcorp.com
Wed Mar 27 01:35:37 EST 2002


Amir Michail wrote:
> 
> I was wondering if there is an easy way to instrument Python code
> so that I can collect information about a particular execution. In
> particular, I am interested in collecting the following info:
> 
> * functions called in execution
> 
> * which function called what other function (the call graph)
> 
> * the values of local/global variables
> 
> It seems I can get all this from the debugger module though it doesn't
> appear to have been designed to be used from another program.  The profiler
> module only gives the first item above.

Among other things, you might want to check out the use of sys.settrace()
(see the sys module) and the standard module 'profile' or the 
trace module included as python/Tools/Scripts/trace.py.

-Peter



More information about the Python-list mailing list