Python: module trace
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 |
| |
- builtins.object
-
- Coverage
- CoverageResults
- Ignore
- Trace
class Coverage(builtins.object) |
|
Coverage(ignore=<trace.Ignore object at 0x7f4948dfa510>)
|
|
Methods defined here:
- __init__(self, ignore=<trace.Ignore object at 0x7f4948dfa510>)
- Initialize self. See help(type(self)) for accurate signature.
- results(self)
- trace(self, frame, why, arg)
Data descriptors defined here:
- __dict__
dictionary for instance variables (if defined)
- __weakref__
list of weak references to the object (if defined)
|
class CoverageResults(builtins.object) |
|
CoverageResults(counts={}, modules={})
|
|
Methods defined here:
- __init__(self, counts={}, modules={})
- Initialize self. See help(type(self)) for accurate signature.
- update(self, other)
- Merge in the data from another CoverageResults
Data descriptors defined here:
- __dict__
dictionary for instance variables (if defined)
- __weakref__
list of weak references to the object (if defined)
|
class Ignore(builtins.object) |
|
Ignore(modules=None, dirs=None)
|
|
Methods defined here:
- __init__(self, modules=None, dirs=None)
- Initialize self. See help(type(self)) for accurate signature.
- names(self, filename, modulename)
Data descriptors defined here:
- __dict__
dictionary for instance variables (if defined)
- __weakref__
list of weak references to the object (if defined)
|
class Trace(builtins.object) |
|
Trace(ignore=<trace.Ignore object at 0x7f4948dfa850>, watchedModules=[])
|
|
Methods defined here:
- __init__(self, ignore=<trace.Ignore object at 0x7f4948dfa850>, watchedModules=[])
- Initialize self. See help(type(self)) for accurate signature.
- run(self, cmd)
- trace(self, frame, why, arg)
Data descriptors defined here:
- __dict__
dictionary for instance variables (if defined)
- __weakref__
list of weak references to the object (if defined)
| |
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)
- notrace_decorate(func)
- Use this decorator to safely disable tracing for calls to a specified
function. This will help optimize functions whose bottlenecks are in
Python code.
- resume()
- resume tracing.
- run(trace, cmd)
- runctx(trace, cmd, globals=None, locals=None)
- runfunc(trace, func, *args, **kw)
- suspend()
- suspend tracing until resume() called.
- 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
savedCnt = 0
savedTrace = None |