API watchio
class WatchIO
- Process IO watcher.
__init__ (self, pids: list = None, *, timeout: float = 600, step: float = 1, check=False)
-
Constructor for WatchIO, call with keyword arguments.
pids is a list of process PIDs to watch. Non-valid PIDs are silently ignored unless
check
is enabled.timeout sets the default timeout value for the poll() method.
step sets the default step value, the interval we check the /proc/{pid}/io file, in seconds for the poll() method.
check raises exceptions (PermissionError if not accessible or FileNotFoundError for non-existent process) instead of silently ignoring bad pids by default.
find_pids (self, name: str) -> list
- Get a list of PIDs by name. Name can be a numerical pid or the name of the process. Returns a (possibly empty) list.
get_io_data (self, pid: int) -> dict
-
Get IO data of the
pid
process. The method reads and parses the file "/proc/{pid}/io" and returns a dictionary with values in int. See https://www.kernel.org/doc/html/latest/filesystems/proc.html#proc-pid-io-display-the-io-accounting-fields for a description of the fields.pid is the process ID to get the io data. The method returns None if the process does not exist. TODO: no read access.
main_cli ()
- Unix command line interface
parse_cli (self)
- Parse Unix command line arguments
poll (self, timeout: float = None, step: float = None, clear=False) -> int
-
Poll the IO activities. The method checks for IO activities every
step
seconds. It returns the number of processes with new IO activities since the last update() or poll(); or returns 0 if the wait time has exceededtimeout
seconds.timeout defaults to instance value if not given.
step defaults to instance value if not given.
clear (default is False) clears the IO counters so that polling uses only IO activities after this function has started.
update (self) -> int
- Update IO activities. Returns the number of process with new IO activities since the last update() or poll(). Returns -1 if no PID is valid.