summaryrefslogtreecommitdiff
path: root/psutil/_pslinux.py
diff options
context:
space:
mode:
authorAlex Manuskin <amanusk@protonmail.com>2019-04-05 21:32:37 +0300
committerGiampaolo Rodola <g.rodola@gmail.com>2019-04-05 20:32:37 +0200
commit05d51649ca709c6626d84cc710c2470d64829848 (patch)
treec1008c83976de8660b0ee3372f359eceea462358 /psutil/_pslinux.py
parent36b5ab0c83ad76a6a6b9ea4e97380a0f05ae332a (diff)
downloadpsutil-05d51649ca709c6626d84cc710c2470d64829848.tar.gz
Linux / CPU freq, fixes #1481
Diffstat (limited to 'psutil/_pslinux.py')
-rw-r--r--psutil/_pslinux.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index bf815e87..1f8ddb93 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -688,23 +688,19 @@ if os.path.exists("/sys/devices/system/cpu/cpufreq") or \
Contrarily to other OSes, Linux updates these values in
real-time.
"""
- # scaling_* files seem preferable to cpuinfo_*, see:
- # http://unix.stackexchange.com/a/87537/168884
+ def get_path(num):
+ for p in ("/sys/devices/system/cpu/cpufreq/policy%s" % num,
+ "/sys/devices/system/cpu/cpu%s/cpufreq" % num):
+ if os.path.exists(p):
+ return p
+
ret = []
- ls = glob.glob("/sys/devices/system/cpu/cpufreq/policy*")
- if ls:
- # Sort the list so that '10' comes after '2'. This should
- # ensure the CPU order is consistent with other CPU functions
- # having a 'percpu' argument and returning results for multiple
- # CPUs (cpu_times(), cpu_percent(), cpu_times_percent()).
- ls.sort(key=lambda x: int(os.path.basename(x)[6:]))
- else:
- # https://github.com/giampaolo/psutil/issues/981
- ls = glob.glob("/sys/devices/system/cpu/cpu[0-9]*/cpufreq")
- ls.sort(key=lambda x: int(re.search('[0-9]+', x).group(0)))
+ for n in range(cpu_count_logical()):
+ path = get_path(n)
+ if not path:
+ continue
- pjoin = os.path.join
- for path in ls:
+ pjoin = os.path.join
curr = cat(pjoin(path, "scaling_cur_freq"), fallback=None)
if curr is None:
# Likely an old RedHat, see: