@@ -13,103 +13,178 @@ or from the command line.
1313
1414.. _trace-cli :
1515
16- Command Line Usage
16+ Command- Line Usage
1717------------------
1818
1919The :mod: `trace ` module can be invoked from the command line. It can be as
2020simple as ::
2121
22- python -m trace --count somefile.py ...
22+ python -m trace --count -C . somefile.py ...
2323
24- The above will generate annotated listings of all Python modules imported during
25- the execution of :file: ` somefile.py ` .
24+ The above will execute :file: ` somefile.py ` and generate annotated listings of
25+ all Python modules imported during the execution into the current directory .
2626
27- The following command-line arguments are supported:
27+ .. program :: trace
28+
29+ .. cmdoption :: --help
30+
31+ Display usage and exit.
32+
33+ .. cmdoption :: --version
34+
35+ Display the version of the module and exit.
36+
37+ Main options
38+ ^^^^^^^^^^^^
39+
40+ At least one of the following options must be specified when invoking
41+ :mod: `trace `. The :option: `--listfuncs <-l> ` option is mutually exclusive with
42+ the :option: `--trace <-t> ` and :option: `--counts <-c> ` options . When
43+ :option: `--listfuncs <-l> ` is provided, neither :option: `--counts <-c> ` nor
44+ :option: `--trace <-t> ` are accepted, and vice versa.
45+
46+ .. program :: trace
47+
48+ .. cmdoption :: -c, --count
49+
50+ Produce a set of annotated listing files upon program completion that shows
51+ how many times each statement was executed. See also
52+ :option: `--coverdir <-C> `, :option: `--file <-f> ` and
53+ :option: `--no-report <-R> ` below.
54+
55+ .. cmdoption :: -t, --trace
2856
29- :option: `--trace `, :option: `-t `
3057 Display lines as they are executed.
3158
32- :option: `--count `, :option: `-c `
33- Produce a set of annotated listing files upon program completion that shows how
34- many times each statement was executed.
59+ .. cmdoption :: -l, --listfuncs
60+
61+ Display the functions executed by running the program.
62+
63+ .. cmdoption :: -r, --report
3564
36- :option: `--report `, :option: `-r `
3765 Produce an annotated list from an earlier program run that used the
38- :option: `--count ` and :option: `--file ` arguments.
66+ :option: `--count <-c> ` and :option: `--file <-f> ` option. This does not
67+ execute any code.
3968
40- :option: `--no-report `, :option: `-R `
41- Do not generate annotated listings. This is useful if you intend to make
42- several runs with :option: `--count ` then produce a single set of annotated
43- listings at the end.
69+ .. cmdoption :: -T, --trackcalls
70+
71+ Display the calling relationships exposed by running the program.
72+
73+ Modifiers
74+ ^^^^^^^^^
75+
76+ .. program :: trace
4477
45- :option: `--listfuncs `, :option: `-l `
46- List the functions executed by running the program.
78+ .. cmdoption :: -f, --file=<file>
4779
48- :option: ` --trackcalls `, :option: ` -T `
49- Generate calling relationships exposed by running the program .
80+ Name of a file to accumulate counts over several tracing runs. Should be
81+ used with the :option: ` --count <-c> ` option .
5082
51- :option: `--file `, :option: `-f `
52- Name a file containing (or to contain) counts.
83+ .. cmdoption :: -C, --coverdir=<dir>
5384
54- :option: `--coverdir `, :option: `-C `
55- Name a directory in which to save annotated listing files.
85+ Directory where the report files go. The coverage report for
86+ ``package.module `` is written to file :file: `{ dir } /{ package } /{ module } .cover `.
87+
88+ .. cmdoption :: -m, --missing
5689
57- :option: `--missing `, :option: `-m `
5890 When generating annotated listings, mark lines which were not executed with
59- '``>>>>>> ``'.
91+ ``>>>>>> ``.
92+
93+ .. cmdoption :: -s, --summary
94+
95+ When using :option: `--count <-c> ` or :option: `--report <-r> `, write a brief
96+ summary to stdout for each file processed.
97+
98+ .. cmdoption :: -R, --no-report
99+
100+ Do not generate annotated listings. This is useful if you intend to make
101+ several runs with :option: `--count <-c> `, and then produce a single set of
102+ annotated listings at the end.
103+
104+ .. cmdoption :: -g, --timing
105+
106+ Prefix each line with the time since the program started. Only used while
107+ tracing.
60108
61- :option: `--summary `, :option: `-s `
62- When using :option: `--count ` or :option: `--report `, write a brief summary to
63- stdout for each file processed.
109+ Filters
110+ ^^^^^^^
64111
65- :option: `--ignore-module `
66- Accepts comma separated list of module names. Ignore each of the named
67- module and its submodules (if it is a package). May be given
68- multiple times.
112+ These options may be repeated multiple times.
69113
70- :option: `--ignore-dir `
71- Ignore all modules and packages in the named directory and subdirectories
72- (multiple directories can be joined by os.pathsep). May be given multiple
73- times.
114+ .. program :: trace
74115
116+ .. cmdoption :: --ignore-module=<mod>
117+
118+ Ignore each of the given module names and its submodules (if it is a
119+ package). The argument can be a list of names separated by a comma.
120+
121+ .. cmdoption :: --ignore-dir=<dir>
122+
123+ Ignore all modules and packages in the named directory and subdirectories.
124+ The argument can be a list of directories separated by :data: `os.pathsep `.
75125
76126.. _trace-api :
77127
78- Programming Interface
79- ---------------------
128+ Programmatic Interface
129+ ----------------------
130+
131+ .. class :: Trace(count=1, trace=1, countfuncs=0, countcallers=0, ignoremods=(),\
132+ ignoredirs=(), infile=None, outfile=None, timing=False)
133+
134+ Create an object to trace execution of a single statement or expression. All
135+ parameters are optional. *count * enables counting of line numbers. *trace *
136+ enables line execution tracing. *countfuncs * enables listing of the
137+ functions called during the run. *countcallers * enables call relationship
138+ tracking. *ignoremods * is a list of modules or packages to ignore.
139+ *ignoredirs * is a list of directories whose modules or packages should be
140+ ignored. *infile * is the name of the file from which to read stored count
141+ information. *outfile * is the name of the file in which to write updated
142+ count information. *timing * enables a timestamp relative to when tracing was
143+ started to be displayed.
144+
145+ .. method :: run(cmd)
146+
147+ Execute the command and gather statistics from the execution with
148+ the current tracing parameters. *cmd * must be a string or code object,
149+ suitable for passing into :func: `exec `.
80150
151+ .. method :: runctx(cmd, globals=None, locals=None)
81152
82- .. class :: Trace(count=1, trace=1, countfuncs=0, countcallers=0, ignoremods=(), ignoredirs=(), infile=None, outfile=None, timing=False)
153+ Execute the command and gather statistics from the execution with the
154+ current tracing parameters, in the defined global and local
155+ environments. If not defined, *globals * and *locals * default to empty
156+ dictionaries.
83157
84- Create an object to trace execution of a single statement or expression. All
85- parameters are optional. *count * enables counting of line numbers. *trace *
86- enables line execution tracing. *countfuncs * enables listing of the functions
87- called during the run. *countcallers * enables call relationship tracking.
88- *ignoremods * is a list of modules or packages to ignore. *ignoredirs * is a list
89- of directories whose modules or packages should be ignored. *infile * is the
90- file from which to read stored count information. *outfile * is a file in which
91- to write updated count information. *timing * enables a timestamp relative
92- to when tracing was started to be displayed.
158+ .. method :: runfunc(func, *args, **kwds)
93159
160+ Call *func * with the given arguments under control of the :class: `Trace `
161+ object with the current tracing parameters.
94162
95- .. method :: Trace.run(cmd )
163+ .. method :: results( )
96164
97- Run *cmd * under control of the Trace object with the current tracing parameters.
165+ Return a :class: `CoverageResults ` object that contains the cumulative
166+ results of all previous calls to ``run ``, ``runctx `` and ``runfunc ``
167+ for the given :class: `Trace ` instance. Does not reset the accumulated
168+ trace results.
98169
170+ .. class :: CoverageResults
99171
100- .. method :: Trace.runctx(cmd, globals=None, locals=None)
172+ A container for coverage results, created by :meth: `Trace.results `. Should
173+ not be created directly by the user.
101174
102- Run *cmd * under control of the Trace object with the current tracing parameters
103- in the defined global and local environments. If not defined, *globals * and
104- *locals * default to empty dictionaries.
175+ .. method :: update(other)
105176
177+ Merge in data from another :class: `CoverageResults ` object.
106178
107- .. method :: Trace.runfunc(func, *args, **kwds )
179+ .. method :: write_results(show_missing=True, summary=False, coverdir=None )
108180
109- Call *func * with the given arguments under control of the :class: `Trace ` object
110- with the current tracing parameters.
181+ Write coverage results. Set *show_missing * to show lines that had no
182+ hits. Set *summary * to include in the output the coverage summary per
183+ module. *coverdir * specifies the directory into which the coverage
184+ result files will be output. If ``None ``, the results for each source
185+ file are placed in its directory.
111186
112- This is a simple example showing the use of this module ::
187+ A simple example demonstrating the use of the programmatic interface ::
113188
114189 import sys
115190 import trace
0 commit comments