本文整理汇总了Python中psutil.cpu_count方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.cpu_count方法的具体用法?Python psutil.cpu_count怎么用?Python psutil.cpu_count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.cpu_count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [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
示例2: test_ini_without_cmdline
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_ini_without_cmdline(testdir, ini_content, mp, num_processes):
"""Confirms that .ini values are used to determine mp run options"""
testdir.makeini(ini_content)
if mp:
if num_processes != 0:
num_processes = num_processes or cpu_count
else:
num_processes = 0
testdir.makepyfile("""
import pytest
import time
def test_mp(mp_use_mp): # mp_use_mp is pytest-mp helper fixture
assert mp_use_mp == {}
def test_num_processes(mp_num_processes): # mp_num_processes is pytest-mp helper fixture
assert mp_num_processes == {}
""".format(mp, num_processes))
result = testdir.runpytest()
result.stdout.re_match_lines(['.*2 passed.*in.*seconds.*'])
assert result.ret == 0
示例3: OSinfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [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]))
示例4: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [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
示例5: test_cpu_count
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_count(self):
logical = psutil.cpu_count()
self.assertEqual(logical, len(psutil.cpu_times(percpu=True)))
self.assertGreaterEqual(logical, 1)
#
if os.path.exists("/proc/cpuinfo"):
with open("/proc/cpuinfo") as fd:
cpuinfo_data = fd.read()
if "physical id" not in cpuinfo_data:
raise unittest.SkipTest("cpuinfo doesn't include physical id")
physical = psutil.cpu_count(logical=False)
if WINDOWS and sys.getwindowsversion()[:2] <= (6, 1): # <= Vista
self.assertIsNone(physical)
else:
self.assertGreaterEqual(physical, 1)
self.assertGreaterEqual(logical, physical)
示例6: test_cpu_freq
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_freq(self):
def check_ls(ls):
for nt in ls:
self.assertEqual(nt._fields, ('current', 'min', 'max'))
self.assertLessEqual(nt.current, nt.max)
for name in nt._fields:
value = getattr(nt, name)
self.assertIsInstance(value, (int, long, float))
self.assertGreaterEqual(value, 0)
ls = psutil.cpu_freq(percpu=True)
if TRAVIS and not ls:
return
assert ls, ls
check_ls([psutil.cpu_freq(percpu=False)])
if LINUX:
self.assertEqual(len(ls), psutil.cpu_count())
示例7: __init__
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def __init__(
self,
*, # Require passing by keyword.
seed,
max_path_length,
n_workers=psutil.cpu_count(logical=False),
worker_class=DefaultWorker,
worker_args=None):
self.n_workers = n_workers
self._seed = seed
self._max_path_length = max_path_length
self._worker_class = worker_class
if worker_args is None:
self._worker_args = {}
else:
self._worker_args = worker_args
示例8: test_cpu_freq
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_cpu_freq(self):
def check_ls(ls):
for nt in ls:
self.assertEqual(nt._fields, ('current', 'min', 'max'))
if nt.max != 0.0:
self.assertLessEqual(nt.current, nt.max)
for name in nt._fields:
value = getattr(nt, name)
self.assertIsInstance(value, (int, long, float))
self.assertGreaterEqual(value, 0)
ls = psutil.cpu_freq(percpu=True)
if TRAVIS and not ls:
raise self.skipTest("skipped on Travis")
if FREEBSD and not ls:
raise self.skipTest("returns empty list on FreeBSD")
assert ls, ls
check_ls([psutil.cpu_freq(percpu=False)])
if LINUX:
self.assertEqual(len(ls), psutil.cpu_count())
示例9: test_sensors_temperatures_against_sysctl
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_sensors_temperatures_against_sysctl(self):
num_cpus = psutil.cpu_count(True)
for cpu in range(num_cpus):
sensor = "dev.cpu.%s.temperature" % cpu
# sysctl returns a string in the format 46.0C
try:
sysctl_result = int(float(sysctl(sensor)[:-1]))
except RuntimeError:
self.skipTest("temperatures not supported by kernel")
self.assertAlmostEqual(
psutil.sensors_temperatures()["coretemp"][cpu].current,
sysctl_result, delta=10)
sensor = "dev.cpu.%s.coretemp.tjmax" % cpu
sysctl_result = int(float(sysctl(sensor)[:-1]))
self.assertEqual(
psutil.sensors_temperatures()["coretemp"][cpu].high,
sysctl_result)
# =====================================================================
# --- OpenBSD
# =====================================================================
示例10: cpu_count_physical
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def cpu_count_physical():
"""
tries to get the number of physical (ie not virtual) cores
"""
try:
import psutil
return psutil.cpu_count(logical=False)
except:
import multiprocessing
return multiprocessing.cpu_count()
示例11: enable
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def enable(self):
self.data['cpu_count'] = psutil.cpu_count()
self.data['hostname'] = socket.gethostname()
self.data['boot_time'] = psutil.boot_time()
super(Plugin, self).enable()
示例12: __init__
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def __init__(self, monitoring_latency, stats_interval=None):
super().__init__(monitoring_latency)
self.__name = Cpu.__get_processor_name()
self.__count = psutil.cpu_count()
self.__load = None
self.__temperature = None
# Init temperature reader
self.__temperature_reader = Cpu.__get_processor_temperature_reader()
# Prepare to collect statistics
if stats_interval is None:
stats_interval = timedelta(hours=1)
self.__load_stats = LimitedTimeTable(stats_interval)
self.__temperature_stats = LimitedTimeTable(stats_interval)
# Read updating value at first time
self._monitoring_action()
示例13: cpu_count
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def cpu_count(self):
"""The number of logical CPU cores (i.e. including hyper-threaded cores),
according to `psutil.cpu_count(True)`."""
return self._num_logical_cores
示例14: get_cpu_count
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def get_cpu_count():
return psutil.cpu_count()
示例15: test_ini_with_cmdline
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_count [as 别名]
def test_ini_with_cmdline(testdir, cmd_mp, cmd_num_processes, ini_content, ini_mp, ini_num_processes):
"""Confirms that .ini values are not used when cmdline values are specified to determine mp run options"""
testdir.makeini(ini_content)
use_mp = cmd_mp or ini_mp
if use_mp:
if cmd_num_processes == 0:
num_processes = cmd_num_processes
else:
priority = cmd_num_processes or ini_num_processes
num_processes = cpu_count if priority is None else priority
else:
num_processes = 0
testdir.makepyfile("""
import pytest
import time
def test_mp(mp_use_mp):
assert mp_use_mp == {}
def test_num_processes(mp_num_processes):
assert mp_num_processes == {}
""".format(use_mp, num_processes))
cmd_options = []
if cmd_mp:
cmd_options.append('--mp')
if cmd_num_processes is not None:
cmd_options.append('--num-processes={}'.format(cmd_num_processes))
result = testdir.runpytest(*cmd_options)
result.stdout.re_match_lines(['.*2 passed.*in.*seconds.*'])
assert result.ret == 0