Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def collect_cpu_temperatures(metadata):
path = sysfs_path("class/hwmon")
try:
names = os.listdir(path)
except OSError:
return None
cpu_temp = []
for name in names:
hwmon = os.path.join(path, name)
get_cpu_temperature(hwmon, cpu_temp)
if not cpu_temp:
return None
metadata['cpu_temp'] = ', '.join(cpu_temp)
def get_isolated_cpus():
"""Get the list of isolated CPUs.
Return a sorted list of CPU identifiers, or return None if no CPU is
isolated.
"""
# The cpu/isolated sysfs was added in Linux 4.2
# (commit 59f30abe94bff50636c8cad45207a01fdcb2ee49)
path = sysfs_path('devices/system/cpu/isolated')
isolated = read_first_line(path)
if isolated:
return parse_cpu_list(isolated)
cmdline = read_first_line(proc_path('cmdline'))
if cmdline:
match = re.search(r'\bisolcpus=([^ ]+)', cmdline)
if match:
isolated = match.group(1)
return parse_cpu_list(isolated)
return None
def use_intel_pstate():
cpu = 0
path = sysfs_path("devices/system/cpu/cpu%s/cpufreq/scaling_driver" % cpu)
scaling_driver = read_first_line(path)
return (scaling_driver == 'intel_pstate')
def collect_cpu_config(metadata, cpus):
nohz_full = read_first_line(sysfs_path('devices/system/cpu/nohz_full'))
if nohz_full:
nohz_full = parse_cpu_list(nohz_full)
isolated = get_isolated_cpus()
if isolated:
isolated = set(isolated)
configs = {}
for cpu in cpus:
config = get_cpu_config(cpu)
if nohz_full and cpu in nohz_full:
config.append('nohz_full')
if isolated and cpu in isolated:
config.append('isolated')
if config:
configs[cpu] = ', '.join(config)
def get_cpu_config(cpu):
sys_cpu_path = sysfs_path("devices/system/cpu")
info = []
path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_driver" % cpu)
scaling_driver = read_first_line(path)
if scaling_driver:
info.append('driver:%s' % scaling_driver)
if scaling_driver == 'intel_pstate':
path = os.path.join(sys_cpu_path, "intel_pstate/no_turbo")
no_turbo = read_first_line(path)
if no_turbo == '1':
info.append('intel_pstate:no turbo')
elif no_turbo == '0':
info.append('intel_pstate:turbo')
path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_governor" % cpu)