Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/trace.rst

    r2 r391  
    1 
    21:mod:`trace` --- Trace or track Python statement execution
    32==========================================================
     
    65   :synopsis: Trace or track Python statement execution.
    76
     7**Source code:** :source:`Lib/trace.py`
     8
     9--------------
    810
    911The :mod:`trace` module allows you to trace program execution, generate
     
    1214or from the command line.
    1315
    14 
    1516.. _trace-cli:
    1617
    17 Command Line Usage
     18Command-Line Usage
    1819------------------
    1920
     
    2122simple as ::
    2223
    23    python -m trace --count somefile.py ...
    24 
    25 The above will generate annotated listings of all Python modules imported during
    26 the execution of :file:`somefile.py`.
    27 
    28 The following command-line arguments are supported:
    29 
    30 :option:`--trace`, :option:`-t`
     24   python -m trace --count -C . somefile.py ...
     25
     26The above will execute :file:`somefile.py` and generate annotated listings of
     27all Python modules imported during the execution into the current directory.
     28
     29.. program:: trace
     30
     31.. cmdoption:: --help
     32
     33   Display usage and exit.
     34
     35.. cmdoption:: --version
     36
     37   Display the version of the module and exit.
     38
     39Main options
     40^^^^^^^^^^^^
     41
     42At least one of the following options must be specified when invoking
     43:mod:`trace`.  The :option:`--listfuncs <-l>` option is mutually exclusive with
     44the :option:`--trace <-t>` and :option:`--counts <-c>` options . When
     45:option:`--listfuncs <-l>` is provided, neither :option:`--counts <-c>` nor
     46:option:`--trace <-t>` are accepted, and vice versa.
     47
     48.. program:: trace
     49
     50.. cmdoption:: -c, --count
     51
     52   Produce a set of annotated listing files upon program completion that shows
     53   how many times each statement was executed.  See also
     54   :option:`--coverdir <-C>`, :option:`--file <-f>` and
     55   :option:`--no-report <-R>` below.
     56
     57.. cmdoption:: -t, --trace
     58
    3159   Display lines as they are executed.
    3260
    33 :option:`--count`, :option:`-c`
    34    Produce a set of  annotated listing files upon program completion that shows how
    35    many times each statement was executed.
    36 
    37 :option:`--report`, :option:`-r`
     61.. cmdoption:: -l, --listfuncs
     62
     63   Display the functions executed by running the program.
     64
     65.. cmdoption:: -r, --report
     66
    3867   Produce an annotated list from an earlier program run that used the
    39    :option:`--count` and :option:`--file` arguments.
    40 
    41 :option:`--no-report`, :option:`-R`
     68   :option:`--count <-c>` and :option:`--file <-f>` option.  This does not
     69   execute any code.
     70
     71.. cmdoption:: -T, --trackcalls
     72
     73   Display the calling relationships exposed by running the program.
     74
     75Modifiers
     76^^^^^^^^^
     77
     78.. program:: trace
     79
     80.. cmdoption:: -f, --file=<file>
     81
     82   Name of a file to accumulate counts over several tracing runs.  Should be
     83   used with the :option:`--count <-c>` option.
     84
     85.. cmdoption:: -C, --coverdir=<dir>
     86
     87   Directory where the report files go.  The coverage report for
     88   ``package.module`` is written to file :file:`{dir}/{package}/{module}.cover`.
     89
     90.. cmdoption:: -m, --missing
     91
     92   When generating annotated listings, mark lines which were not executed with
     93   ``>>>>>>``.
     94
     95.. cmdoption:: -s, --summary
     96
     97   When using :option:`--count <-c>` or :option:`--report <-r>`, write a brief
     98   summary to stdout for each file processed.
     99
     100.. cmdoption:: -R, --no-report
     101
    42102   Do not generate annotated listings.  This is useful if you intend to make
    43    several runs with :option:`--count` then produce a single set of annotated
    44    listings at the end.
    45 
    46 :option:`--listfuncs`, :option:`-l`
    47    List the functions executed by running the program.
    48 
    49 :option:`--trackcalls`, :option:`-T`
    50    Generate calling relationships exposed by running the program.
    51 
    52 :option:`--file`, :option:`-f`
    53    Name a file containing (or to contain) counts.
    54 
    55 :option:`--coverdir`, :option:`-C`
    56    Name a directory in which to save annotated listing files.
    57 
    58 :option:`--missing`, :option:`-m`
    59    When generating annotated listings, mark lines which were not executed with
    60    '``>>>>>>``'.
    61 
    62 :option:`--summary`, :option:`-s`
    63    When using :option:`--count` or :option:`--report`, write a brief summary to
    64    stdout for each file processed.
    65 
    66 :option:`--ignore-module`
    67    Accepts comma separated list of module names. Ignore each of the named
    68    module and its submodules (if it is a package).  May be given
    69    multiple times.
    70 
    71 :option:`--ignore-dir`
    72    Ignore all modules and packages in the named directory and subdirectories
    73    (multiple directories can be joined by os.pathsep).  May be given multiple
    74    times.
    75 
     103   several runs with :option:`--count <-c>`, and then produce a single set of
     104   annotated listings at the end.
     105
     106.. cmdoption:: -g, --timing
     107
     108   Prefix each line with the time since the program started.  Only used while
     109   tracing.
     110
     111Filters
     112^^^^^^^
     113
     114These options may be repeated multiple times.
     115
     116.. program:: trace
     117
     118.. cmdoption:: --ignore-module=<mod>
     119
     120   Ignore each of the given module names and its submodules (if it is a
     121   package).  The argument can be a list of names separated by a comma.
     122
     123.. cmdoption:: --ignore-dir=<dir>
     124
     125   Ignore all modules and packages in the named directory and subdirectories.
     126   The argument can be a list of directories separated by :data:`os.pathsep`.
    76127
    77128.. _trace-api:
    78129
    79 Programming Interface
    80 ---------------------
    81 
     130Programmatic Interface
     131----------------------
    82132
    83133.. class:: Trace([count=1[, trace=1[, countfuncs=0[, countcallers=0[, ignoremods=()[, ignoredirs=()[, infile=None[, outfile=None[, timing=False]]]]]]]]])
    84134
    85    Create an object to trace execution of a single statement or expression. All
    86    parameters are optional.  *count* enables counting of line numbers. *trace*
    87    enables line execution tracing.  *countfuncs* enables listing of the functions
    88    called during the run.  *countcallers* enables call relationship tracking.
    89    *ignoremods* is a list of modules or packages to ignore.  *ignoredirs* is a list
    90    of directories whose modules or packages should be ignored.  *infile* is the
    91    file from which to read stored count information.  *outfile* is a file in which
    92    to write updated count information. *timing* enables a timestamp relative
    93    to when tracing was started to be displayed.
    94 
    95 
    96 .. method:: Trace.run(cmd)
    97 
    98    Run *cmd* under control of the Trace object with the current tracing parameters.
    99 
    100 
    101 .. method:: Trace.runctx(cmd[, globals=None[, locals=None]])
    102 
    103    Run *cmd* under control of the Trace object with the current tracing parameters
    104    in the defined global and local environments.  If not defined, *globals* and
    105    *locals* default to empty dictionaries.
    106 
    107 
    108 .. method:: Trace.runfunc(func, *args, **kwds)
    109 
    110    Call *func* with the given arguments under control of the :class:`Trace` object
    111    with the current tracing parameters.
    112 
    113 This is a simple example showing the use of this module::
     135   Create an object to trace execution of a single statement or expression.  All
     136   parameters are optional.  *count* enables counting of line numbers.  *trace*
     137   enables line execution tracing.  *countfuncs* enables listing of the
     138   functions called during the run.  *countcallers* enables call relationship
     139   tracking.  *ignoremods* is a list of modules or packages to ignore.
     140   *ignoredirs* is a list of directories whose modules or packages should be
     141   ignored.  *infile* is the name of the file from which to read stored count
     142   information.  *outfile* is the name of the file in which to write updated
     143   count information.  *timing* enables a timestamp relative to when tracing was
     144   started to be displayed.
     145
     146    .. method:: run(cmd)
     147
     148       Execute the command and gather statistics from the execution with
     149       the current tracing parameters.  *cmd* must be a string or code object,
     150       suitable for passing into :func:`exec`.
     151
     152    .. method:: runctx(cmd, globals=None, locals=None)
     153
     154       Execute the command and gather statistics from the execution with the
     155       current tracing parameters, in the defined global and local
     156       environments.  If not defined, *globals* and *locals* default to empty
     157       dictionaries.
     158
     159    .. method:: runfunc(func, *args, **kwds)
     160
     161       Call *func* with the given arguments under control of the :class:`Trace`
     162       object with the current tracing parameters.
     163
     164    .. method:: results()
     165
     166       Return a :class:`CoverageResults` object that contains the cumulative
     167       results of all previous calls to ``run``, ``runctx`` and ``runfunc``
     168       for the given :class:`Trace` instance.  Does not reset the accumulated
     169       trace results.
     170
     171.. class:: CoverageResults
     172
     173   A container for coverage results, created by :meth:`Trace.results`.  Should
     174   not be created directly by the user.
     175
     176    .. method:: update(other)
     177
     178       Merge in data from another :class:`CoverageResults` object.
     179
     180    .. method:: write_results([show_missing=True[, summary=False[, coverdir=None]]])
     181
     182       Write coverage results.  Set *show_missing* to show lines that had no
     183       hits.  Set *summary* to include in the output the coverage summary per
     184       module.  *coverdir* specifies the directory into which the coverage
     185       result files will be output.  If ``None``, the results for each source
     186       file are placed in its directory.
     187
     188A simple example demonstrating the use of the programmatic interface::
    114189
    115190   import sys
     
    126201   tracer.run('main()')
    127202
    128    # make a report, placing output in /tmp
     203   # make a report, placing output in the current directory
    129204   r = tracer.results()
    130    r.write_results(show_missing=True, coverdir="/tmp")
    131 
     205   r.write_results(show_missing=True, coverdir=".")
     206
Note: See TracChangeset for help on using the changeset viewer.