2022-07-11 02:50:39 -04:00
|
|
|
local compound_dial = require 'compound_dial'
|
2021-08-08 18:19:37 -04:00
|
|
|
local text_table = require 'text_table'
|
2021-08-08 15:58:53 -04:00
|
|
|
local i_o = require 'i_o'
|
2021-08-08 15:10:09 -04:00
|
|
|
local cpu = require 'sys'
|
|
|
|
local pure = require 'pure'
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2021-07-13 01:01:21 -04:00
|
|
|
local __math_floor = math.floor
|
2021-07-12 23:49:52 -04:00
|
|
|
|
2022-07-17 18:40:24 -04:00
|
|
|
return function(update_freq, config, main_state, common, width, point)
|
2021-07-17 23:06:30 -04:00
|
|
|
local DIAL_INNER_RADIUS = 30
|
|
|
|
local DIAL_OUTER_RADIUS = 42
|
|
|
|
local DIAL_THICKNESS = 5.5
|
2022-07-18 00:36:44 -04:00
|
|
|
local DIAL_SPACING = 20
|
2021-07-17 23:06:30 -04:00
|
|
|
local SEPARATOR_SPACING = 20
|
|
|
|
local TEXT_SPACING = 22
|
|
|
|
local PLOT_SECTION_BREAK = 23
|
|
|
|
local PLOT_HEIGHT = 56
|
|
|
|
local TABLE_SECTION_BREAK = 20
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
2022-07-16 23:48:01 -04:00
|
|
|
-- processor state
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
local mod_state = cpu.read_cpu_loads(cpu.init_cpu_loads())
|
|
|
|
|
|
|
|
local update_state = function()
|
|
|
|
mod_state = cpu.read_cpu_loads(mod_state)
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
|
|
|
|
2022-07-16 23:48:01 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- cores (loads and temps)
|
|
|
|
|
2021-07-29 22:39:38 -04:00
|
|
|
local ncpus = cpu.get_cpu_number()
|
|
|
|
local ncores = cpu.get_core_number()
|
2021-07-17 21:22:17 -04:00
|
|
|
local nthreads = ncpus / ncores
|
|
|
|
|
2022-07-18 00:36:44 -04:00
|
|
|
local show_cores = false
|
|
|
|
|
|
|
|
if config.core_rows > 0 then
|
|
|
|
if math.fmod(ncores, config.core_rows) == 0 then
|
|
|
|
show_cores = true
|
|
|
|
else
|
|
|
|
print(
|
|
|
|
string.format(
|
|
|
|
'WARNING: could not evenly distribute %i cores over %i rows',
|
|
|
|
ncores,
|
|
|
|
config.core_rows
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-17 23:06:30 -04:00
|
|
|
local create_core = function(x, y)
|
|
|
|
return {
|
2021-07-30 22:02:46 -04:00
|
|
|
loads = common.make_compound_dial(
|
2021-07-17 23:06:30 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
DIAL_OUTER_RADIUS,
|
|
|
|
DIAL_INNER_RADIUS,
|
|
|
|
DIAL_THICKNESS,
|
2021-11-10 12:24:13 -05:00
|
|
|
80,
|
2021-07-17 23:06:30 -04:00
|
|
|
nthreads
|
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
coretemp = common.make_text_circle(
|
2021-07-17 23:06:30 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
DIAL_INNER_RADIUS - 2,
|
|
|
|
'%s°C',
|
2021-11-10 16:26:48 -05:00
|
|
|
80,
|
|
|
|
__math_floor
|
2021-07-17 23:06:30 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-07-11 02:50:39 -04:00
|
|
|
local mk_cores = function(y)
|
|
|
|
local coretemp_paths = cpu.get_coretemp_paths()
|
2022-07-18 00:36:44 -04:00
|
|
|
local core_cols = ncores / config.core_rows
|
2022-07-11 02:50:39 -04:00
|
|
|
local cores = {}
|
|
|
|
for c = 1, ncores do
|
2022-07-18 00:36:44 -04:00
|
|
|
local dial_x
|
|
|
|
local dial_y
|
|
|
|
if core_cols == 1 then
|
|
|
|
dial_x = point.x + width / 2
|
|
|
|
dial_y = y + DIAL_OUTER_RADIUS +
|
|
|
|
(2 * DIAL_OUTER_RADIUS + DIAL_SPACING) * (c - 1)
|
|
|
|
else
|
|
|
|
dial_x = point.x + config.core_padding + DIAL_OUTER_RADIUS +
|
|
|
|
(width - 2 * (DIAL_OUTER_RADIUS + config.core_padding))
|
|
|
|
* math.fmod(c - 1, core_cols) / (core_cols - 1)
|
|
|
|
dial_y = y + DIAL_OUTER_RADIUS +
|
|
|
|
(2 * DIAL_OUTER_RADIUS + DIAL_SPACING)
|
|
|
|
* math.floor((c - 1) / core_cols) / (core_cols - 1)
|
|
|
|
end
|
2022-07-11 02:50:39 -04:00
|
|
|
cores[c] = create_core(dial_x, dial_y)
|
|
|
|
end
|
2022-07-16 23:48:01 -04:00
|
|
|
local update = function()
|
|
|
|
for _, load_data in pairs(mod_state) do
|
2022-07-11 02:50:39 -04:00
|
|
|
compound_dial.set(
|
|
|
|
cores[load_data.conky_core_id].loads,
|
|
|
|
load_data.conky_thread_id,
|
2022-07-16 23:48:01 -04:00
|
|
|
load_data.percent_active * 100
|
2022-07-11 02:50:39 -04:00
|
|
|
)
|
|
|
|
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
|
|
|
|
end
|
|
|
|
local static = function(cr)
|
|
|
|
for i = 1, #cores do
|
|
|
|
common.text_circle_draw_static(cores[i].coretemp, cr)
|
|
|
|
compound_dial.draw_static(cores[i].loads, cr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local dynamic = function(cr)
|
|
|
|
for i = 1, #cores do
|
|
|
|
common.text_circle_draw_dynamic(cores[i].coretemp, cr)
|
2022-07-12 01:23:59 -04:00
|
|
|
compound_dial.draw_dynamic(cores[i].loads, cr)
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
|
|
|
end
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-18 00:36:44 -04:00
|
|
|
(DIAL_OUTER_RADIUS * 2 + DIAL_SPACING) * config.core_rows
|
|
|
|
- DIAL_SPACING,
|
2022-07-16 00:00:06 -04:00
|
|
|
update,
|
|
|
|
static,
|
|
|
|
dynamic
|
|
|
|
)
|
2021-07-17 21:22:17 -04:00
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-17 23:06:30 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- HWP status
|
|
|
|
|
2022-07-11 02:50:39 -04:00
|
|
|
local mk_hwp_freq = function(y)
|
|
|
|
local hwp_paths = cpu.get_hwp_paths()
|
|
|
|
local cpu_status = common.make_text_rows(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-11 02:50:39 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-11 02:50:39 -04:00
|
|
|
TEXT_SPACING,
|
|
|
|
{'HWP Preference', 'Ave Freq'}
|
|
|
|
)
|
2022-07-16 23:48:01 -04:00
|
|
|
local update = function()
|
2022-07-11 02:50:39 -04:00
|
|
|
-- For some reason this call is slow (querying anything with pstate in
|
|
|
|
-- general seems slow), but I also don't need to see an update every
|
|
|
|
-- cycle, hence the trigger
|
2022-07-16 23:48:01 -04:00
|
|
|
if main_state.trigger10 == 0 then
|
2022-07-11 02:50:39 -04:00
|
|
|
common.text_rows_set(cpu_status, 1, cpu.read_hwp(hwp_paths))
|
|
|
|
end
|
|
|
|
common.text_rows_set(cpu_status, 2, cpu.read_freq())
|
|
|
|
end
|
|
|
|
local static = pure.partial(common.text_rows_draw_static, cpu_status)
|
|
|
|
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-16 00:00:06 -04:00
|
|
|
TEXT_SPACING,
|
|
|
|
update,
|
|
|
|
static,
|
|
|
|
dynamic
|
|
|
|
)
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
2021-07-17 23:06:30 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- total load plot
|
|
|
|
|
2022-07-11 02:50:39 -04:00
|
|
|
local mk_load_plot = function(y)
|
|
|
|
local total_load = common.make_tagged_percent_timeseries(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-11 02:50:39 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-11 02:50:39 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
PLOT_SECTION_BREAK,
|
|
|
|
"Total Load",
|
|
|
|
update_freq
|
|
|
|
)
|
2022-07-16 23:48:01 -04:00
|
|
|
local update = function()
|
|
|
|
local s = 0
|
|
|
|
for i = 1, #mod_state do
|
|
|
|
s = s + mod_state[i].percent_active
|
|
|
|
end
|
|
|
|
common.tagged_percent_timeseries_set(total_load, s / ncpus * 100)
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-16 00:00:06 -04:00
|
|
|
PLOT_HEIGHT + PLOT_SECTION_BREAK,
|
|
|
|
update,
|
2022-07-18 23:44:51 -04:00
|
|
|
pure.partial(common.tagged_percent_timeseries_draw_static, total_load),
|
|
|
|
pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load)
|
2022-07-16 00:00:06 -04:00
|
|
|
)
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
2021-07-17 23:06:30 -04:00
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- cpu top table
|
|
|
|
|
2022-07-11 02:50:39 -04:00
|
|
|
local mk_tbl = function(y)
|
2022-07-18 00:36:44 -04:00
|
|
|
local num_rows = config.table_rows
|
|
|
|
local table_height = common.table_height(num_rows)
|
|
|
|
local table_conky = pure.map_n(
|
2022-07-11 02:50:39 -04:00
|
|
|
function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
|
2022-07-18 00:36:44 -04:00
|
|
|
num_rows
|
2022-07-11 02:50:39 -04:00
|
|
|
)
|
|
|
|
local tbl = common.make_text_table(
|
2022-07-14 20:13:29 -04:00
|
|
|
point.x,
|
2022-07-11 02:50:39 -04:00
|
|
|
y,
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-18 00:36:44 -04:00
|
|
|
table_height,
|
|
|
|
num_rows,
|
2022-07-11 02:50:39 -04:00
|
|
|
'CPU (%)'
|
|
|
|
)
|
2022-07-18 00:36:44 -04:00
|
|
|
local update = function()
|
|
|
|
for r = 1, num_rows do
|
|
|
|
local pid = i_o.conky(table_conky[r].pid, '(%d+)') -- may have leading spaces
|
2022-07-11 02:50:39 -04:00
|
|
|
if pid ~= '' then
|
|
|
|
text_table.set(tbl, 1, r, i_o.read_file('/proc/'..pid..'/comm', '(%C+)'))
|
|
|
|
text_table.set(tbl, 2, r, pid)
|
2022-07-18 00:36:44 -04:00
|
|
|
text_table.set(tbl, 3, r, i_o.conky(table_conky[r].cpu))
|
2022-07-11 02:50:39 -04:00
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
2019-09-01 15:34:10 -04:00
|
|
|
end
|
2022-07-17 18:54:23 -04:00
|
|
|
return common.mk_acc(
|
2022-07-17 12:40:36 -04:00
|
|
|
width,
|
2022-07-18 00:36:44 -04:00
|
|
|
table_height,
|
2022-07-16 00:00:06 -04:00
|
|
|
update,
|
2022-07-18 00:36:44 -04:00
|
|
|
pure.partial(text_table.draw_static, tbl),
|
|
|
|
pure.partial(text_table.draw_dynamic, tbl)
|
2022-07-16 00:00:06 -04:00
|
|
|
)
|
2018-08-05 11:35:00 -04:00
|
|
|
end
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2022-07-11 02:50:39 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- main functions
|
2018-08-05 11:35:00 -04:00
|
|
|
|
2022-07-17 19:12:31 -04:00
|
|
|
return {
|
|
|
|
header = 'PROCESSOR',
|
|
|
|
point = point,
|
|
|
|
width = width,
|
2022-07-17 22:30:38 -04:00
|
|
|
set_state = update_state,
|
2022-07-17 19:12:31 -04:00
|
|
|
top = {
|
2022-07-18 00:36:44 -04:00
|
|
|
{mk_cores, show_cores, TEXT_SPACING},
|
2022-07-16 23:48:01 -04:00
|
|
|
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
|
|
|
|
},
|
2022-07-17 18:54:23 -04:00
|
|
|
common.mk_section(
|
2022-07-16 23:48:01 -04:00
|
|
|
SEPARATOR_SPACING,
|
|
|
|
{mk_load_plot, config.show_plot, TABLE_SECTION_BREAK},
|
2022-07-18 00:36:44 -04:00
|
|
|
{mk_tbl, config.table_rows > 0, 0}
|
2022-07-16 23:48:01 -04:00
|
|
|
)
|
2022-07-17 19:12:31 -04:00
|
|
|
}
|
2021-07-17 00:17:22 -04:00
|
|
|
end
|