Skip to content

Commit b912f93

Browse files
bombs-kimasvetlov
authored andcommitted
bpo-35511: Trivial docs updates for profile and resource library modules. (GH-11124)
polish documentation for profile and resource modules
1 parent 640ed52 commit b912f93

File tree

3 files changed

+59
-42
lines changed

3 files changed

+59
-42
lines changed

Doc/library/profile.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ functions:
265265
ps.print_stats()
266266
print(s.getvalue())
267267

268-
The :class:`Profile` class can also be used as a context manager (see
269-
:ref:`typecontextmanager`)::
268+
The :class:`Profile` class can also be used as a context manager (supported
269+
only in :mod:`cProfile` module. see :ref:`typecontextmanager`)::
270270

271271
import cProfile
272272

@@ -280,11 +280,11 @@ functions:
280280

281281
.. method:: enable()
282282

283-
Start collecting profiling data.
283+
Start collecting profiling data. Only in :mod:`cProfile`.
284284

285285
.. method:: disable()
286286

287-
Stop collecting profiling data.
287+
Stop collecting profiling data. Only in :mod:`cProfile`.
288288

289289
.. method:: create_stats()
290290

@@ -540,9 +540,9 @@ less overhead (as the code does not need to be instrumented), but provides only
540540
relative indications of where time is being spent.
541541

542542
In Python, since there is an interpreter active during execution, the presence
543-
of instrumented code is not required to do deterministic profiling. Python
544-
automatically provides a :dfn:`hook` (optional callback) for each event. In
545-
addition, the interpreted nature of Python tends to add so much overhead to
543+
of instrumented code is not required in order to do deterministic profiling.
544+
Python automatically provides a :dfn:`hook` (optional callback) for each event.
545+
In addition, the interpreted nature of Python tends to add so much overhead to
546546
execution, that deterministic profiling tends to only add small processing
547547
overhead in typical applications. The result is that deterministic profiling is
548548
not that expensive, yet provides extensive run time statistics about the

Doc/library/resource.rst

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ These functions are used to retrieve resource usage information:
261261
*who* parameter should be specified using one of the :const:`RUSAGE_\*`
262262
constants described below.
263263

264+
A simple example::
265+
266+
from resource import *
267+
import time
268+
269+
# a non CPU-bound task
270+
time.sleep(3)
271+
print(getrusage(RUSAGE_SELF))
272+
273+
# a CPU-bound task
274+
for i in range(10 ** 8):
275+
_ = 1 + 1
276+
print(getrusage(RUSAGE_SELF))
277+
264278
The fields of the return value each describe how a particular system resource
265279
has been used, e.g. amount of time spent running is user mode or number of times
266280
the process was swapped out of main memory. Some values are dependent on the
@@ -275,41 +289,41 @@ These functions are used to retrieve resource usage information:
275289
remaining values are integers. Consult the :manpage:`getrusage(2)` man page for
276290
detailed information about these values. A brief summary is presented here:
277291

278-
+--------+---------------------+-------------------------------+
279-
| Index | Field | Resource |
280-
+========+=====================+===============================+
281-
| ``0`` | :attr:`ru_utime` | time in user mode (float) |
282-
+--------+---------------------+-------------------------------+
283-
| ``1`` | :attr:`ru_stime` | time in system mode (float) |
284-
+--------+---------------------+-------------------------------+
285-
| ``2`` | :attr:`ru_maxrss` | maximum resident set size |
286-
+--------+---------------------+-------------------------------+
287-
| ``3`` | :attr:`ru_ixrss` | shared memory size |
288-
+--------+---------------------+-------------------------------+
289-
| ``4`` | :attr:`ru_idrss` | unshared memory size |
290-
+--------+---------------------+-------------------------------+
291-
| ``5`` | :attr:`ru_isrss` | unshared stack size |
292-
+--------+---------------------+-------------------------------+
293-
| ``6`` | :attr:`ru_minflt` | page faults not requiring I/O |
294-
+--------+---------------------+-------------------------------+
295-
| ``7`` | :attr:`ru_majflt` | page faults requiring I/O |
296-
+--------+---------------------+-------------------------------+
297-
| ``8`` | :attr:`ru_nswap` | number of swap outs |
298-
+--------+---------------------+-------------------------------+
299-
| ``9`` | :attr:`ru_inblock` | block input operations |
300-
+--------+---------------------+-------------------------------+
301-
| ``10`` | :attr:`ru_oublock` | block output operations |
302-
+--------+---------------------+-------------------------------+
303-
| ``11`` | :attr:`ru_msgsnd` | messages sent |
304-
+--------+---------------------+-------------------------------+
305-
| ``12`` | :attr:`ru_msgrcv` | messages received |
306-
+--------+---------------------+-------------------------------+
307-
| ``13`` | :attr:`ru_nsignals` | signals received |
308-
+--------+---------------------+-------------------------------+
309-
| ``14`` | :attr:`ru_nvcsw` | voluntary context switches |
310-
+--------+---------------------+-------------------------------+
311-
| ``15`` | :attr:`ru_nivcsw` | involuntary context switches |
312-
+--------+---------------------+-------------------------------+
292+
+--------+---------------------+---------------------------------------+
293+
| Index | Field | Resource |
294+
+========+=====================+=======================================+
295+
| ``0`` | :attr:`ru_utime` | time in user mode (float seconds) |
296+
+--------+---------------------+---------------------------------------+
297+
| ``1`` | :attr:`ru_stime` | time in system mode (float seconds) |
298+
+--------+---------------------+---------------------------------------+
299+
| ``2`` | :attr:`ru_maxrss` | maximum resident set size |
300+
+--------+---------------------+---------------------------------------+
301+
| ``3`` | :attr:`ru_ixrss` | shared memory size |
302+
+--------+---------------------+---------------------------------------+
303+
| ``4`` | :attr:`ru_idrss` | unshared memory size |
304+
+--------+---------------------+---------------------------------------+
305+
| ``5`` | :attr:`ru_isrss` | unshared stack size |
306+
+--------+---------------------+---------------------------------------+
307+
| ``6`` | :attr:`ru_minflt` | page faults not requiring I/O |
308+
+--------+---------------------+---------------------------------------+
309+
| ``7`` | :attr:`ru_majflt` | page faults requiring I/O |
310+
+--------+---------------------+---------------------------------------+
311+
| ``8`` | :attr:`ru_nswap` | number of swap outs |
312+
+--------+---------------------+---------------------------------------+
313+
| ``9`` | :attr:`ru_inblock` | block input operations |
314+
+--------+---------------------+---------------------------------------+
315+
| ``10`` | :attr:`ru_oublock` | block output operations |
316+
+--------+---------------------+---------------------------------------+
317+
| ``11`` | :attr:`ru_msgsnd` | messages sent |
318+
+--------+---------------------+---------------------------------------+
319+
| ``12`` | :attr:`ru_msgrcv` | messages received |
320+
+--------+---------------------+---------------------------------------+
321+
| ``13`` | :attr:`ru_nsignals` | signals received |
322+
+--------+---------------------+---------------------------------------+
323+
| ``14`` | :attr:`ru_nvcsw` | voluntary context switches |
324+
+--------+---------------------+---------------------------------------+
325+
| ``15`` | :attr:`ru_nivcsw` | involuntary context switches |
326+
+--------+---------------------+---------------------------------------+
313327

314328
This function will raise a :exc:`ValueError` if an invalid *who* parameter is
315329
specified. It may also raise :exc:`error` exception in unusual circumstances.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Specified that profile.Profile class doesn't not support enable or disable
2+
methods. Also, elaborated that Profile object as a context manager is only
3+
supported in cProfile module.

0 commit comments

Comments
 (0)