def virtual_memory(): """System virtual memory as a namedutple.""" mem = _psutil_bsd.get_virtual_mem() total, free, active, inactive, wired, cached, buffers, shared = mem avail = inactive + cached + free used = active + wired + cached percent = usage_percent((total - avail), total, _round=1) return nt_virtmem_info(total, avail, percent, used, free, active, inactive, buffers, cached, shared, wired)
def virtual_memory(): """System virtual memory as a namedutple.""" mem = _psutil_bsd.get_virtual_mem() total, free, active, inactive, wired, cached, buffers, shared = mem avail = inactive + cached + free used = active + wired + cached percent = usage_percent((total - avail), total, _round=1) return nt_virtmem_info(total, avail, percent, used, free, active, inactive, buffers, cached, shared, wired)
import sys import _psutil_bsd import _psutil_posix from psutil import _psposix from psutil.error import AccessDenied, NoSuchProcess, TimeoutExpired from psutil._compat import namedtuple from psutil._common import * __extra__all__ = [] # --- constants NUM_CPUS = _psutil_bsd.get_num_cpus() BOOT_TIME = _psutil_bsd.get_system_boot_time() TOTAL_PHYMEM = _psutil_bsd.get_virtual_mem()[0] _TERMINAL_MAP = _psposix._get_terminal_map() _PAGESIZE = os.sysconf("SC_PAGE_SIZE") _cputimes_ntuple = namedtuple('cputimes', 'user nice system idle irq') # --- public functions nt_virtmem_info = namedtuple( 'vmem', ' '.join([ # all platforms 'total', 'available', 'percent', 'used', 'free',
__extra__all__ = [] # --- constants # Since these constants get determined at import time we do not want to # crash immediately; instead we'll set them to None and most likely # we'll crash later as they're used for determining process CPU stats # and creation_time try: NUM_CPUS = _psutil_bsd.get_num_cpus() except Exception: NUM_CPUS = None warnings.warn("couldn't determine platform's NUM_CPUS", RuntimeWarning) try: TOTAL_PHYMEM = _psutil_bsd.get_virtual_mem()[0] except Exception: TOTAL_PHYMEM = None warnings.warn("couldn't determine platform's TOTAL_PHYMEM", RuntimeWarning) try: BOOT_TIME = _psutil_bsd.get_system_boot_time() except Exception: BOOT_TIME = None warnings.warn("couldn't determine platform's BOOT_TIME", RuntimeWarning) PROC_STATUSES = { _psutil_bsd.SSTOP: STATUS_STOPPED, _psutil_bsd.SSLEEP: STATUS_SLEEPING, _psutil_bsd.SRUN: STATUS_RUNNING, _psutil_bsd.SIDL: STATUS_IDLE, _psutil_bsd.SWAIT: STATUS_WAITING,