summaryrefslogtreecommitdiff
path: root/psutil/_psbsd.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-06-03 03:17:40 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-06-03 03:17:40 +0200
commit380ce8a95e4afc6903c080e632e47113d0244308 (patch)
tree76cea10506bd87c28dfad93caae67675ac50957b /psutil/_psbsd.py
parent815c6c0b2eea7ef999979fe3554c54d2047c8e7a (diff)
downloadpsutil-380ce8a95e4afc6903c080e632e47113d0244308.tar.gz
prettyfy code
Diffstat (limited to 'psutil/_psbsd.py')
-rw-r--r--psutil/_psbsd.py94
1 files changed, 71 insertions, 23 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 990ecd51..6e04dfd7 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -26,7 +26,11 @@ from ._compat import which
__extra__all__ = []
+
+# =====================================================================
# --- constants
+# =====================================================================
+
if FREEBSD:
PROC_STATUSES = {
@@ -92,6 +96,12 @@ else:
PAGESIZE = os.sysconf("SC_PAGE_SIZE")
AF_LINK = cext_posix.AF_LINK
+
+# =====================================================================
+# --- named tuples
+# =====================================================================
+
+
# extend base mem ntuple with BSD-specific memory metrics
svmem = namedtuple(
'svmem', ['total', 'available', 'percent', 'used', 'free',
@@ -116,13 +126,23 @@ else:
'read_bytes', 'write_bytes'])
-# 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
+# =====================================================================
+# --- memory
+# =====================================================================
+
+
def virtual_memory():
"""System virtual memory as a namedtuple."""
mem = cext.virtual_mem()
@@ -151,6 +171,11 @@ def swap_memory():
return _common.sswap(total, used, free, percent, sin, sout)
+# =====================================================================
+# --- CPU
+# =====================================================================
+
+
def cpu_times():
"""Return system per-CPU times as a namedtuple"""
user, nice, system, idle, irq = cext.cpu_times()
@@ -252,9 +277,9 @@ def cpu_stats():
return _common.scpustats(ctxsw, intrs, soft_intrs, syscalls)
-def boot_time():
- """The system boot time expressed in seconds since the epoch."""
- return cext.boot_time()
+# =====================================================================
+# --- disks
+# =====================================================================
def disk_partitions(all=False):
@@ -272,18 +297,6 @@ def disk_partitions(all=False):
return retlist
-def users():
- retlist = []
- rawlist = cext.users()
- for item in rawlist:
- user, tty, hostname, tstamp = item
- if tty == '~':
- continue # reboot or shutdown
- nt = _common.suser(user, tty or None, hostname, tstamp)
- retlist.append(nt)
- return retlist
-
-
def net_connections(kind):
if OPENBSD:
ret = []
@@ -324,6 +337,15 @@ def net_connections(kind):
return list(ret)
+disk_usage = _psposix.disk_usage
+disk_io_counters = cext.disk_io_counters
+
+
+# =====================================================================
+# --- network
+# =====================================================================
+
+
def net_if_stats():
"""Get NIC stats (isup, duplex, speed, mtu)."""
names = net_io_counters().keys()
@@ -336,6 +358,39 @@ def net_if_stats():
return ret
+net_io_counters = cext.net_io_counters
+net_if_addrs = cext_posix.net_if_addrs
+
+
+# =====================================================================
+# --- other system functions
+# =====================================================================
+
+
+def boot_time():
+ """The system boot time expressed in seconds since the epoch."""
+ return cext.boot_time()
+
+
+def users():
+ retlist = []
+ rawlist = cext.users()
+ for item in rawlist:
+ user, tty, hostname, tstamp = item
+ if tty == '~':
+ continue # reboot or shutdown
+ nt = _common.suser(user, tty or None, hostname, tstamp)
+ retlist.append(nt)
+ return retlist
+
+
+# =====================================================================
+# --- processes
+# =====================================================================
+
+
+pids = cext.pids
+
if OPENBSD or NETBSD:
def pid_exists(pid):
exists = _psposix.pid_exists(pid)
@@ -349,13 +404,6 @@ else:
pid_exists = _psposix.pid_exists
-pids = cext.pids
-disk_usage = _psposix.disk_usage
-net_io_counters = cext.net_io_counters
-disk_io_counters = cext.disk_io_counters
-net_if_addrs = cext_posix.net_if_addrs
-
-
def wrap_exceptions(fun):
"""Decorator which translates bare OSError exceptions into
NoSuchProcess and AccessDenied.