diff options
author | Beomsoo Kim <bluewhale8202@gmail.com> | 2018-12-16 19:34:08 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2018-12-16 19:34:08 (GMT) |
commit | b912f9342e7a37d170ba659c13c959115c11545a (patch) | |
tree | ec99f5147d0c42df360952381b0184540cbc3c08 /Doc/library/resource.rst | |
parent | 640ed520dd6a43a8bf470b79542f58b5d57af9de (diff) | |
download | cpython-b912f9342e7a37d170ba659c13c959115c11545a.zip cpython-b912f9342e7a37d170ba659c13c959115c11545a.tar.gz cpython-b912f9342e7a37d170ba659c13c959115c11545a.tar.bz2 |
bpo-35511: Trivial docs updates for profile and resource library modules. (GH-11124)
polish documentation for profile and resource modules
Diffstat (limited to 'Doc/library/resource.rst')
-rw-r--r-- | Doc/library/resource.rst | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/Doc/library/resource.rst b/Doc/library/resource.rst index bd49c87..2ed15c1 100644 --- a/Doc/library/resource.rst +++ b/Doc/library/resource.rst @@ -261,6 +261,20 @@ These functions are used to retrieve resource usage information: *who* parameter should be specified using one of the :const:`RUSAGE_\*` constants described below. + A simple example:: + + from resource import * + import time + + # a non CPU-bound task + time.sleep(3) + print(getrusage(RUSAGE_SELF)) + + # a CPU-bound task + for i in range(10 ** 8): + _ = 1 + 1 + print(getrusage(RUSAGE_SELF)) + The fields of the return value each describe how a particular system resource has been used, e.g. amount of time spent running is user mode or number of times 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: remaining values are integers. Consult the :manpage:`getrusage(2)` man page for detailed information about these values. A brief summary is presented here: - +--------+---------------------+-------------------------------+ - | Index | Field | Resource | - +========+=====================+===============================+ - | ``0`` | :attr:`ru_utime` | time in user mode (float) | - +--------+---------------------+-------------------------------+ - | ``1`` | :attr:`ru_stime` | time in system mode (float) | - +--------+---------------------+-------------------------------+ - | ``2`` | :attr:`ru_maxrss` | maximum resident set size | - +--------+---------------------+-------------------------------+ - | ``3`` | :attr:`ru_ixrss` | shared memory size | - +--------+---------------------+-------------------------------+ - | ``4`` | :attr:`ru_idrss` | unshared memory size | - +--------+---------------------+-------------------------------+ - | ``5`` | :attr:`ru_isrss` | unshared stack size | - +--------+---------------------+-------------------------------+ - | ``6`` | :attr:`ru_minflt` | page faults not requiring I/O | - +--------+---------------------+-------------------------------+ - | ``7`` | :attr:`ru_majflt` | page faults requiring I/O | - +--------+---------------------+-------------------------------+ - | ``8`` | :attr:`ru_nswap` | number of swap outs | - +--------+---------------------+-------------------------------+ - | ``9`` | :attr:`ru_inblock` | block input operations | - +--------+---------------------+-------------------------------+ - | ``10`` | :attr:`ru_oublock` | block output operations | - +--------+---------------------+-------------------------------+ - | ``11`` | :attr:`ru_msgsnd` | messages sent | - +--------+---------------------+-------------------------------+ - | ``12`` | :attr:`ru_msgrcv` | messages received | - +--------+---------------------+-------------------------------+ - | ``13`` | :attr:`ru_nsignals` | signals received | - +--------+---------------------+-------------------------------+ - | ``14`` | :attr:`ru_nvcsw` | voluntary context switches | - +--------+---------------------+-------------------------------+ - | ``15`` | :attr:`ru_nivcsw` | involuntary context switches | - +--------+---------------------+-------------------------------+ + +--------+---------------------+---------------------------------------+ + | Index | Field | Resource | + +========+=====================+=======================================+ + | ``0`` | :attr:`ru_utime` | time in user mode (float seconds) | + +--------+---------------------+---------------------------------------+ + | ``1`` | :attr:`ru_stime` | time in system mode (float seconds) | + +--------+---------------------+---------------------------------------+ + | ``2`` | :attr:`ru_maxrss` | maximum resident set size | + +--------+---------------------+---------------------------------------+ + | ``3`` | :attr:`ru_ixrss` | shared memory size | + +--------+---------------------+---------------------------------------+ + | ``4`` | :attr:`ru_idrss` | unshared memory size | + +--------+---------------------+---------------------------------------+ + | ``5`` | :attr:`ru_isrss` | unshared stack size | + +--------+---------------------+---------------------------------------+ + | ``6`` | :attr:`ru_minflt` | page faults not requiring I/O | + +--------+---------------------+---------------------------------------+ + | ``7`` | :attr:`ru_majflt` | page faults requiring I/O | + +--------+---------------------+---------------------------------------+ + | ``8`` | :attr:`ru_nswap` | number of swap outs | + +--------+---------------------+---------------------------------------+ + | ``9`` | :attr:`ru_inblock` | block input operations | + +--------+---------------------+---------------------------------------+ + | ``10`` | :attr:`ru_oublock` | block output operations | + +--------+---------------------+---------------------------------------+ + | ``11`` | :attr:`ru_msgsnd` | messages sent | + +--------+---------------------+---------------------------------------+ + | ``12`` | :attr:`ru_msgrcv` | messages received | + +--------+---------------------+---------------------------------------+ + | ``13`` | :attr:`ru_nsignals` | signals received | + +--------+---------------------+---------------------------------------+ + | ``14`` | :attr:`ru_nvcsw` | voluntary context switches | + +--------+---------------------+---------------------------------------+ + | ``15`` | :attr:`ru_nivcsw` | involuntary context switches | + +--------+---------------------+---------------------------------------+ This function will raise a :exc:`ValueError` if an invalid *who* parameter is specified. It may also raise :exc:`error` exception in unusual circumstances. |