make cpu indices correct

This commit is contained in:
petrucci4prez 2018-01-05 23:36:50 -05:00
parent 04c3b0df40
commit e988ce6ace
1 changed files with 160 additions and 160 deletions

View File

@ -34,67 +34,67 @@ local _TABLE_SECTION_BREAK_ = 20
local _TABLE_HEIGHT_ = 114 local _TABLE_HEIGHT_ = 114
local _create_core_ = function(cores, id, x, y) local _create_core_ = function(cores, id, x, y)
local conky_loads = {} local conky_loads = {}
local conky_freqs = {} local conky_freqs = {}
for c = 0, NUM_PHYSICAL_CORES * NUM_THREADS_PER_CORE - 1 do
if Util.read_file('/sys/devices/system/cpu/cpu'..c..'/topology/core_id', nil, '*n') == id then
table.insert(conky_loads, '${cpu cpu'..(c+1)..'}')
table.insert(conky_freqs, '${freq '..c..'}')
end
end
for c = 0, NUM_PHYSICAL_CORES * NUM_THREADS_PER_CORE - 1 do local hwmon_index = -1
if Util.read_file('/sys/devices/system/cpu/cpu'..c..'/topology/core_id', nil, '*n') == id then while Util.read_file(string.format(CORETEMP_PATH, hwmon_index, 'name'), nil, '*l') ~= 'coretemp' do
table.insert(conky_loads, '${cpu cpu'..c..'}') hwmon_index = hwmon_index + 1
table.insert(conky_freqs, '${freq '..c..'}') end
end
end
local hwmon_index = -1 cores[id +1] = {
while Util.read_file(string.format(CORETEMP_PATH, hwmon_index, 'name'), nil, '*l') ~= 'coretemp' do dials = _G_Widget_.CompoundDial{
hwmon_index = hwmon_index + 1 x = x,
end y = y,
inner_radius = _DIAL_INNER_RADIUS_,
cores[id +1] = { outer_radius = _DIAL_OUTER_RADIUS_,
dials = _G_Widget_.CompoundDial{ spacing = _DIAL_SPACING_,
x = x, num_dials = NUM_THREADS_PER_CORE,
y = y, critical_limit = '>0.8'
inner_radius = _DIAL_INNER_RADIUS_, },
outer_radius = _DIAL_OUTER_RADIUS_, inner_ring = _G_Widget_.Arc{
spacing = _DIAL_SPACING_, x = x,
num_dials = NUM_THREADS_PER_CORE, y = y,
critical_limit = '>0.8' radius = _DIAL_INNER_RADIUS_ - 2,
}, theta0 = 0,
inner_ring = _G_Widget_.Arc{ theta1 = 360
x = x, },
y = y, coretemp_text = _G_Widget_.CriticalText{
radius = _DIAL_INNER_RADIUS_ - 2, x = x,
theta0 = 0, y = y,
theta1 = 360 x_align = 'center',
}, y_align = 'center',
coretemp_text = _G_Widget_.CriticalText{ append_end = '°C',
x = x, critical_limit = '>90'
y = y, },
x_align = 'center', coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'),
y_align = 'center', conky_loads = conky_loads,
append_end = '°C', conky_freqs = conky_freqs
critical_limit = '>90' }
},
coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'),
conky_loads = conky_loads,
conky_freqs = conky_freqs
}
end end
local header = _G_Widget_.Header{ local header = _G_Widget_.Header{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _MODULE_Y_, y = _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
header = 'PROCESSOR' header = 'PROCESSOR'
} }
--we assume that this cpu has 4 physical cores with 2 logical each --we assume that this cpu has 4 physical cores with 2 logical each
local cores = {} local cores = {}
for c = 0, NUM_PHYSICAL_CORES - 1 do for c = 0, NUM_PHYSICAL_CORES - 1 do
local dial_x = _G_INIT_DATA_.LEFT_X + _DIAL_OUTER_RADIUS_ + local dial_x = _G_INIT_DATA_.LEFT_X + _DIAL_OUTER_RADIUS_ +
(_G_INIT_DATA_.SECTION_WIDTH - 2 * _DIAL_OUTER_RADIUS_) * c / 3 (_G_INIT_DATA_.SECTION_WIDTH - 2 * _DIAL_OUTER_RADIUS_) * c / 3
local dial_y = header.bottom_y + _DIAL_OUTER_RADIUS_ local dial_y = header.bottom_y + _DIAL_OUTER_RADIUS_
_create_core_(cores, c, dial_x, dial_y) _create_core_(cores, c, dial_x, dial_y)
end end
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
@ -102,128 +102,128 @@ local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
local _PROCESS_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_ local _PROCESS_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_
local process = { local process = {
label = _G_Widget_.Text{ label = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _PROCESS_Y_, y = _PROCESS_Y_,
text = 'R | S | D | T | Z' text = 'R | S | D | T | Z'
}, },
value = _G_Widget_.Text{ value = _G_Widget_.Text{
x = _RIGHT_X_, x = _RIGHT_X_,
y = _PROCESS_Y_, y = _PROCESS_Y_,
x_align = 'right', x_align = 'right',
text_color = _G_Patterns_.BLUE, text_color = _G_Patterns_.BLUE,
text = '<R> | <S> | <D> | <T> | <Z>' text = '<R> | <S> | <D> | <T> | <Z>'
} }
} }
local _FREQ_Y_ = _PROCESS_Y_ + _TEXT_SPACING_ local _FREQ_Y_ = _PROCESS_Y_ + _TEXT_SPACING_
local ave_freq = { local ave_freq = {
label = _G_Widget_.Text{ label = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _FREQ_Y_, y = _FREQ_Y_,
text = 'Ave Freq' text = 'Ave Freq'
}, },
value = _G_Widget_.Text{ value = _G_Widget_.Text{
x = _RIGHT_X_, x = _RIGHT_X_,
y = _FREQ_Y_, y = _FREQ_Y_,
x_align = 'right', x_align = 'right',
text_color = _G_Patterns_.BLUE, text_color = _G_Patterns_.BLUE,
text = '<freq>' text = '<freq>'
} }
} }
local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_ local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_
local separator = _G_Widget_.Line{ local separator = _G_Widget_.Line{
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_}, p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_},
p2 = {x = _RIGHT_X_, y = _SEP_Y_} p2 = {x = _RIGHT_X_, y = _SEP_Y_}
} }
local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
local total_load = { local total_load = {
label = _G_Widget_.Text{ label = _G_Widget_.Text{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _LOAD_Y_, y = _LOAD_Y_,
text = 'Total Load' text = 'Total Load'
}, },
value = _G_Widget_.CriticalText{ value = _G_Widget_.CriticalText{
x = _RIGHT_X_, x = _RIGHT_X_,
y = _LOAD_Y_, y = _LOAD_Y_,
x_align = 'right', x_align = 'right',
append_end = '%', append_end = '%',
critical_limit = '>80' critical_limit = '>80'
} }
} }
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
local plot = _G_Widget_.LabelPlot{ local plot = _G_Widget_.LabelPlot{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _PLOT_Y_, y = _PLOT_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
height = _PLOT_HEIGHT_ height = _PLOT_HEIGHT_
} }
local tbl = _G_Widget_.Table{ local tbl = _G_Widget_.Table{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_, y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
height = _TABLE_HEIGHT_, height = _TABLE_HEIGHT_,
num_rows = NUM_ROWS, num_rows = NUM_ROWS,
'Name', 'Name',
'PID', 'PID',
'CPU (%)' 'CPU (%)'
} }
local update = function(cr) local update = function(cr)
local conky = Util.conky local conky = Util.conky
local char_count = Util.char_count local char_count = Util.char_count
local load_sum = 0 local load_sum = 0
local freq_sum = 0 local freq_sum = 0
for c = 1, NUM_PHYSICAL_CORES do for c = 1, NUM_PHYSICAL_CORES do
local core = cores[c] local core = cores[c]
local conky_loads = core.conky_loads local conky_loads = core.conky_loads
local conky_freqs = core.conky_freqs local conky_freqs = core.conky_freqs
for t = 1, NUM_THREADS_PER_CORE do for t = 1, NUM_THREADS_PER_CORE do
local percent = Util.conky_numeric(conky_loads[t]) * 0.01 local percent = Util.conky_numeric(conky_loads[t]) * 0.01
CompoundDial.set(core.dials, t, percent) CompoundDial.set(core.dials, t, percent)
load_sum = load_sum + percent load_sum = load_sum + percent
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t]) freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
end end
CriticalText.set(core.coretemp_text, cr, Util.round(0.001 * Util.read_file(core.coretemp_path, nil, '*n'))) CriticalText.set(core.coretemp_text, cr, Util.round(0.001 * Util.read_file(core.coretemp_path, nil, '*n')))
end end
local process_glob = Util.execute_cmd('ps -A -o s') local process_glob = Util.execute_cmd('ps -A -o s')
--subtract one from running b/c ps will always be "running" --subtract one from running b/c ps will always be "running"
Text.set(process.value, cr, (char_count(process_glob, 'R') - 1)..' | '.. Text.set(process.value, cr, (char_count(process_glob, 'R') - 1)..' | '..
char_count(process_glob, 'S')..' | '.. char_count(process_glob, 'S')..' | '..
char_count(process_glob, 'D')..' | '.. char_count(process_glob, 'D')..' | '..
char_count(process_glob, 'T')..' | '.. char_count(process_glob, 'T')..' | '..
char_count(process_glob, 'Z')) char_count(process_glob, 'Z'))
Text.set(ave_freq.value, cr, Util.round(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz') Text.set(ave_freq.value, cr, Util.round(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz')
local load_percent = Util.round(load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE, 2) local load_percent = Util.round(load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE, 2)
CriticalText.set(total_load.value, cr, load_percent * 100) CriticalText.set(total_load.value, cr, load_percent * 100)
LabelPlot.update(plot, load_percent) LabelPlot.update(plot, load_percent)
for c = 1, 3 do for c = 1, 3 do
local column = TABLE_CONKY[c] local column = TABLE_CONKY[c]
for r = 1, NUM_ROWS do for r = 1, NUM_ROWS do
Table.set(tbl, cr, c, r, conky(column[r], '(%S+)')) Table.set(tbl, cr, c, r, conky(column[r], '(%S+)'))
end end
end end
end end
_MODULE_Y_ = nil _MODULE_Y_ = nil
@ -246,34 +246,34 @@ _PROCESS_Y_ = nil
_PLOT_Y_ = nil _PLOT_Y_ = nil
local draw = function(cr, current_interface) local draw = function(cr, current_interface)
update(cr) update(cr)
if current_interface == 0 then if current_interface == 0 then
Text.draw(header.text, cr) Text.draw(header.text, cr)
Line.draw(header.underline, cr) Line.draw(header.underline, cr)
for c = 1, NUM_PHYSICAL_CORES do for c = 1, NUM_PHYSICAL_CORES do
local core = cores[c] local core = cores[c]
CompoundDial.draw(core.dials, cr) CompoundDial.draw(core.dials, cr)
Arc.draw(core.inner_ring, cr) Arc.draw(core.inner_ring, cr)
CriticalText.draw(core.coretemp_text, cr) CriticalText.draw(core.coretemp_text, cr)
end end
Text.draw(process.label, cr) Text.draw(process.label, cr)
Text.draw(process.value, cr) Text.draw(process.value, cr)
Text.draw(ave_freq.label, cr) Text.draw(ave_freq.label, cr)
Text.draw(ave_freq.value, cr) Text.draw(ave_freq.value, cr)
Line.draw(separator, cr) Line.draw(separator, cr)
Text.draw(total_load.label, cr) Text.draw(total_load.label, cr)
CriticalText.draw(total_load.value, cr) CriticalText.draw(total_load.value, cr)
LabelPlot.draw(plot, cr) LabelPlot.draw(plot, cr)
Table.draw(tbl, cr) Table.draw(tbl, cr)
end end
end end
return draw return draw