本文整理汇总了Python中psutil.cpu_stats方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.cpu_stats方法的具体用法?Python psutil.cpu_stats怎么用?Python psutil.cpu_stats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.cpu_stats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSystemInfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [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_cpu_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats(self):
self.execute(psutil.cpu_stats)
示例3: test_cpu_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats(self):
out = sh('/usr/bin/mpstat -a')
re_pattern = "ALL\s*"
for field in ("min maj mpcs mpcr dev soft dec ph cs ics bound rq "
"push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd "
"sysc").split():
re_pattern += "(?P<%s>\S+)\s+" % (field,)
matchobj = re.search(re_pattern, out)
self.assertIsNotNone(
matchobj, "mpstat command returned unexpected output")
# numbers are usually in the millions so 1000 is ok for tolerance
CPU_STATS_TOLERANCE = 1000
psutil_result = psutil.cpu_stats()
self.assertAlmostEqual(
psutil_result.ctx_switches,
int(matchobj.group("cs")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.syscalls,
int(matchobj.group("sysc")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.interrupts,
int(matchobj.group("dev")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.soft_interrupts,
int(matchobj.group("soft")),
delta=CPU_STATS_TOLERANCE)
示例4: test_cpu_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats(self):
# Tested more extensively in per-platform test modules.
infos = psutil.cpu_stats()
self.assertEqual(
infos._fields,
('ctx_switches', 'interrupts', 'soft_interrupts', 'syscalls'))
for name in infos._fields:
value = getattr(infos, name)
self.assertGreaterEqual(value, 0)
# on AIX, ctx_switches is always 0
if not AIX and name in ('ctx_switches', 'interrupts'):
self.assertGreater(value, 0)
示例5: test_cpu_stats_ctx_switches
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats_ctx_switches(self):
self.assertAlmostEqual(psutil.cpu_stats().ctx_switches,
sysctl('vm.stats.sys.v_swtch'), delta=1000)
示例6: test_cpu_stats_interrupts
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats_interrupts(self):
self.assertAlmostEqual(psutil.cpu_stats().interrupts,
sysctl('vm.stats.sys.v_intr'), delta=1000)
示例7: test_cpu_stats_syscalls
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats_syscalls(self):
self.assertAlmostEqual(psutil.cpu_stats().syscalls,
sysctl('vm.stats.sys.v_syscall'), delta=1000)
# def test_cpu_stats_traps(self):
# self.assertAlmostEqual(psutil.cpu_stats().traps,
# sysctl('vm.stats.sys.v_trap'), delta=1000)
# --- swap memory
示例8: test_ctx_switches
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_ctx_switches(self):
vmstat_value = vmstat("context switches")
psutil_value = psutil.cpu_stats().ctx_switches
self.assertAlmostEqual(vmstat_value, psutil_value, delta=500)
示例9: test_interrupts
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_interrupts(self):
vmstat_value = vmstat("interrupts")
psutil_value = psutil.cpu_stats().interrupts
self.assertAlmostEqual(vmstat_value, psutil_value, delta=500)
# =====================================================================
# --- system network
# =====================================================================
示例10: test_cpu_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats(self):
out = sh('/usr/bin/mpstat -a')
re_pattern = r"ALL\s*"
for field in ("min maj mpcs mpcr dev soft dec ph cs ics bound rq "
"push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd "
"sysc").split():
re_pattern += r"(?P<%s>\S+)\s+" % (field,)
matchobj = re.search(re_pattern, out)
self.assertIsNotNone(
matchobj, "mpstat command returned unexpected output")
# numbers are usually in the millions so 1000 is ok for tolerance
CPU_STATS_TOLERANCE = 1000
psutil_result = psutil.cpu_stats()
self.assertAlmostEqual(
psutil_result.ctx_switches,
int(matchobj.group("cs")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.syscalls,
int(matchobj.group("sysc")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.interrupts,
int(matchobj.group("dev")),
delta=CPU_STATS_TOLERANCE)
self.assertAlmostEqual(
psutil_result.soft_interrupts,
int(matchobj.group("soft")),
delta=CPU_STATS_TOLERANCE)
示例11: test_cpu_stats_soft_interrupts
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats_soft_interrupts(self):
self.assertAlmostEqual(psutil.cpu_stats().soft_interrupts,
sysctl('vm.stats.sys.v_soft'), delta=1000)
示例12: test_interrupts
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_interrupts(self):
vmstat_value = vmstat("interrupts")
psutil_value = psutil.cpu_stats().interrupts
self.assertAlmostEqual(vmstat_value, psutil_value, delta=500)
示例13: cpu_stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def cpu_stats(self) -> CpuStatsResponse:
"""
Get CPU stats.
:return: :class:`platypush.message.response.system.CpuStatsResponse`
"""
import psutil
stats = psutil.cpu_stats()
return CpuStatsResponse(
ctx_switches=stats.ctx_switches,
interrupts=stats.interrupts,
soft_interrupts=stats.soft_interrupts,
syscalls=stats.syscalls,
)
示例14: stats
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def stats():
return psutil.cpu_stats()
示例15: test_cpu_stats_syscalls
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats_syscalls(self):
self.assertAlmostEqual(psutil.cpu_stats().syscalls,
sysctl('vm.stats.sys.v_syscall'), delta=1000)
# def test_cpu_stats_traps(self):
# self.assertAlmostEqual(psutil.cpu_stats().traps,
# sysctl('vm.stats.sys.v_trap'), delta=1000)
# --- others