Python psutil.cpu_freq() Examples
The following are 30
code examples of psutil.cpu_freq().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
psutil
, or try the search function
.
Example #1
Source File: server.py From MoePhoto with Apache License 2.0 | 6 votes |
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
Example #2
Source File: test_system.py From vnpy_crypto with MIT License | 6 votes |
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())
Example #3
Source File: test_linux.py From jarvis with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: test_linux.py From jarvis with GNU General Public License v2.0 | 6 votes |
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)
Example #5
Source File: test_linux.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #6
Source File: test_linux.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #7
Source File: __init__.py From platypush with MIT License | 6 votes |
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, )
Example #8
Source File: test_system.py From psutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
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())
Example #9
Source File: test_system.py From jarvis with GNU General Public License v2.0 | 6 votes |
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())
Example #10
Source File: automatic.py From fanshim-python with MIT License | 5 votes |
def get_cpu_freq(): freq = psutil.cpu_freq() return freq
Example #11
Source File: server.py From pykit with MIT License | 5 votes |
def make_serverrec(server_id, idc, idc_type, roles, allocated_drive_pre, **argkv): serverrec = {} ips = net.get_host_ip4(exclude_prefix="docker") inn_ips = net.choose_inn(ips) pub_ips = net.choose_pub(ips) memory = psutil.virtual_memory().total cpu_info = {} # count of logical cpus cpu_info['count'] = psutil.cpu_count() # Mhz if hasattr(psutil, 'cpu_freq'): cpu_info['frequency'] = psutil.cpu_freq().max serverrec['server_id'] = server_id serverrec['pub_ips'] = pub_ips serverrec['inn_ips'] = inn_ips serverrec['hostname'] = socket.gethostname() serverrec['memory'] = memory serverrec['cpu'] = cpu_info serverrec['idc'] = idc serverrec['idc_type'] = idc_type serverrec['roles'] = roles mps = _make_mountpoints_info() serverrec['mountpoints'] = mps allocated_drive, max_mount_idx = _get_allocated_drive(allocated_drive_pre, mps) serverrec['next_mount_index'] = max_mount_idx + 1 serverrec['allocated_drive'] = allocated_drive serverrec['status'] = ServerStatus.def_status() serverrec.update(argkv) return serverrec
Example #12
Source File: freq_source.py From s-tui with GNU General Public License v2.0 | 5 votes |
def __init__(self): self.is_available = True if not hasattr(psutil, "cpu_freq"): self.is_available = False logging.debug("cpu_freq is not available from psutil") return Source.__init__(self) self.name = 'Frequency' self.measurement_unit = 'MHz' self.pallet = ('freq light', 'freq dark', 'freq light smooth', 'freq dark smooth') # Check if psutil.cpu_freq is available. # +1 for average frequency self.last_measurement = [0] * len(psutil.cpu_freq(True)) if psutil.cpu_freq(False): self.last_measurement.append(0) self.top_freq = psutil.cpu_freq().max self.max_freq = self.top_freq if self.top_freq == 0.0: # If top freq not available, take the current as top if max(self.last_measurement) >= 0: self.max_freq = max(self.last_measurement) self.available_sensors = ['Avg'] for core_id, _ in enumerate(psutil.cpu_freq(True)): self.available_sensors.append("Core " + str(core_id))
Example #13
Source File: freq_source.py From s-tui with GNU General Public License v2.0 | 5 votes |
def update(self): self.last_measurement = [psutil.cpu_freq(False).current] for core in psutil.cpu_freq(True): self.last_measurement.append(core.current)
Example #14
Source File: status.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def status(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ uptime_set = arrow.utcnow().float_timestamp - cmd.bot.start_time.float_timestamp processed = round(cmd.bot.queue.processed / uptime_set, 3) os_icon, os_color = get_os_icon() general_text = f'Latency: **{int(cmd.bot.latency * 1000)}ms**' general_text += f'\nPlatform: **{sys.platform.upper()}**' general_text += f'\nStarted: **{arrow.get(psutil.boot_time()).humanize()}**' cpu_clock = psutil.cpu_freq() cpu_clock = round(cpu_clock.current, 2) if cpu_clock else '???' cpu_text = f'Count: **{psutil.cpu_count()} ({psutil.cpu_count(logical=False)})**' cpu_text += f'\nUsage: **{psutil.cpu_percent()}%**' cpu_text += f'\nClock: **{cpu_clock} MHz**' avail_mem = psutil.virtual_memory().available total_mem = psutil.virtual_memory().total used_mem = humanfriendly.format_size(total_mem - avail_mem, binary=True) total_mem = humanfriendly.format_size(total_mem, binary=True) sigma_mem = humanfriendly.format_size(psutil.Process(os.getpid()).memory_info().rss, binary=True) mem_text = f'Me: **{sigma_mem}**' mem_text += f'\nUsed: **{used_mem}**' mem_text += f'\nTotal: **{total_mem}**' response = discord.Embed(color=os_color) response.set_author(name=socket.gethostname(), icon_url=os_icon) response.add_field(name='General', value=general_text) response.add_field(name='CPU', value=cpu_text) response.add_field(name='Memory', value=mem_text) if cmd.bot.cfg.dsc.bot: shard_latency = get_shard_latency(cmd.bot.latencies, pld.msg.guild.shard_id) verbose_description = f'Shard: #{pld.msg.guild.shard_id} | ' verbose_description += f'Latency: {shard_latency}ms | ' verbose_description += f'Activity: {processed} ev/s' response.description = verbose_description await pld.msg.channel.send(embed=response)
Example #15
Source File: system.py From vexbot with GNU General Public License v3.0 | 5 votes |
def cpu_frequency(*args, **kwargs): freq = psutil.cpu_freq() if freq is None: return ('CPU frequency file moved or not present. See: ' 'https://stackoverflow.com/questions/42979943/python3-psutils') return [x.max for x in freq]
Example #16
Source File: common.py From experiment-impact-tracker with MIT License | 5 votes |
def get_cpu_freq(*args, **kwargs): """ Returns all cpu freq of all cpu's available """ try: return [x._asdict() for x in psutil.cpu_freq(percpu=True)] except NotImplementedError: # psutil.cpu_freq() fails on some machines return []
Example #17
Source File: test_memory_leaks.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_cpu_freq(self): self.execute(psutil.cpu_freq) # --- mem
Example #18
Source File: test_windows.py From jarvis with GNU General Public License v2.0 | 5 votes |
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)
Example #19
Source File: test_osx.py From jarvis with GNU General Public License v2.0 | 5 votes |
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
Example #20
Source File: test_linux.py From jarvis with GNU General Public License v2.0 | 5 votes |
def test_cpu_freq_no_result(self): with mock.patch("psutil._pslinux.glob.glob", return_value=[]): self.assertIsNone(psutil.cpu_freq())
Example #21
Source File: machinemodel.py From kerncraft with GNU Affero General Public License v3.0 | 5 votes |
def get_cpu_frequency(): """Get CPU frequency in Hz""" # TODO use likwid to read actual base frequency cpu_frequency = psutil.cpu_freq() if cpu_frequency: return cpu_frequency.current*1e6 else: return None
Example #22
Source File: util.py From BugZoo with MIT License | 5 votes |
def report_system_resources(logger: logging.Logger) -> None: cores_physical = psutil.cpu_count(logical=False) cores_logical = psutil.cpu_count(logical=True) cores_s = "{} physical, {} logical".format(cores_physical, cores_logical) if psutil.cpu_freq(): cpu_freq_s = "{:.2f} GHz".format(psutil.cpu_freq().max / 1000) else: cpu_freq_s = "unknown" if psutil.virtual_memory(): vmem_total = bytes_to_gigabytes(psutil.virtual_memory().total) vmem_total_s = "{:.2f} GB".format(vmem_total) else: vmem_total_s = "unknown" if psutil.swap_memory(): swap_total = bytes_to_gigabytes(psutil.swap_memory().total) swap_free = bytes_to_gigabytes(psutil.swap_memory().free) swap_s = "{:.2f} GB ({:.2f} GB free)".format(swap_total, swap_free) else: swap_s = "unknown" disk_info = psutil.disk_usage('/') if disk_info: disk_size = bytes_to_gigabytes(disk_info.total) disk_free = bytes_to_gigabytes(disk_info.free) disk_s = "{:.2f} GB ({:.2f} GB free)".format(disk_size, disk_free) else: disk_s = "unknown" resource_s = '\n'.join([ '* CPU cores: {}'.format(cores_s), '* CPU frequency: {}'.format(cpu_freq_s), '* virtual memory: {}'.format(vmem_total_s), '* swap memory: {}'.format(swap_s), '* disk space: {}'.format(disk_s) ]) logger.info("system resources:\n%s", indent(resource_s, 2))
Example #23
Source File: ss-agent.py From ServerSan with Apache License 2.0 | 5 votes |
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)
Example #24
Source File: test_memory_leaks.py From vnpy_crypto with MIT License | 5 votes |
def test_cpu_freq(self): self.execute(psutil.cpu_freq) # --- mem
Example #25
Source File: test_linux.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_emulate_data(self): def open_mock(name, *args, **kwargs): if (name.endswith('/scaling_cur_freq') and name.startswith("/sys/devices/system/cpu/cpufreq/policy")): return io.BytesIO(b"500000") elif (name.endswith('/scaling_min_freq') and name.startswith("/sys/devices/system/cpu/cpufreq/policy")): return io.BytesIO(b"600000") elif (name.endswith('/scaling_max_freq') and name.startswith("/sys/devices/system/cpu/cpufreq/policy")): return io.BytesIO(b"700000") elif name == '/proc/cpuinfo': return io.BytesIO(b"cpu MHz : 500") 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( 'os.path.exists', return_value=True): freq = psutil.cpu_freq() self.assertEqual(freq.current, 500.0) # when /proc/cpuinfo is used min and max frequencies are not # available and are set to 0. if freq.min != 0.0: self.assertEqual(freq.min, 600.0) if freq.max != 0.0: self.assertEqual(freq.max, 700.0)
Example #26
Source File: test_linux.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #27
Source File: test_linux.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #28
Source File: test_memleaks.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_cpu_freq(self): self.execute(psutil.cpu_freq)
Example #29
Source File: test_osx.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #30
Source File: test_windows.py From psutil with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)