| 1 |
:mod:`sphinx.ext.duration` -- Measure durations of Sphinx processing |
| 2 |
==================================================================== |
| 3 |
|
| 4 |
.. module:: sphinx.ext.duration |
| 5 |
:synopsis: Measure durations of Sphinx processing |
| 6 |
|
| 7 |
.. versionadded:: 2.4 |
| 8 |
|
| 9 |
This extension measures durations of Sphinx processing when reading |
| 10 |
documents and is useful for inspecting what document is slowly built. |
| 11 |
Durations are printed to console at the end of the build and saved |
| 12 |
to a JSON file in the output directory by default. |
| 13 |
|
| 14 |
Enable this extension by adding ``'sphinx.ext.duration'`` to |
| 15 |
the :confval:`extensions` list in your :file:`conf.py`: |
| 16 |
|
| 17 |
.. code-block:: python |
| 18 |
|
| 19 |
extensions = [ |
| 20 |
... |
| 21 |
'sphinx.ext.duration', |
| 22 |
] |
| 23 |
|
| 24 |
|
| 25 |
Configuration |
| 26 |
------------- |
| 27 |
|
| 28 |
.. confval:: duration_print_total |
| 29 |
:type: :code-py:`bool` |
| 30 |
:default: :code-py:`True` |
| 31 |
|
| 32 |
Show the total reading duration in the build summary, e.g.: |
| 33 |
|
| 34 |
.. code-block:: text |
| 35 |
|
| 36 |
====================== total reading duration ========================== |
| 37 |
Total time reading 31 files: 0m 3.142s |
| 38 |
|
| 39 |
.. versionadded:: 9.0 |
| 40 |
|
| 41 |
.. confval:: duration_print_slowest |
| 42 |
:type: :code-py:`bool` |
| 43 |
:default: :code-py:`True` |
| 44 |
|
| 45 |
Show the slowest durations in the build summary. |
| 46 |
The durations are sorted in order from slowest to fastest. |
| 47 |
This prints up to :confval:`duration_n_slowest` durations, e.g.: |
| 48 |
|
| 49 |
.. code-block:: text |
| 50 |
|
| 51 |
====================== slowest 5 reading durations ======================= |
| 52 |
0.012s spam |
| 53 |
0.011s ham |
| 54 |
0.011s eggs |
| 55 |
0.006s lobster |
| 56 |
0.005s beans |
| 57 |
|
| 58 |
.. versionadded:: 9.0 |
| 59 |
|
| 60 |
.. confval:: duration_n_slowest |
| 61 |
:type: :code-py:`int` |
| 62 |
:default: :code-py:`5` |
| 63 |
|
| 64 |
Maximum number of slowest durations to show in the build summary |
| 65 |
when :confval:`duration_print_slowest` is enabled. |
| 66 |
By default, only the ``5`` slowest durations are shown. |
| 67 |
Set this to ``0`` to show all durations. |
| 68 |
|
| 69 |
.. versionadded:: 9.0 |
| 70 |
|
| 71 |
.. confval:: duration_write_json |
| 72 |
:type: :code-py:`str | None` |
| 73 |
:default: :code-py:`'sphinx-reading-durations.json'` |
| 74 |
|
| 75 |
Write all reading durations to a JSON file in the output directory |
| 76 |
The file contents are a map of the document names to reading durations, |
| 77 |
where document names are strings and durations are floats in seconds. |
| 78 |
Set this value to an empty string or ``None`` to disable writing the file, |
| 79 |
or set it to a relative path to customize it. |
| 80 |
|
| 81 |
This may be useful for testing and setting a limit on reading times. |
| 82 |
|
| 83 |
.. versionadded:: 9.0 |
| 84 |
|
| 85 |
.. confval:: duration_limit |
| 86 |
:type: :code-py:`float | int | None` |
| 87 |
:default: :code-py:`None` |
| 88 |
|
| 89 |
Set a duration limit (in seconds) for reading a document. |
| 90 |
If any duration exceeds this value, a warning is emitted. |
| 91 |
|
| 92 |
.. versionadded:: 9.0 |