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