当前位置: 首页>>代码示例>>Python>>正文


Python psutil.virtual_memory方法代码示例

本文整理汇总了Python中psutil.virtual_memory方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.virtual_memory方法的具体用法?Python psutil.virtual_memory怎么用?Python psutil.virtual_memory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psutil的用法示例。


在下文中一共展示了psutil.virtual_memory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def getSystemInfo(cls):
        system = {
            'boot_time': psutil.boot_time(),
            'cpu_count': psutil.cpu_count(),
            'cpu_stats': psutil.cpu_stats().__dict__,
            'cpu_times': [k.__dict__ for k in psutil.cpu_times(percpu=True)],
            'disk_io_counters': psutil.disk_io_counters().__dict__,
            'disk_usage': [],
            'net_io_counters': psutil.net_io_counters().__dict__,
            'swap_memory': psutil.swap_memory().__dict__,
            'virtual_memory': psutil.virtual_memory().__dict__
        }

        partitions = psutil.disk_partitions()
        for p in partitions:
            if p.mountpoint in cls.INCLUDED_PARTITIONS:
                usage = psutil.disk_usage(p.mountpoint)
                system['disk_usage'].append({
                    'mountpoint': p.mountpoint,
                    'total': usage.total,
                    'used': usage.used
                })

        return system 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:26,代码来源:system_status.py

示例2: memory

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def memory():
    c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.memory')
    while True:
        swap = psutil.swap_memory()
        c.gauge('swap.total', swap.total)
        c.gauge('swap.used', swap.used)
        c.gauge('swap.free', swap.free)
        c.gauge('swap.percent', swap.percent)

        virtual = psutil.virtual_memory()
        c.gauge('virtual.total', virtual.total)
        c.gauge('virtual.available', virtual.available)
        c.gauge('virtual.used', virtual.used)
        c.gauge('virtual.free', virtual.free)
        c.gauge('virtual.percent', virtual.percent)
        c.gauge('virtual.active', virtual.active)
        c.gauge('virtual.inactive', virtual.inactive)
        c.gauge('virtual.buffers', virtual.buffers)
        c.gauge('virtual.cached', virtual.cached)
        time.sleep(GRANULARITY) 
开发者ID:thenetcircle,项目名称:dino,代码行数:22,代码来源:statsd-agent.py

示例3: updateGui

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def updateGui(screen, boxes, data):
    maxy, maxx = screen.getmaxyx()

    date = str(time.strftime("%c"))
    screen.addstr(1, maxx - len(date) - 2, date)

    screen.addstr(3, 15, '%3d' % (psutil.cpu_percent()))
    # svmem(total=10367352832, available=6472179712, percent=37.6, used=8186245120, free=2181107712, active=4748992512, inactive=2758115328, buffers=790724608, cached=3500347392, shared=787554304)
    screen.addstr(4, 15, str(psutil.virtual_memory()[4] / (1024 * 1024)))

    screen.refresh()
    n = 0
    for box in boxes:
        testspersecond = '%8d' % data[n]["testspersecond"]
        testcount = '%8d' % data[n]["testcount"]
        crashcount = '%8d' % data[n]["crashcount"]
        box.addstr(1, 1, testspersecond)
        box.addstr(2, 1, testcount)
        box.addstr(3, 1, crashcount)
        box.refresh()
        n += 1 
开发者ID:dobin,项目名称:ffw,代码行数:23,代码来源:gui.py

示例4: OSinfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def OSinfo():
    '''操作系统基本信息查看'''
    core_number = psutil.cpu_count()
    cpu_number = psutil.cpu_count(logical=True)
    cpu_usage_precent = psutil.cpu_times_percent()
    mem_info = psutil.virtual_memory()
    result = {
        "memtotal": mem_info[0],
        "memavail": mem_info[1],
        "memprecn": mem_info[2],
        "memusage": mem_info[3],
        "memfreed": mem_info[4],
    }
    print '''
        内核版本 : %s
        CORE数量 : %s
        CPU数量 : %s
        CPU使用率 : %s
        内存总量  : %s
        内存使用率 : %s
    '''%(str(platform.platform()),str(core_number),str(cpu_number),str(cpu_usage_precent),str(mem_info[0]),str(mem_info[2])) 
开发者ID:cisp,项目名称:LinuxEmergency,代码行数:23,代码来源:emergency.py

示例5: cache_data

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def cache_data(self, max_size=None):
        '''Cache this dataset in RAM. If ``max_size`` is given, then only cache if the entire dataset
        fits in ``max_size`` bytes. If ``max_size`` is the string 'available', then only cache if 
        the entire dataset fits in available RAM, as defined by the ``psutil`` module.'''
        
        if max_size is not None:
            dssize = self.dtype.itemsize * numpy.multiply.reduce(self.dataset.shape)
            if max_size == 'available' and psutil is not None:
                avail_bytes = psutil.virtual_memory().available
                if dssize > avail_bytes:
                    return
            elif isinstance(max_size, str):
                return
            else:
                if dssize > max_size:
                    return
        if self.dataset is not None:
            if self.data is None:
                self.data = self.dataset[...] 
开发者ID:westpa,项目名称:westpa,代码行数:21,代码来源:h5io.py

示例6: _get_mem_available

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def _get_mem_available():
    """
    Get information about memory available, not counting swap.
    """
    try:
        import psutil
        return psutil.virtual_memory().available
    except (ImportError, AttributeError):
        pass

    if sys.platform.startswith('linux'):
        info = {}
        with open('/proc/meminfo', 'r') as f:
            for line in f:
                p = line.split()
                info[p[0].strip(':').lower()] = float(p[1]) * 1e3

        if 'memavailable' in info:
            # Linux >= 3.14
            return info['memavailable']
        else:
            return info['memfree'] + info['cached']

    return None 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:26,代码来源:_testutils.py

示例7: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def getSystemInfo(info):
  import readgpu
  cuda, cudnn = readgpu.getCudaVersion()
  info.update({
    'cpu_count_phy': psutil.cpu_count(logical=False),
    'cpu_count_log': psutil.cpu_count(logical=True),
    'cpu_freq': psutil.cpu_freq().max,
    'disk_total': psutil.disk_usage(cwd).total // 2**20,
    'mem_total': psutil.virtual_memory().total // 2**20,
    'python': readgpu.getPythonVersion(),
    'torch': readgpu.getTorchVersion(),
    'cuda': cuda,
    'cudnn': cudnn,
    'gpus': readgpu.getGPUProperties()
  })
  readgpu.uninstall()
  del readgpu
  return info 
开发者ID:opteroncx,项目名称:MoePhoto,代码行数:20,代码来源:server.py

示例8: test_serialization

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def test_serialization(self):
        def check(ret):
            if json is not None:
                json.loads(json.dumps(ret))
            a = pickle.dumps(ret)
            b = pickle.loads(a)
            self.assertEqual(ret, b)

        check(psutil.Process().as_dict())
        check(psutil.virtual_memory())
        check(psutil.swap_memory())
        check(psutil.cpu_times())
        check(psutil.cpu_times_percent(interval=0))
        check(psutil.net_io_counters())
        if LINUX and not os.path.exists('/proc/diskstats'):
            pass
        else:
            if not APPVEYOR:
                check(psutil.disk_io_counters())
        check(psutil.disk_partitions())
        check(psutil.disk_usage(os.getcwd()))
        check(psutil.users()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_misc.py

示例9: test_total_phymem

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def test_total_phymem(self):
        w = wmi.WMI().Win32_ComputerSystem()[0]
        self.assertEqual(int(w.TotalPhysicalMemory),
                         psutil.virtual_memory().total)

    # @unittest.skipIf(wmi is None, "wmi module is not installed")
    # def test__UPTIME(self):
    #     # _UPTIME constant is not public but it is used internally
    #     # as value to return for pid 0 creation time.
    #     # WMI behaves the same.
    #     w = wmi.WMI().Win32_Process(ProcessId=self.pid)[0]
    #     p = psutil.Process(0)
    #     wmic_create = str(w.CreationDate.split('.')[0])
    #     psutil_create = time.strftime("%Y%m%d%H%M%S",
    #                                   time.localtime(p.create_time()))

    # Note: this test is not very reliable 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_windows.py

示例10: test_proc_cpu_times

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def test_proc_cpu_times(self):
        tested = []
        out = sh('procstat -r %s' % self.pid)
        p = psutil.Process(self.pid)
        for line in out.split('\n'):
            line = line.lower().strip()
            if 'user time' in line:
                pstat_value = float('0.' + line.split()[-1].split('.')[-1])
                psutil_value = p.cpu_times().user
                self.assertEqual(pstat_value, psutil_value)
                tested.append(None)
            elif 'system time' in line:
                pstat_value = float('0.' + line.split()[-1].split('.')[-1])
                psutil_value = p.cpu_times().system
                self.assertEqual(pstat_value, psutil_value)
                tested.append(None)
        if len(tested) != 2:
            raise RuntimeError("couldn't find lines match in procstat out")

    # --- virtual_memory(); tests against sysctl 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_bsd.py

示例11: test_avail_old_missing_fields

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def test_avail_old_missing_fields(self):
        # Remove Active(file), Inactive(file) and SReclaimable
        # from /proc/meminfo and make sure the fallback is used
        # (free + cached),
        with mock_open_content(
            "/proc/meminfo",
            textwrap.dedent("""\
                    Active:          9444728 kB
                    Active(anon):    6145416 kB
                    Buffers:          287952 kB
                    Cached:          4818144 kB
                    Inactive(file):  1578132 kB
                    Inactive(anon):   574764 kB
                    MemFree:         2057400 kB
                    MemTotal:       16325648 kB
                    Shmem:            577588 kB
                    """).encode()) as m:
            with warnings.catch_warnings(record=True) as ws:
                ret = psutil.virtual_memory()
            assert m.called
            self.assertEqual(ret.available, 2057400 * 1024 + 4818144 * 1024)
            w = ws[0]
            self.assertIn(
                "inactive memory stats couldn't be determined", str(w.message)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:test_linux.py

示例12: test_procfs_path

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def test_procfs_path(self):
        tdir = tempfile.mkdtemp()
        try:
            psutil.PROCFS_PATH = tdir
            self.assertRaises(IOError, psutil.virtual_memory)
            self.assertRaises(IOError, psutil.cpu_times)
            self.assertRaises(IOError, psutil.cpu_times, percpu=True)
            self.assertRaises(IOError, psutil.boot_time)
            # self.assertRaises(IOError, psutil.pids)
            self.assertRaises(IOError, psutil.net_connections)
            self.assertRaises(IOError, psutil.net_io_counters)
            self.assertRaises(IOError, psutil.net_if_stats)
            self.assertRaises(IOError, psutil.disk_io_counters)
            self.assertRaises(IOError, psutil.disk_partitions)
            self.assertRaises(psutil.NoSuchProcess, psutil.Process)
        finally:
            psutil.PROCFS_PATH = "/proc"
            os.rmdir(tdir) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_linux.py

示例13: _virtual_memory

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def _virtual_memory(self):
        vmem = psutil.virtual_memory()
        return {
            'total': vmem.total,
            'available': vmem.available,
            'percent': vmem.percent,
            'used': vmem.used,
            'free': vmem.free,
            'active': vmem.active,
            'inactive': vmem.inactive,
            'buffers': vmem.buffers,
            'cached': vmem.cached,
            'cached_percent': round((vmem.cached / vmem.total) * 100, 1)
        } 
开发者ID:pkkid,项目名称:pkmeter,代码行数:16,代码来源:system.py

示例14: __init__

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def __init__(self):
        self.vendor = pdos.read_sys_file('/sys/devices/virtual/dmi/id/sys_vendor')
        self.board = pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_name', default='') \
                     + ' ' + pdos.read_sys_file('/sys/devices/virtual/dmi/id/product_version', default='')
        self.cpu = platform.processor()
        self.memory = virtual_memory().total

        self.wifi = []
        devices = detectSystemDevices()
        for wifiDev in devices['wifi']:
            # Skip unusual devices that are missing the id field.
            if 'id' not in wifiDev:
                continue

            self.wifi.append({
                'id': wifiDev['id'],
                'macAddr': wifiDev['mac'],
                'vendorId': wifiDev['vendor'],
                'deviceId': wifiDev['device'],
                'slot': wifiDev['slot']
            })

        self.biosVendor = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_vendor')
        self.biosVersion = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_version')
        self.biosDate = pdos.read_sys_file('/sys/devices/virtual/dmi/id/bios_date')
        self.osVersion = getOSVersion()
        self.kernelVersion = platform.system() + '-' + platform.release()
        self.pdVersion = getPackageVersion('paradrop')
        self.uptime = int(float(pdos.read_sys_file('/proc/uptime', default='0').split()[0])) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:31,代码来源:information_api.py

示例15: refreshMemoryInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import virtual_memory [as 别名]
def refreshMemoryInfo(self):
        mem = psutil.virtual_memory()
        self.mem['total'] = mem.total
        self.mem['available'] = mem.available
        self.mem['free'] = mem.free
        self.mem['cached'] = mem.cached
        self.mem['buffers'] = mem.buffers 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:9,代码来源:system_status.py


注:本文中的psutil.virtual_memory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。