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


Python psutil.cpu_stats方法代码示例

本文整理汇总了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 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:26,代码来源:system_status.py

示例2: test_cpu_stats

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def test_cpu_stats(self):
        self.execute(psutil.cpu_stats) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:4,代码来源:test_memory_leaks.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,代码来源:test_aix.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:test_system.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_bsd.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_bsd.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_bsd.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_linux.py

示例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
# ===================================================================== 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_linux.py

示例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) 
开发者ID:giampaolo,项目名称:psutil,代码行数:34,代码来源:test_aix.py

示例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) 
开发者ID:giampaolo,项目名称:psutil,代码行数:5,代码来源:test_bsd.py

示例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) 
开发者ID:giampaolo,项目名称:psutil,代码行数:6,代码来源:test_linux.py

示例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,
        ) 
开发者ID:BlackLight,项目名称:platypush,代码行数:16,代码来源:__init__.py

示例14: stats

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_stats [as 别名]
def stats():
                return psutil.cpu_stats() 
开发者ID:Pardus-LiderAhenk,项目名称:ahenk,代码行数:4,代码来源:system.py

示例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 
开发者ID:haynieresearch,项目名称:jarvis,代码行数:11,代码来源:test_bsd.py


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