Skip to content

Commit

Permalink
Merge pull request #523 from gztong/master
Browse files Browse the repository at this point in the history
Fix the crash when not all CPUs are online
  • Loading branch information
rbonghi committed May 16, 2024
2 parents cd2a2df + d119604 commit 7871872
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions jtop/core/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,17 @@ def read_system_cpu(path, cpu_status={}):
if os.path.isfile(path + "/online"):
with open(path + "/online", 'r') as f:
cpu_status['online'] = f.read().strip() == '1'
# Read governor
if os.path.isdir(path + "/cpufreq"):
with open(path + "/cpufreq/scaling_governor", 'r') as f:
cpu_status['governor'] = f.read().strip()
# Store values
cpu_status['freq'] = read_freq_cpu(path, 'scaling')
cpu_status['info_freq'] = read_freq_cpu(path, 'cpuinfo')
# Read idle CPU
if os.path.isdir(path + "/cpuidle"):
cpu_status['idle_state'] = read_idle(path + "/cpuidle")
# Read governor only if CPU is online
if cpu_status['online']:
if os.path.isdir(path + "/cpufreq"):
with open(path + "/cpufreq/scaling_governor", 'r') as f:
cpu_status['governor'] = f.read().strip()
# Store values
cpu_status['freq'] = read_freq_cpu(path, 'scaling')
cpu_status['info_freq'] = read_freq_cpu(path, 'cpuinfo')
# Read idle CPU
if os.path.isdir(path + "/cpuidle"):
cpu_status['idle_state'] = read_idle(path + "/cpuidle")
return cpu_status


Expand Down

0 comments on commit 7871872

Please sign in to comment.