2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local Arc = require 'Arc'
|
|
|
|
local CompoundDial = require 'CompoundDial'
|
|
|
|
local CriticalText = require 'CriticalText'
|
|
|
|
local Text = require 'Text'
|
|
|
|
local Line = require 'Line'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
|
|
|
local Table = require 'Table'
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2019-09-01 15:34:10 -04:00
|
|
|
local __string_format = string.format
|
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local CORETEMP_PATH = '/sys/devices/platform/coretemp.0/hwmon/hwmon%i/%s'
|
|
|
|
|
|
|
|
local NUM_PHYSICAL_CORES = 4
|
|
|
|
local NUM_THREADS_PER_CORE = 2
|
|
|
|
|
|
|
|
local NUM_ROWS = 5
|
2018-08-04 17:54:34 -04:00
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
local HWP_PATHS = {}
|
|
|
|
|
|
|
|
for i = 1, NUM_ROWS do
|
|
|
|
HWP_PATHS[i] = '/sys/devices/system/cpu/cpu' .. i ..
|
|
|
|
'/cpufreq/energy_performance_preference'
|
|
|
|
end
|
|
|
|
|
2018-08-04 17:54:34 -04:00
|
|
|
local TABLE_CONKY = {}
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
for r = 1, NUM_ROWS do
|
2018-08-04 17:54:34 -04:00
|
|
|
TABLE_CONKY[r] = {}
|
|
|
|
TABLE_CONKY[r].pid = '${top pid '..r..'}'
|
|
|
|
TABLE_CONKY[r].cpu = '${top cpu '..r..'}'
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2017-10-23 02:40:12 -04:00
|
|
|
local _MODULE_Y_ = 614
|
2017-07-19 00:36:15 -04:00
|
|
|
local _DIAL_INNER_RADIUS_ = 30
|
|
|
|
local _DIAL_OUTER_RADIUS_ = 42
|
|
|
|
local _DIAL_SPACING_ = 1
|
|
|
|
local _SEPARATOR_SPACING_ = 20
|
2017-10-23 02:40:12 -04:00
|
|
|
local _TEXT_SPACING_ = 22
|
2017-07-19 00:36:15 -04:00
|
|
|
local _PLOT_SECTION_BREAK_ = 23
|
|
|
|
local _PLOT_HEIGHT_ = 56
|
|
|
|
local _TABLE_SECTION_BREAK_ = 20
|
|
|
|
local _TABLE_HEIGHT_ = 114
|
|
|
|
|
|
|
|
local _create_core_ = function(cores, id, x, y)
|
2018-01-05 23:36:50 -05:00
|
|
|
local conky_loads = {}
|
|
|
|
local conky_freqs = {}
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-01-05 23:36:50 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
local hwmon_index = -1
|
|
|
|
while Util.read_file(string.format(CORETEMP_PATH, hwmon_index, 'name'), nil, '*l') ~= 'coretemp' do
|
|
|
|
hwmon_index = hwmon_index + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
cores[id +1] = {
|
|
|
|
dials = _G_Widget_.CompoundDial{
|
|
|
|
x = x,
|
2019-09-01 15:34:10 -04:00
|
|
|
y = y,
|
2018-01-05 23:36:50 -05:00
|
|
|
inner_radius = _DIAL_INNER_RADIUS_,
|
|
|
|
outer_radius = _DIAL_OUTER_RADIUS_,
|
|
|
|
spacing = _DIAL_SPACING_,
|
|
|
|
num_dials = NUM_THREADS_PER_CORE,
|
|
|
|
critical_limit = '>0.8'
|
|
|
|
},
|
|
|
|
inner_ring = _G_Widget_.Arc{
|
|
|
|
x = x,
|
|
|
|
y = y,
|
|
|
|
radius = _DIAL_INNER_RADIUS_ - 2,
|
|
|
|
theta0 = 0,
|
|
|
|
theta1 = 360
|
|
|
|
},
|
|
|
|
coretemp_text = _G_Widget_.CriticalText{
|
|
|
|
x = x,
|
|
|
|
y = y,
|
|
|
|
x_align = 'center',
|
|
|
|
y_align = 'center',
|
|
|
|
append_end = '°C',
|
|
|
|
critical_limit = '>90'
|
|
|
|
},
|
|
|
|
coretemp_path = string.format(CORETEMP_PATH, hwmon_index, 'temp'..(id + 2)..'_input'),
|
|
|
|
conky_loads = conky_loads,
|
|
|
|
conky_freqs = conky_freqs
|
|
|
|
}
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local header = _G_Widget_.Header{
|
2018-01-05 23:36:50 -05:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _MODULE_Y_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
header = 'PROCESSOR'
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
--we assume that this cpu has 4 physical cores with 2 logical each
|
|
|
|
local cores = {}
|
|
|
|
|
|
|
|
for c = 0, NUM_PHYSICAL_CORES - 1 do
|
2018-01-05 23:36:50 -05:00
|
|
|
local dial_x = _G_INIT_DATA_.LEFT_X + _DIAL_OUTER_RADIUS_ +
|
2017-07-19 00:36:15 -04:00
|
|
|
(_G_INIT_DATA_.SECTION_WIDTH - 2 * _DIAL_OUTER_RADIUS_) * c / 3
|
2018-01-05 23:36:50 -05:00
|
|
|
local dial_y = header.bottom_y + _DIAL_OUTER_RADIUS_
|
|
|
|
_create_core_(cores, c, dial_x, dial_y)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local _RIGHT_X_ = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH
|
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
local _HWP_Y_ = header.bottom_y + _DIAL_OUTER_RADIUS_ * 2 + _PLOT_SECTION_BREAK_
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
local hwp = {
|
2018-01-05 23:36:50 -05:00
|
|
|
label = _G_Widget_.Text{
|
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
2020-01-28 20:06:56 -05:00
|
|
|
y = _HWP_Y_,
|
|
|
|
text = 'HWP Preference'
|
2018-01-05 23:36:50 -05:00
|
|
|
},
|
|
|
|
value = _G_Widget_.Text{
|
|
|
|
x = _RIGHT_X_,
|
2020-01-28 20:06:56 -05:00
|
|
|
y = _HWP_Y_,
|
2018-01-05 23:36:50 -05:00
|
|
|
x_align = 'right',
|
|
|
|
text_color = _G_Patterns_.BLUE,
|
2020-01-28 20:06:56 -05:00
|
|
|
text = '<hwp_pref>'
|
2018-01-05 23:36:50 -05:00
|
|
|
}
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
local _FREQ_Y_ = _HWP_Y_ + _TEXT_SPACING_
|
2017-10-23 02:40:12 -04:00
|
|
|
|
|
|
|
local ave_freq = {
|
2018-01-05 23:36:50 -05:00
|
|
|
label = _G_Widget_.Text{
|
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _FREQ_Y_,
|
|
|
|
text = 'Ave Freq'
|
|
|
|
},
|
|
|
|
value = _G_Widget_.Text{
|
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _FREQ_Y_,
|
|
|
|
x_align = 'right',
|
2020-01-28 20:22:15 -05:00
|
|
|
text_color = _G_Patterns_.BLUE,
|
2018-01-05 23:36:50 -05:00
|
|
|
text = '<freq>'
|
|
|
|
}
|
2017-10-23 02:40:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local separator = _G_Widget_.Line{
|
2018-01-05 23:36:50 -05:00
|
|
|
p1 = {x = _G_INIT_DATA_.LEFT_X, y = _SEP_Y_},
|
|
|
|
p2 = {x = _RIGHT_X_, y = _SEP_Y_}
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
|
|
|
|
|
|
|
|
local total_load = {
|
2018-01-05 23:36:50 -05:00
|
|
|
label = _G_Widget_.Text{
|
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _LOAD_Y_,
|
|
|
|
text = 'Total Load'
|
|
|
|
},
|
|
|
|
value = _G_Widget_.CriticalText{
|
|
|
|
x = _RIGHT_X_,
|
|
|
|
y = _LOAD_Y_,
|
|
|
|
x_align = 'right',
|
|
|
|
append_end = '%',
|
|
|
|
critical_limit = '>80'
|
2019-09-01 15:34:10 -04:00
|
|
|
}
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local plot = _G_Widget_.LabelPlot{
|
2018-01-05 23:36:50 -05:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _PLOT_Y_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
height = _PLOT_HEIGHT_
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
2017-07-20 00:49:24 -04:00
|
|
|
local tbl = _G_Widget_.Table{
|
2018-01-05 23:36:50 -05:00
|
|
|
x = _G_INIT_DATA_.LEFT_X,
|
|
|
|
y = _PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
|
|
|
width = _G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
height = _TABLE_HEIGHT_,
|
|
|
|
num_rows = NUM_ROWS,
|
|
|
|
'Name',
|
|
|
|
'PID',
|
|
|
|
'CPU (%)'
|
2017-07-19 00:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
local update = function(cr)
|
2018-01-05 23:36:50 -05:00
|
|
|
local conky = Util.conky
|
|
|
|
local char_count = Util.char_count
|
|
|
|
|
|
|
|
local load_sum = 0
|
|
|
|
local freq_sum = 0
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-01-05 23:36:50 -05:00
|
|
|
for c = 1, NUM_PHYSICAL_CORES do
|
|
|
|
local core = cores[c]
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-01-05 23:36:50 -05:00
|
|
|
local conky_loads = core.conky_loads
|
|
|
|
local conky_freqs = core.conky_freqs
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-01-05 23:36:50 -05:00
|
|
|
for t = 1, NUM_THREADS_PER_CORE do
|
|
|
|
local percent = Util.conky_numeric(conky_loads[t]) * 0.01
|
|
|
|
CompoundDial.set(core.dials, t, percent)
|
|
|
|
load_sum = load_sum + percent
|
|
|
|
|
|
|
|
freq_sum = freq_sum + Util.conky_numeric(conky_freqs[t])
|
|
|
|
end
|
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
CriticalText.set(
|
|
|
|
core.coretemp_text, cr,
|
|
|
|
Util.round_to_string(
|
|
|
|
0.001 * Util.read_file(core.coretemp_path, nil, '*n')))
|
2018-01-05 23:36:50 -05:00
|
|
|
end
|
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
-- read HWP of first cpu, then test all others to see if they match
|
|
|
|
local hwp_pref = Util.read_file(HWP_PATHS[1], nil, "*l")
|
|
|
|
local mixed = nil
|
|
|
|
local i = 2
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
while not mixed and i <= #HWP_PATHS do
|
|
|
|
if hwp_pref ~= Util.read_file(HWP_PATHS[i], nil, '*l') then
|
|
|
|
mixed = 0
|
|
|
|
end
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if mixed then
|
|
|
|
Text.set(hwp.value, cr, "Mixed")
|
|
|
|
elseif hwp_pref == "power" then
|
|
|
|
Text.set(hwp.value, cr, "Power")
|
|
|
|
elseif hwp_pref == "balance_power" then
|
|
|
|
Text.set(hwp.value, cr, "Bal. Power")
|
|
|
|
elseif hwp_pref == "balance_performance" then
|
|
|
|
Text.set(hwp.value, cr, "Bal. Performance")
|
|
|
|
elseif hwp_pref == "performance" then
|
|
|
|
Text.set(hwp.value, cr, "Performance")
|
|
|
|
elseif hwp_pref == "default" then
|
|
|
|
Text.set(hwp.value, cr, "Default")
|
|
|
|
else
|
|
|
|
Text.set(hwp.value, cr, "Unknown")
|
|
|
|
end
|
2018-01-05 23:36:50 -05:00
|
|
|
|
2019-09-01 15:34:10 -04:00
|
|
|
Text.set(ave_freq.value, cr, Util.round_to_string(freq_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE) .. ' MHz')
|
2018-01-05 23:36:50 -05:00
|
|
|
|
|
|
|
local load_percent = Util.round(load_sum / NUM_PHYSICAL_CORES / NUM_THREADS_PER_CORE, 2)
|
2019-09-01 15:34:10 -04:00
|
|
|
CriticalText.set(total_load.value, cr,
|
|
|
|
Util.round_to_string(load_percent * 100))
|
2018-01-05 23:36:50 -05:00
|
|
|
|
|
|
|
LabelPlot.update(plot, load_percent)
|
|
|
|
|
2018-08-04 17:54:34 -04:00
|
|
|
for r = 1, NUM_ROWS do
|
2019-10-12 10:33:32 -04:00
|
|
|
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
|
2019-09-01 15:34:10 -04:00
|
|
|
if pid ~= '' then
|
|
|
|
local cpu = conky(TABLE_CONKY[r].cpu)
|
2019-10-12 11:42:44 -04:00
|
|
|
local comm = Util.read_file('/proc/'..pid..'/comm', '(%C+)')
|
2019-09-01 15:34:10 -04:00
|
|
|
Table.set(tbl, cr, 1, r, comm)
|
|
|
|
Table.set(tbl, cr, 2, r, pid)
|
|
|
|
Table.set(tbl, cr, 3, r, cpu)
|
|
|
|
end
|
2018-01-05 23:36:50 -05:00
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
_MODULE_Y_ = nil
|
|
|
|
_DIAL_INNER_RADIUS_ = nil
|
|
|
|
_DIAL_OUTER_RADIUS_ = nil
|
|
|
|
_DIAL_SPACING_ = nil
|
|
|
|
_TEXT_Y_OFFSET_ = nil
|
|
|
|
_SEPARATOR_SPACING_ = nil
|
2017-10-23 02:40:12 -04:00
|
|
|
_TEXT_SPACING_ = nil
|
2017-07-19 00:36:15 -04:00
|
|
|
_PLOT_SECTION_BREAK_ = nil
|
|
|
|
_PLOT_HEIGHT_ = nil
|
|
|
|
_TABLE_SECTION_BREAK_ = nil
|
|
|
|
_TABLE_HEIGHT_ = nil
|
|
|
|
_create_core_ = nil
|
2017-10-23 02:40:12 -04:00
|
|
|
_FREQ_Y_ = nil
|
2017-07-19 00:36:15 -04:00
|
|
|
_LOAD_Y_ = nil
|
|
|
|
_RIGHT_X_ = nil
|
|
|
|
_SEP_Y_ = nil
|
2020-01-28 20:06:56 -05:00
|
|
|
_HWP_Y_ = nil
|
2017-07-19 00:36:15 -04:00
|
|
|
_PLOT_Y_ = nil
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
local draw_static = function(cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Text.draw(header.text, cr)
|
|
|
|
Line.draw(header.underline, cr)
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-08-05 11:35:00 -04:00
|
|
|
for c = 1, NUM_PHYSICAL_CORES do
|
|
|
|
local this_core = cores[c]
|
|
|
|
Arc.draw(this_core.inner_ring, cr)
|
2018-08-05 14:45:41 -04:00
|
|
|
CompoundDial.draw_static(this_core.dials, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
end
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
Text.draw(hwp.label, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
Text.draw(ave_freq.label, cr)
|
|
|
|
Line.draw(separator, cr)
|
|
|
|
|
|
|
|
Text.draw(total_load.label, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_static(plot, cr)
|
2018-08-05 11:56:11 -04:00
|
|
|
|
|
|
|
Table.draw_static(tbl, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local draw_dynamic = function(cr)
|
2018-01-05 23:36:50 -05:00
|
|
|
update(cr)
|
|
|
|
|
2018-08-05 11:08:37 -04:00
|
|
|
for c = 1, NUM_PHYSICAL_CORES do
|
2018-08-05 11:35:00 -04:00
|
|
|
local this_core = cores[c]
|
2018-08-05 14:45:41 -04:00
|
|
|
CompoundDial.draw_dynamic(this_core.dials, cr)
|
2018-08-05 11:35:00 -04:00
|
|
|
CriticalText.draw(this_core.coretemp_text, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
end
|
2018-01-05 23:36:50 -05:00
|
|
|
|
2020-01-28 20:06:56 -05:00
|
|
|
Text.draw(hwp.value, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
Text.draw(ave_freq.value, cr)
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-08-05 11:08:37 -04:00
|
|
|
CriticalText.draw(total_load.value, cr)
|
2018-08-05 14:29:52 -04:00
|
|
|
LabelPlot.draw_dynamic(plot, cr)
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2018-08-05 11:56:11 -04:00
|
|
|
Table.draw_dynamic(tbl, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
M.draw_static = draw_static
|
|
|
|
M.draw_dynamic = draw_dynamic
|
|
|
|
|
|
|
|
return M
|