@@ -261,6 +261,20 @@ These functions are used to retrieve resource usage information:
261
261
*who * parameter should be specified using one of the :const: `RUSAGE_\* `
262
262
constants described below.
263
263
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
+
264
278
The fields of the return value each describe how a particular system resource
265
279
has been used, e.g. amount of time spent running is user mode or number of times
266
280
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:
275
289
remaining values are integers. Consult the :manpage: `getrusage(2)` man page for
276
290
detailed information about these values. A brief summary is presented here:
277
291
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
+ +--------+---------------------+--------------------------------------- +
313
327
314
328
This function will raise a :exc: `ValueError ` if an invalid *who * parameter is
315
329
specified. It may also raise :exc: `error ` exception in unusual circumstances.
0 commit comments