ENH make processor not puke if coretemps paths not found

This commit is contained in:
Nathan Dwarshuis 2022-07-23 19:42:21 -04:00
parent a6d1175a73
commit 348eafc1cc
2 changed files with 13 additions and 7 deletions

View File

@ -70,7 +70,6 @@ return function(update_freq, config, main_state, common, width, point)
end
local mk_cores = function(y)
local coretemp_paths = cpu.get_coretemp_paths()
local core_cols = ncores / config.core_rows
local cores = {}
for c = 1, ncores do
@ -85,6 +84,16 @@ return function(update_freq, config, main_state, common, width, point)
* math.floor((c - 1) / core_cols)
cores[c] = create_core(dial_x, dial_y)
end
local coretemp_paths = cpu.get_coretemp_paths()
local update_coretemps = function() end
if coretemp_paths ~= nil then
update_coretemps = function()
for conky_core_id, path in pairs(coretemp_paths) do
local temp = __math_floor(0.001 * i_o.read_file(path, nil, '*n'))
common.text_circle_set(cores[conky_core_id].coretemp, temp)
end
end
end
local update = function()
for _, load_data in pairs(mod_state) do
compound_dial.set(
@ -93,10 +102,7 @@ return function(update_freq, config, main_state, common, width, point)
load_data.percent_active * 100
)
end
for conky_core_id, path in pairs(coretemp_paths) do
local temp = __math_floor(0.001 * i_o.read_file(path, nil, '*n'))
common.text_circle_set(cores[conky_core_id].coretemp, temp)
end
update_coretemps()
end
local static = function(cr)
for i = 1, #cores do

View File

@ -184,11 +184,10 @@ M.get_cpu_number = function()
return tonumber(i_o.execute_cmd('nproc', nil, '*n'))
end
-- TODO what if this fails?
local get_coretemp_dir = function()
i_o.assert_exe_exists('grep')
local s = i_o.execute_cmd('grep -l \'^coretemp$\' /sys/class/hwmon/*/name')
return dirname(s)
if s == nil then return else return dirname(s) end
end
-- map cores to integer values starting at 1; this is necessary since some cpus
@ -226,6 +225,7 @@ end
M.get_coretemp_paths = function()
local d = get_coretemp_dir()
if d == nil then return end
i_o.assert_exe_exists('grep')
local s = i_o.execute_cmd(string.format('grep Core %s/temp*_label', d))
local ps = {}