This module in python provides basic mechanisms for measuring and controlling system resources utilized by a program. And symbolic constants are used to specify particular system resources and to request usage information about either the current process or its children. If there is a syscall failure, the OSError is raised.
Resource Usage:
These are some functions in the resource library of python which is used to retrieve resource usage information.
resource.getrusage(who):
This function returns an object that describes the resources consumed by either the current process or its children as specified by the 'who' parameter. 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
For backward compatibility, the return value is also accessible as a tuple of 16 elements.
INDEX FIELD RESOURCE
0 ru_utime time in user mode(float seconds)
1 ru_stime time in system mode (float seconds)
2 ru_maxrss maximum resident set size
3 ru_ixrss shared memory size
4 ru_idrss unshared memory size
5 ru_isrss unshared stack size
6 ru_minflt page faults not requiring I/O
7 ru_majflt page faults requiring I/O
8 ru_nswap number of swap outs
9 ru_inblock block input operations
10 ru_oublock block output operations
11 ru_msgsnd messages sent
12 ru_msgrcv messages received
13 ru_nsignals signals received
14 ru_nvcsw voluntary context switches
15 re_nivcsw involuntary context switches
This function will raise a ValueError if an invalid who parameter is specified. It may also raise error exception in unusual circumstances.
resource.getpagesize():
This function returns the number of bytes in a system page.
A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in the page table. It is the smallest unit of data for memory management in a virtual memory operating system.
Comments