4
4
circumstances.
5
5
6
6
To profile a script, decorate the functions of interest with
7
- :py:deco:`profile`:
7
+ :py:deco:`profile <line_profiler.explicit_profiler.GlobalProfiler> `:
8
8
9
9
.. code:: bash
10
10
@@ -19,25 +19,27 @@ def main():
19
19
20
20
New in 4.1.0: Instead of relying on injecting :py:deco:`profile`
21
21
into the builtins you can now ``import line_profiler`` and use
22
- :py:deco:`line_profiler.profile` to decorate your functions. This
23
- allows the script to remain functional even if it is not actively
24
- profiled. See :py:mod:`line_profiler` for details.
22
+ :py:deco:`line_profiler.profile <line_profiler.explicit_profiler.GlobalProfiler>`
23
+ to decorate your functions. This allows the script to remain
24
+ functional even if it is not actively profiled. See
25
+ :py:mod:`!line_profiler` (:ref:`link <line-profiler-basic-usage>`) for
26
+ details.
25
27
26
28
27
- Then run the script using :command :`kernprof`:
29
+ Then run the script using :program :`kernprof`:
28
30
29
31
.. code:: bash
30
32
31
33
kernprof -b script_to_profile.py
32
34
33
35
By default this runs with the default :py:mod:`cProfile` profiler and
34
36
does not require compiled modules. Instructions to view the results will
35
- be given in the output. Alternatively, adding :option:`-v` to the
37
+ be given in the output. Alternatively, adding :option:`! -v` to the
36
38
command line will write results to stdout.
37
39
38
40
To enable line-by-line profiling, :py:mod:`line_profiler` must be
39
- available and compiled, and the :option:`-l` argument should be added to
40
- the :command :`kernprof` invocation:
41
+ available and compiled, and the :option:`! -l` argument should be added to
42
+ the :program :`kernprof` invocation:
41
43
42
44
.. code:: bash
43
45
@@ -49,19 +51,19 @@ def main():
49
51
50
52
* :command:`kernprof <options> -m some.module <args to module>`
51
53
parallels :command:`python -m` and runs the provided module as
52
- `` __main__` `.
54
+ :py:mod:` __main__`.
53
55
* :command:`kernprof <options> -c "some code" <args to code>`
54
56
parallels :command:`python -c` and executes the provided literal
55
57
code.
56
58
* :command:`kernprof <options> - <args to code>` parallels
57
59
:command:`python -` and executes literal code passed via the
58
- `` stdin` `.
60
+ :file:` stdin`.
59
61
60
62
See also
61
63
:doc:`kernprof invocations </manual/examples/example_kernprof>`.
62
64
63
65
For more details and options, refer to the CLI help.
64
- To view :command :`kernprof` help run:
66
+ To view the :program :`kernprof` help text run:
65
67
66
68
.. code:: bash
67
69
@@ -106,12 +108,12 @@ def main():
106
108
NOTE:
107
109
108
110
New in 4.3.0: For more intuitive profiling behavior, profiling
109
- targets in :option:`--prof-mod` (except the profiled script/code)
111
+ targets in :option:`! --prof-mod` (except the profiled script/code)
110
112
are now eagerly pre-imported to be profiled
111
113
(see :py:mod:`line_profiler.autoprofile.eager_preimports`),
112
114
regardless of whether those imports directly occur in the profiled
113
115
script/module/code.
114
- To restore the old behavior, pass the :option:`--no-preimports`
116
+ To restore the old behavior, pass the :option:`! --no-preimports`
115
117
flag.
116
118
"""
117
119
import builtins
@@ -265,7 +267,7 @@ def _python_command():
265
267
266
268
def _normalize_profiling_targets (targets ):
267
269
"""
268
- Normalize the parsed :option:`--prof-mod` by:
270
+ Normalize the parsed :option:`! --prof-mod` by:
269
271
270
272
* Normalizing file paths with :py:func:`find_script()`, and
271
273
subsequently to absolute paths.
@@ -338,7 +340,7 @@ def wrapper(*args, **kwargs):
338
340
def pre_parse_single_arg_directive (args , flag , sep = '--' ):
339
341
"""
340
342
Pre-parse high-priority single-argument directives like
341
- :option:`-m module` to emulate the behavior of
343
+ :option:`! -m module` to emulate the behavior of
342
344
:command:`python [...]`.
343
345
344
346
Examples
0 commit comments