Skip to content

Commit 0e56350

Browse files
committed
Doc updates
kernprof.py - Fixed broken link to `@line_profiler.profile` (or `line_profiler.explicit_profiler.GlobalProfiler`) - Suppressed link for the `-v` flag which linked to some nonsense line_profiler/__init__.py - Added anchor to section `Line Profiler Basic Usage` - Replaced inlines with the appropriate roles - Fixed broken link to `@line_profiler.profile` - Fixed accidentally uncommented TODO
1 parent c9e767a commit 0e56350

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

kernprof.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
circumstances.
55
66
To profile a script, decorate the functions of interest with
7-
:py:deco:`profile`:
7+
:py:deco:`profile <line_profiler.explicit_profiler.GlobalProfiler>`:
88
99
.. code:: bash
1010
@@ -19,25 +19,27 @@ def main():
1919
2020
New in 4.1.0: Instead of relying on injecting :py:deco:`profile`
2121
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.
2527
2628
27-
Then run the script using :command:`kernprof`:
29+
Then run the script using :program:`kernprof`:
2830
2931
.. code:: bash
3032
3133
kernprof -b script_to_profile.py
3234
3335
By default this runs with the default :py:mod:`cProfile` profiler and
3436
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
3638
command line will write results to stdout.
3739
3840
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:
4143
4244
.. code:: bash
4345
@@ -49,19 +51,19 @@ def main():
4951
5052
* :command:`kernprof <options> -m some.module <args to module>`
5153
parallels :command:`python -m` and runs the provided module as
52-
``__main__``.
54+
:py:mod:`__main__`.
5355
* :command:`kernprof <options> -c "some code" <args to code>`
5456
parallels :command:`python -c` and executes the provided literal
5557
code.
5658
* :command:`kernprof <options> - <args to code>` parallels
5759
:command:`python -` and executes literal code passed via the
58-
``stdin``.
60+
:file:`stdin`.
5961
6062
See also
6163
:doc:`kernprof invocations </manual/examples/example_kernprof>`.
6264
6365
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:
6567
6668
.. code:: bash
6769
@@ -106,12 +108,12 @@ def main():
106108
NOTE:
107109
108110
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)
110112
are now eagerly pre-imported to be profiled
111113
(see :py:mod:`line_profiler.autoprofile.eager_preimports`),
112114
regardless of whether those imports directly occur in the profiled
113115
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`
115117
flag.
116118
"""
117119
import builtins
@@ -265,7 +267,7 @@ def _python_command():
265267

266268
def _normalize_profiling_targets(targets):
267269
"""
268-
Normalize the parsed :option:`--prof-mod` by:
270+
Normalize the parsed :option:`!--prof-mod` by:
269271
270272
* Normalizing file paths with :py:func:`find_script()`, and
271273
subsequently to absolute paths.
@@ -338,7 +340,7 @@ def wrapper(*args, **kwargs):
338340
def pre_parse_single_arg_directive(args, flag, sep='--'):
339341
"""
340342
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
342344
:command:`python [...]`.
343345
344346
Examples

line_profiler/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
pip install line_profiler[all]
3434
3535
36+
.. _line-profiler-basic-usage:
37+
3638
Line Profiler Basic Usage
3739
=========================
3840
3941
To demonstrate line profiling, we first need to generate a Python script to
40-
profile. Write the following code to a file called ``demo_primes.py``.
42+
profile. Write the following code to a file called :file:`demo_primes.py`:
4143
4244
.. code:: python
4345
@@ -80,8 +82,10 @@ def main():
8082
main()
8183
8284
83-
In this script we explicitly import the ``profile`` function from
84-
``line_profiler``, and then we decorate function of interest with ``@profile``.
85+
In this script we explicitly import the
86+
:py:deco:`profile <line_profiler.explicit_profiler.GlobalProfiler>` function
87+
from :py:mod:`line_profiler`, and then we decorate function of interest with
88+
:py:deco:`profile`.
8589
8690
By default nothing is profiled when running the script.
8791
@@ -99,17 +103,18 @@ def main():
99103
100104
101105
The quickest way to enable profiling is to set the environment variable
102-
``LINE_PROFILE=1`` and running your script as normal.
103-
104-
.... todo: add a link that points to docs showing all the different ways to enable profiling.
106+
:envvar:`LINE_PROFILE=1 <LINE_PROFILE>` and running your script as normal.
105107
108+
.. .. todo: add a link that points to docs showing all the different ways to
109+
.. .. to enable profiling.
106110
107111
.. code:: bash
108112
109113
LINE_PROFILE=1 python demo_primes.py
110114
111-
This will output 3 files: profile_output.txt, profile_output_<timestamp>.txt,
112-
and profile_output.lprof and stdout will look something like:
115+
This will output 3 files: :file:`profile_output.txt`,
116+
:file:`profile_output_<timestamp>.txt`, and :file:`profile_output.lprof`; and
117+
:file:`stdout` will look something like:
113118
114119
115120
.. code::
@@ -219,7 +224,7 @@ def main():
219224
220225
* `timeit <https://docs.python.org/3/library/timeit.html>`_: The builtin timeit module for profiling single statements.
221226
222-
* `timerit <https://github.com/Erotemic/timerit>`_: A multi-statements alternative to the builtin ``timeit`` module.
227+
* `timerit <https://github.com/Erotemic/timerit>`_: A multi-statements alternative to the builtin :py:mod:`timeit` module.
223228
224229
* `torch.profiler <https://pytorch.org/docs/stable/profiler.html>`_ tools for profiling torch code.
225230

0 commit comments

Comments
 (0)