trace
index
trace.py


program/module to trace Python program or function execution
 
This version is modified from the trace module distributed with Python.
Within Xplor-NIH, the most commonly called functions are suspend() and
resume(), which suspend/resume the echoing of Python commands to stdout.
 
Sample use, command line:
  trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
  trace.py -t --ignore-dir '$prefix' spam.py eggs
 
Sample use, programmatically (still more complicated than it should be)
   # create an Ignore option, telling it what you want to ignore
   ignore = trace.Ignore(dirs = [sys.prefix, sys.exec_prefix])
   # create a Coverage object, telling it what to ignore
   coverage = trace.Coverage(ignore)
   # run the new command using the given trace
   trace.run(coverage.trace, 'main()')
 
   # make a report, telling it where you want output
   t = trace.create_results_log(coverage.results(),
                                '/usr/local/Automatrix/concerts/coverage')
                                show_missing = 1)
 
   The Trace class can be instantited instead of the Coverage class if
   runtime display of executable lines is desired instead of statement
   converage measurement.

 
Classes
       
Coverage
CoverageResults
Ignore
Trace

 
class Coverage
     Methods defined here:
__init__(self, ignore=<trace.Ignore instance at 0xb86560>)
results(self)
trace(self, frame, why, arg)

 
class CoverageResults
     Methods defined here:
__init__(self, counts={}, modules={})
update(self, other)
Merge in the data from another CoverageResults

 
class Ignore
     Methods defined here:
__init__(self, modules=None, dirs=None)
names(self, filename, modulename)

 
class Trace
     Methods defined here:
__init__(self, ignore=<trace.Ignore instance at 0xb865a8>, watchedModules=[])
trace(self, frame, why, arg)

 
Functions
       
addModuleName(name)
add the name (string) of a module to be traced - to the current trace
commonprefix(dirs)
Given a list of pathnames, returns the longest common leading component
create_results_log(results, dirname='.', show_missing=1, save_counts=0)
current()
return most recently created trace object
find_executable_linenos(filename)
return a dict of the line numbers from executable statements in a file
 
    Works by finding all of the code-like objects in the module then searching
    the byte code for 'SET_LINENO' terms (so this won't work one -O files).
 
    
main(argv=None)
resume()
resume the current trace
run(trace, cmd)
runctx(trace, cmd, globals=None, locals=None)
runfunc(trace, func, *args, **kw)
suspend()
suspend the current trace
traceCmd(cmdString, modules=[])
traceCmd <python command>:
    simplified interface for tracing execution of python command
traceFile(fileName, modules=[])
traceFile <fileName>:
    simplified interface for tracing execution of file named fileName
usage(outfile)

 
Data
        currentTrace = 0