2017-07-19 00:36:15 -04:00
|
|
|
local CompoundDial = require 'CompoundDial'
|
2021-07-17 23:06:30 -04:00
|
|
|
local Line = require 'Line'
|
|
|
|
local Table = require 'Table'
|
|
|
|
local Util = require 'Util'
|
|
|
|
local Common = require 'Common'
|
2021-07-16 23:25:44 -04:00
|
|
|
local Geometry = require 'Geometry'
|
2021-07-17 21:22:17 -04:00
|
|
|
local CPU = require 'CPU'
|
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.Header(
|
|
|
|
Geometry.LEFT_X,
|
|
|
|
MODULE_Y,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
'PROCESSOR'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 23:06:30 -04:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- cores (loads and temps)
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
local cpu_loads = CPU.init_cpu_loads()
|
|
|
|
local ncpus = CPU.get_cpu_number()
|
|
|
|
local ncores = CPU.get_core_number()
|
|
|
|
local nthreads = ncpus / ncores
|
|
|
|
local hwp_paths = CPU.get_hwp_paths()
|
|
|
|
local coretemp_paths = CPU.get_coretemp_paths()
|
2021-07-17 23:06:30 -04:00
|
|
|
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 {
|
|
|
|
loads = Common.compound_dial(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
DIAL_OUTER_RADIUS,
|
|
|
|
DIAL_INNER_RADIUS,
|
|
|
|
DIAL_THICKNESS,
|
|
|
|
0.8,
|
|
|
|
nthreads
|
|
|
|
),
|
|
|
|
coretemp = Common.initTextRing(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
DIAL_INNER_RADIUS - 2,
|
|
|
|
'%s°C',
|
|
|
|
90
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
for c = 1, ncores do
|
2021-07-17 23:06:30 -04:00
|
|
|
local dial_x = Geometry.LEFT_X + DIAL_OUTER_RADIUS +
|
|
|
|
(Geometry.SECTION_WIDTH - 2 * DIAL_OUTER_RADIUS) * (c - 1) / 3
|
|
|
|
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 16:43:00 -04:00
|
|
|
|
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.initTextRows(
|
|
|
|
Geometry.LEFT_X,
|
|
|
|
HWP_Y,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
TEXT_SPACING,
|
|
|
|
{'HWP Preference', 'Ave Freq'}
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- frequency
|
|
|
|
|
|
|
|
local SEP_Y = HWP_Y + TEXT_SPACING + SEPARATOR_SPACING
|
|
|
|
|
|
|
|
local separator = Common.initSeparator(
|
|
|
|
Geometry.LEFT_X,
|
|
|
|
SEP_Y,
|
|
|
|
Geometry.SECTION_WIDTH
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- total load plot
|
|
|
|
|
|
|
|
local LOAD_Y = SEP_Y + SEPARATOR_SPACING
|
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local total_load = Common.initPercentPlot(
|
|
|
|
Geometry.LEFT_X,
|
2021-07-17 23:06:30 -04:00
|
|
|
LOAD_Y,
|
2021-07-17 16:43:00 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-17 23:06:30 -04:00
|
|
|
PLOT_HEIGHT,
|
|
|
|
PLOT_SECTION_BREAK,
|
2021-07-17 16:43:00 -04:00
|
|
|
"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
|
|
|
|
local TABLE_CONKY = {}
|
|
|
|
for r = 1, NUM_ROWS do
|
|
|
|
TABLE_CONKY[r] = {
|
|
|
|
pid = '${top pid '..r..'}',
|
|
|
|
cpu = '${top cpu '..r..'}'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local tbl = Common.initTable(
|
|
|
|
Geometry.LEFT_X,
|
|
|
|
PLOT_Y + PLOT_HEIGHT + TABLE_SECTION_BREAK,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
TABLE_HEIGHT,
|
|
|
|
NUM_ROWS,
|
|
|
|
{'Name', 'PID', 'CPU (%)'}
|
|
|
|
)
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- main functions
|
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local update = function(cr, trigger)
|
|
|
|
local conky = Util.conky
|
|
|
|
local load_sum = 0
|
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
cpu_loads = CPU.read_cpu_loads(cpu_loads)
|
|
|
|
for _, load_data in pairs(cpu_loads) do
|
|
|
|
local cur = load_data.percent_active
|
|
|
|
load_sum = load_sum + cur
|
2021-07-17 22:45:30 -04:00
|
|
|
CompoundDial.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-07-17 21:22:17 -04:00
|
|
|
local temp = __math_floor(0.001 * Util.read_file(path, nil, '*n'))
|
2021-07-17 22:45:30 -04:00
|
|
|
Common.text_ring_set(cores[conky_core_id].coretemp, cr, temp)
|
2021-07-13 23:50:50 -04:00
|
|
|
end
|
2018-01-05 23:36:50 -05:00
|
|
|
|
2021-07-17 16:43:00 -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
|
|
|
|
if trigger == 0 then
|
2021-07-17 21:22:17 -04:00
|
|
|
Common.text_rows_set(cpu_status, cr, 1, CPU.read_hwp(hwp_paths))
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
2021-07-17 21:22:17 -04:00
|
|
|
Common.text_rows_set(cpu_status, cr, 2, CPU.read_freq())
|
2021-07-17 16:43:00 -04:00
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
Common.percent_plot_set(total_load, cr, load_sum / ncpus * 100)
|
2021-07-17 16:43:00 -04:00
|
|
|
|
|
|
|
for r = 1, NUM_ROWS do
|
|
|
|
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces
|
|
|
|
if pid ~= '' then
|
2021-07-17 23:06:30 -04:00
|
|
|
Table.set(tbl, cr, 1, r, Util.read_file('/proc/'..pid..'/comm', '(%C+)'))
|
2021-07-17 16:43:00 -04:00
|
|
|
Table.set(tbl, cr, 2, r, pid)
|
2021-07-17 23:06:30 -04:00
|
|
|
Table.set(tbl, cr, 3, r, conky(TABLE_CONKY[r].cpu))
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
2019-09-01 15:34:10 -04:00
|
|
|
end
|
2018-08-05 11:35:00 -04:00
|
|
|
end
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local draw_static = function(cr)
|
|
|
|
Common.drawHeader(cr, header)
|
2018-08-05 11:35:00 -04:00
|
|
|
|
2021-07-17 23:06:30 -04:00
|
|
|
for i = 1, #cores do
|
|
|
|
Common.text_ring_draw_static(cores[i].coretemp, cr)
|
|
|
|
CompoundDial.draw_static(cores[i].loads, cr)
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
2018-08-05 11:56:11 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.text_rows_draw_static(cpu_status, cr)
|
|
|
|
Line.draw(separator, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Common.percent_plot_draw_static(total_load, cr)
|
2018-01-05 23:36:50 -05:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
Table.draw_static(tbl, cr)
|
2018-08-05 11:08:37 -04:00
|
|
|
end
|
2018-01-05 23:36:50 -05:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
local draw_dynamic = function(cr, trigger)
|
|
|
|
update(cr, trigger)
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2021-07-17 23:06:30 -04:00
|
|
|
for i = 1, #cores do
|
|
|
|
CompoundDial.draw_dynamic(cores[i].loads, cr)
|
|
|
|
Common.text_ring_draw_dynamic(cores[i].coretemp, cr)
|
2021-07-17 16:43:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Common.text_rows_draw_dynamic(cpu_status, cr)
|
|
|
|
Common.percent_plot_draw_dynamic(total_load, cr)
|
|
|
|
|
|
|
|
Table.draw_dynamic(tbl, cr)
|
|
|
|
end
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 00:17:22 -04:00
|
|
|
return {static = draw_static, dynamic = draw_dynamic}
|
|
|
|
end
|