The trace module allows you to trace program execution, generate annotated statement coverage listings, print caller/callee relationships and list functions executed during a program run. It can be used in another program or from the command line.
The trace module can be invoked from the command line. It can be as simple as
python -m trace --count somefile.py ...
The above will generate annotated listings of all Python modules imported during the execution of somefile.py.
The following command-line arguments are supported:
This is a simple example showing the use of this module:
import sys import trace # create a Trace object, telling it what to ignore, and whether to # do tracing or line-counting or both. tracer = trace.Trace( ignoredirs=[sys.prefix, sys.exec_prefix], trace=0, count=1) # run the new command using the given tracer tracer.run('main()') # make a report, placing output in /tmp r = tracer.results() r.write_results(show_missing=True, coverdir="/tmp")
timeit — Measure execution time of small code snippets
Enter search terms or a module, class or function name.