Fix bug in detection of CPU throttling
glob.glob actually does not provide a way to match
for example either "2" or "10",
the pattern we created in such a case would match either "2", "1", "0", or ",".
This could lead to matching the wrong cores
when cores with multi-digit numbers were used.
@@ -115,11 +115,10 @@ class CPUThrottleCheck(object):
Create an instance that monitors the given list of cores (or all CPUs).
"""
self.cpu_throttle_count = {}
- cpu_pattern = "[{0}]".format(",".join(map(str, cores))) if cores else "*"
- for file in glob.glob(
- "/sys/devices/system/cpu/cpu{}/thermal_throttle/*_throttle_count".format(
- cpu_pattern
- )
+ cores = [str(core) for core in cores] if cores else ["*"]
+ for core in cores:
+ for file in glob.iglob(
+ f"/sys/devices/system/cpu/cpu{core}/thermal_throttle/*_throttle_count"
):
try:
self.cpu_throttle_count[file] = int(util.read_file(file))
