conky-config/drawing/processor.lua

202 lines
5.7 KiB
Lua
Raw Normal View History

2021-08-08 18:19:37 -04:00
local compound_dial = require 'compound_dial'
2021-07-29 22:37:30 -04:00
local line = require 'line'
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'
local common = require 'common'
local geometry = require 'geometry'
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
2021-07-17 23:06:30 -04:00
return function(update_freq)
local MODULE_Y = 614
local DIAL_INNER_RADIUS = 30
local DIAL_OUTER_RADIUS = 42
local DIAL_THICKNESS = 5.5
local SEPARATOR_SPACING = 20
local TEXT_SPACING = 22
local PLOT_SECTION_BREAK = 23
local PLOT_HEIGHT = 56
local TABLE_SECTION_BREAK = 20
local TABLE_HEIGHT = 114
-----------------------------------------------------------------------------
-- header
local header = common.make_header(
geometry.LEFT_X,
2021-07-17 23:06:30 -04:00
MODULE_Y,
geometry.SECTION_WIDTH,
2021-07-17 23:06:30 -04:00
'PROCESSOR'
)
2017-07-19 00:36:15 -04:00
2021-07-17 23:06:30 -04:00
-----------------------------------------------------------------------------
-- cores (loads and temps)
local cpu_loads = cpu.init_cpu_loads()
local ncpus = cpu.get_cpu_number()
local ncores = cpu.get_core_number()
2021-07-17 21:22:17 -04:00
local nthreads = ncpus / ncores
local hwp_paths = cpu.get_hwp_paths()
local coretemp_paths = cpu.get_coretemp_paths()
cpu.read_cpu_loads(cpu_loads) -- prime load matrix by side effect
2021-07-17 21:22:17 -04:00
local cores = {}
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,
0.8,
nthreads
),
coretemp = common.make_text_circle(
2021-07-17 23:06:30 -04:00
x,
y,
DIAL_INNER_RADIUS - 2,
'%s°C',
90
)
}
end
2021-07-17 21:22:17 -04:00
for c = 1, ncores do
local dial_x = geometry.LEFT_X + DIAL_OUTER_RADIUS +
(geometry.SECTION_WIDTH - 2 * DIAL_OUTER_RADIUS) * (c - 1) / 3
2021-07-17 23:06:30 -04:00
local dial_y = header.bottom_y + DIAL_OUTER_RADIUS
cores[c] = create_core(dial_x, dial_y)
2021-07-17 21:22:17 -04:00
end
2021-07-17 23:06:30 -04:00
-----------------------------------------------------------------------------
-- HWP status
local HWP_Y = header.bottom_y + DIAL_OUTER_RADIUS * 2 + PLOT_SECTION_BREAK
local cpu_status = common.make_text_rows(
geometry.LEFT_X,
2021-07-17 23:06:30 -04:00
HWP_Y,
geometry.SECTION_WIDTH,
2021-07-17 23:06:30 -04:00
TEXT_SPACING,
{'HWP Preference', 'Ave Freq'}
)
-----------------------------------------------------------------------------
-- frequency
local SEP_Y = HWP_Y + TEXT_SPACING + SEPARATOR_SPACING
local separator = common.make_separator(
geometry.LEFT_X,
2021-07-17 23:06:30 -04:00
SEP_Y,
geometry.SECTION_WIDTH
2021-07-17 23:06:30 -04:00
)
-----------------------------------------------------------------------------
-- total load plot
local LOAD_Y = SEP_Y + SEPARATOR_SPACING
2021-07-30 22:46:20 -04:00
local total_load = common.make_tagged_percent_timeseries(
geometry.LEFT_X,
2021-07-17 23:06:30 -04:00
LOAD_Y,
geometry.SECTION_WIDTH,
2021-07-17 23:06:30 -04:00
PLOT_HEIGHT,
PLOT_SECTION_BREAK,
"Total Load",
update_freq
)
2021-07-17 23:06:30 -04:00
local PLOT_Y = LOAD_Y + PLOT_SECTION_BREAK
-----------------------------------------------------------------------------
-- cpu top table
local NUM_ROWS = 5
2021-08-08 17:15:39 -04:00
local TABLE_CONKY = pure.map_n(
2021-07-23 01:41:06 -04:00
function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
2021-08-08 17:15:39 -04:00
NUM_ROWS
2021-07-23 01:41:06 -04:00
)
2021-07-17 23:06:30 -04:00
local tbl = common.make_text_table(
geometry.LEFT_X,
2021-07-17 23:06:30 -04:00
PLOT_Y + PLOT_HEIGHT + TABLE_SECTION_BREAK,
geometry.SECTION_WIDTH,
2021-07-17 23:06:30 -04:00
TABLE_HEIGHT,
NUM_ROWS,
2021-08-08 18:06:28 -04:00
'CPU (%)'
2021-07-17 23:06:30 -04:00
)
-----------------------------------------------------------------------------
-- main functions
2021-07-26 23:45:54 -04:00
local update = function(trigger)
local load_sum = 0
cpu_loads = cpu.read_cpu_loads(cpu_loads)
2021-07-17 21:22:17 -04:00
for _, load_data in pairs(cpu_loads) do
local cur = load_data.percent_active
load_sum = load_sum + cur
2021-08-08 18:19:37 -04:00
compound_dial.set(cores[load_data.conky_core_id].loads, load_data.conky_thread_id, cur)
2021-07-17 21:22:17 -04:00
end
2021-07-17 22:45:30 -04:00
for conky_core_id, path in pairs(coretemp_paths) do
2021-08-08 15:58:53 -04:00
local temp = __math_floor(0.001 * i_o.read_file(path, nil, '*n'))
2021-07-30 22:02:46 -04:00
common.text_circle_set(cores[conky_core_id].coretemp, temp)
end
2018-01-05 23:36:50 -05: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
if trigger == 0 then
common.text_rows_set(cpu_status, 1, cpu.read_hwp(hwp_paths))
end
common.text_rows_set(cpu_status, 2, cpu.read_freq())
2021-07-30 22:46:20 -04:00
common.tagged_percent_timeseries_set(total_load, load_sum / ncpus * 100)
for r = 1, NUM_ROWS do
2021-08-08 15:58:53 -04:00
local pid = i_o.conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
if pid ~= '' then
2021-08-08 18:19:37 -04:00
text_table.set(tbl, 1, r, i_o.read_file('/proc/'..pid..'/comm', '(%C+)'))
text_table.set(tbl, 2, r, pid)
text_table.set(tbl, 3, r, i_o.conky(TABLE_CONKY[r].cpu))
end
2019-09-01 15:34:10 -04:00
end
end
local draw_static = function(cr)
common.draw_header(cr, header)
2021-07-17 23:06:30 -04:00
for i = 1, #cores do
2021-07-30 22:02:46 -04:00
common.text_circle_draw_static(cores[i].coretemp, cr)
2021-08-08 18:19:37 -04:00
compound_dial.draw_static(cores[i].loads, cr)
end
2018-08-05 11:56:11 -04:00
common.text_rows_draw_static(cpu_status, cr)
2021-07-29 22:37:30 -04:00
line.draw(separator, cr)
2021-07-30 22:46:20 -04:00
common.tagged_percent_timeseries_draw_static(total_load, cr)
2018-01-05 23:36:50 -05:00
2021-08-08 18:19:37 -04:00
text_table.draw_static(tbl, cr)
2018-08-05 11:08:37 -04:00
end
2018-01-05 23:36:50 -05:00
local draw_dynamic = function(cr)
2021-07-17 23:06:30 -04:00
for i = 1, #cores do
2021-08-08 18:19:37 -04:00
compound_dial.draw_dynamic(cores[i].loads, cr)
2021-07-30 22:02:46 -04:00
common.text_circle_draw_dynamic(cores[i].coretemp, cr)
end
common.text_rows_draw_dynamic(cpu_status, cr)
2021-07-30 22:46:20 -04:00
common.tagged_percent_timeseries_draw_dynamic(total_load, cr)
2021-08-08 18:19:37 -04:00
text_table.draw_dynamic(tbl, cr)
end
2017-07-19 00:36:15 -04:00
return {static = draw_static, dynamic = draw_dynamic, update = update}
end