當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。