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


Python psutil.cpu_freq方法代码示例

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


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

示例1: getSystemInfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [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

示例2: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [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()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_system.py

示例3: test_cpu_freq_emulate_data

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq_emulate_data(self):
        def open_mock(name, *args, **kwargs):
            if name.endswith('/scaling_cur_freq'):
                return io.BytesIO(b"500000")
            elif name.endswith('/scaling_min_freq'):
                return io.BytesIO(b"600000")
            elif name.endswith('/scaling_max_freq'):
                return io.BytesIO(b"700000")
            else:
                return orig_open(name, *args, **kwargs)

        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        with mock.patch(patch_point, side_effect=open_mock):
            with mock.patch(
                    'glob.glob',
                    return_value=['/sys/devices/system/cpu/cpufreq/policy0']):
                freq = psutil.cpu_freq()
                self.assertEqual(freq.current, 500.0)
                self.assertEqual(freq.min, 600.0)
                self.assertEqual(freq.max, 700.0) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:test_linux.py

示例4: test_cpu_freq_emulate_multi_cpu

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq_emulate_multi_cpu(self):
        def open_mock(name, *args, **kwargs):
            if name.endswith('/scaling_cur_freq'):
                return io.BytesIO(b"100000")
            elif name.endswith('/scaling_min_freq'):
                return io.BytesIO(b"200000")
            elif name.endswith('/scaling_max_freq'):
                return io.BytesIO(b"300000")
            else:
                return orig_open(name, *args, **kwargs)

        orig_open = open
        patch_point = 'builtins.open' if PY3 else '__builtin__.open'
        policies = ['/sys/devices/system/cpu/cpufreq/policy0',
                    '/sys/devices/system/cpu/cpufreq/policy1',
                    '/sys/devices/system/cpu/cpufreq/policy2']
        with mock.patch(patch_point, side_effect=open_mock):
            with mock.patch('glob.glob', return_value=policies):
                freq = psutil.cpu_freq()
                self.assertEqual(freq.current, 100.0)
                self.assertEqual(freq.min, 200.0)
                self.assertEqual(freq.max, 300.0) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_linux.py

示例5: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [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()) 
开发者ID:giampaolo,项目名称:psutil,代码行数:24,代码来源:test_system.py

示例6: cpu_frequency

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def cpu_frequency(self, per_cpu: bool = False) -> Union[CpuFrequencyResponse, CpuResponseList]:
        """
        Get CPU stats.

        :param per_cpu: Get per-CPU stats (default: False).
        :return: :class:`platypush.message.response.system.CpuFrequencyResponse`
        """
        import psutil
        freq = psutil.cpu_freq(percpu=per_cpu)

        if per_cpu:
            return CpuResponseList([
                CpuFrequencyResponse(
                    min=f.min,
                    max=f.max,
                    current=f.current,
                )
                for f in freq
            ])

        return CpuFrequencyResponse(
            min=freq.min,
            max=freq.max,
            current=freq.current,
        ) 
开发者ID:BlackLight,项目名称:platypush,代码行数:27,代码来源:__init__.py

示例7: get_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def get_cpu_freq():
    # psutil won't return current cpu freq in visualization.
    # return psutil.cpu_freq()[0]
    return round(float(cpuinfo.get_cpu_info()['hz_actual'].split(' ')[0]), 2) 
开发者ID:BennyThink,项目名称:ServerSan,代码行数:6,代码来源:ss-agent.py

示例8: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq(self):
        self.execute(psutil.cpu_freq)

    # --- mem 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_memory_leaks.py

示例9: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq(self):
        w = wmi.WMI()
        proc = w.Win32_Processor()[0]
        self.assertEqual(proc.CurrentClockSpeed, psutil.cpu_freq().current)
        self.assertEqual(proc.MaxClockSpeed, psutil.cpu_freq().max) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_windows.py

示例10: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq(self):
        freq = psutil.cpu_freq()
        self.assertEqual(
            freq.current * 1000 * 1000, sysctl("sysctl hw.cpufrequency"))
        self.assertEqual(
            freq.min * 1000 * 1000, sysctl("sysctl hw.cpufrequency_min"))
        self.assertEqual(
            freq.max * 1000 * 1000, sysctl("sysctl hw.cpufrequency_max"))

    # --- virtual mem 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_osx.py

示例11: test_cpu_freq_no_result

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq_no_result(self):
        with mock.patch("psutil._pslinux.glob.glob", return_value=[]):
            self.assertIsNone(psutil.cpu_freq()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:test_linux.py

示例12: test_cpu_freq

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_cpu_freq(self):
        self.assertEqual(hasattr(psutil, "cpu_freq"),
                         LINUX or MACOS or WINDOWS or FREEBSD) 
开发者ID:giampaolo,项目名称:psutil,代码行数:5,代码来源:test_contracts.py

示例13: test_cpu_freq

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

示例14: test_emulate_use_second_file

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_emulate_use_second_file(self):
        # https://github.com/giampaolo/psutil/issues/981
        def path_exists_mock(path):
            if path.startswith("/sys/devices/system/cpu/cpufreq/policy"):
                return False
            else:
                return orig_exists(path)

        orig_exists = os.path.exists
        with mock.patch("os.path.exists", side_effect=path_exists_mock,
                        create=True):
            assert psutil.cpu_freq() 
开发者ID:giampaolo,项目名称:psutil,代码行数:14,代码来源:test_linux.py

示例15: test_emulate_use_cpuinfo

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import cpu_freq [as 别名]
def test_emulate_use_cpuinfo(self):
        # Emulate a case where /sys/devices/system/cpu/cpufreq* does not
        # exist and /proc/cpuinfo is used instead.
        def path_exists_mock(path):
            if path.startswith('/sys/devices/system/cpu/'):
                return False
            else:
                if path == "/proc/cpuinfo":
                    flags.append(None)
                return os_path_exists(path)

        flags = []
        os_path_exists = os.path.exists
        try:
            with mock.patch("os.path.exists", side_effect=path_exists_mock):
                reload_module(psutil._pslinux)
                ret = psutil.cpu_freq()
                assert ret
                assert flags
                self.assertEqual(ret.max, 0.0)
                self.assertEqual(ret.min, 0.0)
                for freq in psutil.cpu_freq(percpu=True):
                    self.assertEqual(ret.max, 0.0)
                    self.assertEqual(ret.min, 0.0)
        finally:
            reload_module(psutil._pslinux)
            reload_module(psutil) 
开发者ID:giampaolo,项目名称:psutil,代码行数:29,代码来源:test_linux.py


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