Skip to content

Commit

Permalink
Fix: Disable CPU frequency retrieval on macOS systems with Apple Sili…
Browse files Browse the repository at this point in the history
…con (closes #384)
  • Loading branch information
liuyue committed Aug 19, 2024
1 parent c743182 commit ca2211f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions backend/utils/server_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,22 @@ def get_cpu_info() -> dict:
"""获取 CPU 信息"""
cpu_info = {'usage': round(psutil.cpu_percent(interval=1, percpu=False), 2)} # %

# CPU 频率信息,最大、最小和当前频率
cpu_freq = psutil.cpu_freq()
cpu_info['max_freq'] = round(cpu_freq.max, 2) # MHz
cpu_info['min_freq'] = round(cpu_freq.min, 2) # MHz
cpu_info['current_freq'] = round(cpu_freq.current, 2) # MHz
# 检查是否是 Apple M1/M2/M3 芯片
if platform.system() == "Darwin" and "arm" in platform.machine().lower():
cpu_info['max_freq'] = None
cpu_info['min_freq'] = None
cpu_info['current_freq'] = None
else:
try:
# CPU 频率信息,最大、最小和当前频率
cpu_freq = psutil.cpu_freq()
cpu_info['max_freq'] = round(cpu_freq.max, 2) # MHz
cpu_info['min_freq'] = round(cpu_freq.min, 2) # MHz
cpu_info['current_freq'] = round(cpu_freq.current, 2) # MHz
except FileNotFoundError:
cpu_info['max_freq'] = None
cpu_info['min_freq'] = None
cpu_info['current_freq'] = None

# CPU 逻辑核心数,物理核心数
cpu_info['logical_num'] = psutil.cpu_count(logical=True)
Expand Down

0 comments on commit ca2211f

Please sign in to comment.