traceback tool to increase efficiency.

Rich Harkins rich at worldsinfinite.com
Mon Aug 12 18:53:15 CEST 2002


On Monday 12 August 2002 12:37 pm, Hunter Peress wrote:
> I've tried traceback.print_stack() and inspect.stack() and
> inspect.trace() and they don't do what I want.
>
> Here's what Im looking for.
>
> Imagine this simple code:
> [snip]
>
> So after this runs, I want to look at this "traceback" type thing, and
> be able to see a list of all methods called...eg:
>
> a() in file whatever
> print(" SADSADSAD ")in file sys?
>
> localtime() in file time
> print ([localtimelist]) in file time
> b() in file whatever
>

I think you might be looking for the profiler.  Try pydoc profile to get the 
basics, but you can just do something like the following:

python [path to python library]/profile.py program args...

[path to python library] is whatever path the Python libraries were installed 
into (usually /usr/lib/pythonX.Y or /usr/local/lib/pythonX.Y where X and Y 
are version numbers such as 2 and 2, etc.)  You will get a dump of all the 
calls and the amount of time Python was executing each one.

The other way to do what I think you're looking for is to employ 
sys.settrace().  This lets you set a function that will be called before 
*every* python instruction.  You can get into a great deal of trouble with it 
but it is sometimes a useful way to track what's going on.  See the Python 
documentation "How it works" in the Profiler section or loopup sys.settrace() 
and click on the referenced "How it works" document.  You may also want to 
look into the Python debugger which provides nicely intrusive capabilities 
with running Python programs.

Either way the Python traceback isn't likely what you're looking for.  Python 
tracebacks are created when exceptions are raised and only reflect the 
contents of the stack between the exception generator and the exception 
handler.

Hope this is of some help,
Rich


>
> [snip]




More information about the Python-list mailing list