From 2cea6bfb9c81d1c01ca647aafe36f21f418cef2a Mon Sep 17 00:00:00 2001 From: Apostol Fet Date: Wed, 19 Feb 2025 21:26:56 +0300 Subject: [PATCH 1/5] use .. program:: directive for documenting cProfile CLI --- Doc/library/profile.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index 3334833eba6b8c..a0f4e1ef5be1d1 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -122,18 +122,25 @@ The :class:`pstats.Stats` class reads profile results from a file and formats them in various ways. .. _profile-cli: +.. program:: cProfile The files :mod:`cProfile` and :mod:`profile` can also be invoked as a script to profile another script. For example:: python -m cProfile [-o output_file] [-s sort_order] (-m module | myscript.py) -``-o`` writes the profile results to a file instead of to stdout +.. option:: -o -``-s`` specifies one of the :func:`~pstats.Stats.sort_stats` sort values to sort -the output by. This only applies when ``-o`` is not supplied. + Writes the profile results to a file instead of to stdout. -``-m`` specifies that a module is being profiled instead of a script. +.. option:: -s + + Specifies one of the :func:`~pstats.Stats.sort_stats` sort values to sort + the output by. This only applies when ``-o`` is not supplied. + +.. option:: -m + + Specifies that a module is being profiled instead of a script. .. versionadded:: 3.7 Added the ``-m`` option to :mod:`cProfile`. From 77003de7c6277ebb2a1af2c6f1d5ffc23b9efcd5 Mon Sep 17 00:00:00 2001 From: Apostol Fet <90645107+ApostolFet@users.noreply.github.com> Date: Thu, 20 Feb 2025 06:32:30 +0000 Subject: [PATCH 2/5] Move versionadded in -m section --- Doc/library/profile.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index a0f4e1ef5be1d1..02d0189973858a 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -142,11 +142,11 @@ profile another script. For example:: Specifies that a module is being profiled instead of a script. -.. versionadded:: 3.7 - Added the ``-m`` option to :mod:`cProfile`. + .. versionadded:: 3.7 + Added the ``-m`` option to :mod:`cProfile`. -.. versionadded:: 3.8 - Added the ``-m`` option to :mod:`profile`. + .. versionadded:: 3.8 + Added the ``-m`` option to :mod:`profile`. The :mod:`pstats` module's :class:`~pstats.Stats` class has a variety of methods for manipulating and printing the data saved into a profile results file:: From cd6d47b5f12ae6b7755d69e67876162b7ce8086f Mon Sep 17 00:00:00 2001 From: Apostol Fet <90645107+ApostolFet@users.noreply.github.com> Date: Fri, 21 Feb 2025 17:14:49 +0300 Subject: [PATCH 3/5] Update Doc/library/profile.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/profile.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index 02d0189973858a..573f0a53430715 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -136,7 +136,7 @@ profile another script. For example:: .. option:: -s Specifies one of the :func:`~pstats.Stats.sort_stats` sort values to sort - the output by. This only applies when ``-o`` is not supplied. + the output by. This only applies when :option:`-o ` is not supplied. .. option:: -m From ab125ed61dd6223a939dfb6deb0a2667bcf4ea4f Mon Sep 17 00:00:00 2001 From: Apostol Fet <90645107+ApostolFet@users.noreply.github.com> Date: Sun, 23 Feb 2025 11:05:23 +0300 Subject: [PATCH 4/5] Update Doc/library/profile.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/library/profile.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index 573f0a53430715..e12950b5ab096e 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -135,8 +135,9 @@ profile another script. For example:: .. option:: -s - Specifies one of the :func:`~pstats.Stats.sort_stats` sort values to sort - the output by. This only applies when :option:`-o ` is not supplied. + Specifies one of the :func:`~pstats.Stats.sort_stats` sort values + to sort the output by. + This only applies when :option:`-o ` is not supplied. .. option:: -m From 5ab85db8f291db3044b26f829e5fbec3a9982a84 Mon Sep 17 00:00:00 2001 From: Apostol Fet <90645107+ApostolFet@users.noreply.github.com> Date: Sun, 23 Feb 2025 11:05:35 +0300 Subject: [PATCH 5/5] Update Doc/library/profile.rst Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Doc/library/profile.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst index e12950b5ab096e..b6e51dffc40157 100644 --- a/Doc/library/profile.rst +++ b/Doc/library/profile.rst @@ -122,6 +122,7 @@ The :class:`pstats.Stats` class reads profile results from a file and formats them in various ways. .. _profile-cli: + .. program:: cProfile The files :mod:`cProfile` and :mod:`profile` can also be invoked as a script to