diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-06-27 16:19:47 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-06-27 16:19:47 +0200 |
commit | 4c102a53346ae8d491b10ea9fbe303184461c877 (patch) | |
tree | a61d585f2f5a9240250c2e441a1b0975482ced2f /psutil/_pssunos.py | |
parent | f34770d5cc4b23dd399fa3796f61b21d35b8e7e7 (diff) | |
parent | 978b673c48dc0422ea3ee3267a13b0e24e88e07a (diff) | |
download | psutil-4c102a53346ae8d491b10ea9fbe303184461c877.tar.gz |
merge from master
Diffstat (limited to 'psutil/_pssunos.py')
-rw-r--r-- | psutil/_pssunos.py | 120 |
1 files changed, 85 insertions, 35 deletions
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index 3b8a3de3..b14d0ef1 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -25,6 +25,12 @@ from ._compat import PY3 __extra__all__ = ["CONN_IDLE", "CONN_BOUND", "PROCFS_PATH"] + +# ===================================================================== +# --- constants +# ===================================================================== + + PAGE_SIZE = os.sysconf('SC_PAGE_SIZE') AF_LINK = cext_posix.AF_LINK @@ -58,6 +64,12 @@ TCP_STATUSES = { cext.TCPS_BOUND: CONN_BOUND, # sunos specific } + +# ===================================================================== +# --- named tuples +# ===================================================================== + + scputimes = namedtuple('scputimes', ['user', 'system', 'idle', 'iowait']) pcputimes = namedtuple('pcputimes', ['user', 'system', 'children_user', 'children_system']) @@ -70,25 +82,30 @@ pmmap_ext = namedtuple( 'pmmap_ext', 'addr perms ' + ' '.join(pmmap_grouped._fields)) -# set later from __init__.py +# ===================================================================== +# --- exceptions +# ===================================================================== + + +# these get overwritten on "import psutil" from the __init__.py file NoSuchProcess = None ZombieProcess = None AccessDenied = None TimeoutExpired = None +# ===================================================================== # --- utils +# ===================================================================== + def get_procfs_path(): return sys.modules['psutil'].PROCFS_PATH -# --- functions - -disk_io_counters = cext.disk_io_counters -net_io_counters = cext.net_io_counters -disk_usage = _psposix.disk_usage -net_if_addrs = cext_posix.net_if_addrs +# ===================================================================== +# --- memory +# ===================================================================== def virtual_memory(): @@ -133,14 +150,9 @@ def swap_memory(): sin * PAGE_SIZE, sout * PAGE_SIZE) -def pids(): - """Returns a list of PIDs currently running on the system.""" - return [int(x) for x in os.listdir(b(get_procfs_path())) if x.isdigit()] - - -def pid_exists(pid): - """Check for the existence of a unix pid.""" - return _psposix.pid_exists(pid) +# ===================================================================== +# --- CPU +# ===================================================================== def cpu_times(): @@ -176,28 +188,13 @@ def cpu_stats(): syscalls) -def boot_time(): - """The system boot time expressed in seconds since the epoch.""" - return cext.boot_time() +# ===================================================================== +# --- disks +# ===================================================================== -def users(): - """Return currently connected users as a list of namedtuples.""" - retlist = [] - rawlist = cext.users() - localhost = (':0.0', ':0') - for item in rawlist: - user, tty, hostname, tstamp, user_process = item - # note: the underlying C function includes entries about - # system boot, run level and others. We might want - # to use them in the future. - if not user_process: - continue - if hostname in localhost: - hostname = 'localhost' - nt = _common.suser(user, tty, hostname, tstamp) - retlist.append(nt) - return retlist +disk_io_counters = cext.disk_io_counters +disk_usage = _psposix.disk_usage def disk_partitions(all=False): @@ -221,6 +218,15 @@ def disk_partitions(all=False): return retlist +# ===================================================================== +# --- network +# ===================================================================== + + +net_io_counters = cext.net_io_counters +net_if_addrs = cext_posix.net_if_addrs + + def net_connections(kind, _pid=-1): """Return socket connections. If pid == -1 return system-wide connections (as opposed to connections opened by one process only). @@ -263,6 +269,50 @@ def net_if_stats(): return ret +# ===================================================================== +# --- other system functions +# ===================================================================== + + +def boot_time(): + """The system boot time expressed in seconds since the epoch.""" + return cext.boot_time() + + +def users(): + """Return currently connected users as a list of namedtuples.""" + retlist = [] + rawlist = cext.users() + localhost = (':0.0', ':0') + for item in rawlist: + user, tty, hostname, tstamp, user_process = item + # note: the underlying C function includes entries about + # system boot, run level and others. We might want + # to use them in the future. + if not user_process: + continue + if hostname in localhost: + hostname = 'localhost' + nt = _common.suser(user, tty, hostname, tstamp) + retlist.append(nt) + return retlist + + +# ===================================================================== +# --- processes +# ===================================================================== + + +def pids(): + """Returns a list of PIDs currently running on the system.""" + return [int(x) for x in os.listdir(b(get_procfs_path())) if x.isdigit()] + + +def pid_exists(pid): + """Check for the existence of a unix pid.""" + return _psposix.pid_exists(pid) + + def wrap_exceptions(fun): """Call callable into a try/except clause and translate ENOENT, EACCES and EPERM in NoSuchProcess or AccessDenied exceptions. |