2017-07-19 00:36:15 -04:00
|
|
|
local CompoundDial = require 'CompoundDial'
|
|
|
|
local Line = require 'Line'
|
|
|
|
local Table = require 'Table'
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
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
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
local NUM_ROWS = 5
|
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
|
2021-07-17 16:48:22 -04:00
|
|
|
TABLE_CONKY[r] = {
|
|
|
|
pid = '${top pid '..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
|
2021-07-11 12:58:51 -04:00
|
|
|
local _DIAL_THICKNESS_ = 5.5
|
2017-07-19 00:36:15 -04:00
|
|
|
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
|
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
local _create_core_ = function(x, y, nthreads)
|
|
|
|
return {
|
|
|
|
loads = Common.compound_dial(
|
2021-07-11 23:10:35 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
_DIAL_OUTER_RADIUS_,
|
|
|
|
_DIAL_INNER_RADIUS_,
|
|
|
|
_DIAL_THICKNESS_,
|
|
|
|
0.8,
|
2021-07-17 21:22:17 -04:00
|
|
|
nthreads
|
2021-07-08 22:57:35 -04:00
|
|
|
),
|
2021-07-17 21:22:17 -04:00
|
|
|
coretemp = Common.initTextRing(
|
2021-07-05 23:27:43 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
_DIAL_INNER_RADIUS_ - 2,
|
2021-07-10 19:07:45 -04:00
|
|
|
'%s°C',
|
2021-07-06 19:32:18 -04:00
|
|
|
90
|
2021-07-17 21:22:17 -04:00
|
|
|
)
|
2018-01-05 23:36:50 -05:00
|
|
|
}
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local header = Common.Header(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.LEFT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_MODULE_Y_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
'PROCESSOR'
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
|
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 _FREQ_Y_ = _HWP_Y_ + _TEXT_SPACING_
|
2017-10-23 02:40:12 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local cpu_status = Common.initTextRows(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.LEFT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_HWP_Y_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
_TEXT_SPACING_,
|
|
|
|
{'HWP Preference', 'Ave Freq'}
|
|
|
|
)
|
2017-10-23 02:40:12 -04:00
|
|
|
|
|
|
|
local _SEP_Y_ = _FREQ_Y_ + _SEPARATOR_SPACING_
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local separator = Common.initSeparator(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.LEFT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_SEP_Y_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
|
|
|
|
|
|
|
|
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
|
|
|
|
local tbl = Common.initTable(
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.LEFT_X,
|
2021-07-05 23:27:43 -04:00
|
|
|
_PLOT_Y_ + _PLOT_HEIGHT_ + _TABLE_SECTION_BREAK_,
|
2021-07-16 23:25:44 -04:00
|
|
|
Geometry.SECTION_WIDTH,
|
2021-07-05 23:27:43 -04:00
|
|
|
_TABLE_HEIGHT_,
|
|
|
|
NUM_ROWS,
|
|
|
|
{'Name', 'PID', 'CPU (%)'}
|
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-17 21:22:17 -04:00
|
|
|
-- local cpu_loads = {}
|
|
|
|
-- for i = 1, NCPU do
|
|
|
|
-- cpu_loads[i] = {active_prev = 0, active_total = 0}
|
|
|
|
-- end
|
2021-07-12 23:49:52 -04:00
|
|
|
|
2021-07-13 01:12:34 -04:00
|
|
|
|
2021-07-17 16:43:00 -04:00
|
|
|
-- _MODULE_Y_ = nil
|
|
|
|
-- _DIAL_INNER_RADIUS_ = nil
|
|
|
|
-- _DIAL_OUTER_RADIUS_ = nil
|
|
|
|
-- _DIAL_THICKNESS_ = nil
|
|
|
|
-- _TEXT_Y_OFFSET_ = nil
|
|
|
|
-- _SEPARATOR_SPACING_ = nil
|
|
|
|
-- _TEXT_SPACING_ = nil
|
|
|
|
-- _PLOT_SECTION_BREAK_ = nil
|
|
|
|
-- _PLOT_HEIGHT_ = nil
|
|
|
|
-- _TABLE_SECTION_BREAK_ = nil
|
|
|
|
-- _TABLE_HEIGHT_ = nil
|
|
|
|
-- _create_core_ = nil
|
|
|
|
-- _FREQ_Y_ = nil
|
|
|
|
-- _LOAD_Y_ = nil
|
|
|
|
-- _SEP_Y_ = nil
|
|
|
|
-- _HWP_Y_ = nil
|
|
|
|
-- _PLOT_Y_ = nil
|
|
|
|
|
|
|
|
return function(update_freq)
|
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()
|
|
|
|
|
|
|
|
-- prime the load matrix
|
|
|
|
CPU.read_cpu_loads(cpu_loads)
|
|
|
|
|
|
|
|
local cores = {}
|
|
|
|
|
|
|
|
for c = 1, ncores do
|
|
|
|
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, nthreads)
|
|
|
|
end
|
2021-07-17 16:43:00 -04:00
|
|
|
|
|
|
|
local total_load = Common.initPercentPlot(
|
|
|
|
Geometry.LEFT_X,
|
|
|
|
_LOAD_Y_,
|
|
|
|
Geometry.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
|
|
|
_PLOT_SECTION_BREAK_,
|
|
|
|
"Total Load",
|
|
|
|
update_freq
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
CompoundDial.set(cores[load_data.core_id].loads, load_data.thread_id, cur)
|
|
|
|
end
|
|
|
|
|
|
|
|
for core_id, path in pairs(coretemp_paths) do
|
|
|
|
local temp = __math_floor(0.001 * Util.read_file(path, nil, '*n'))
|
|
|
|
Common.text_ring_set(cores[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
|
|
|
|
local cpu = conky(TABLE_CONKY[r].cpu)
|
|
|
|
local comm = Util.read_file('/proc/'..pid..'/comm', '(%C+)')
|
|
|
|
Table.set(tbl, cr, 1, r, comm)
|
|
|
|
Table.set(tbl, cr, 2, r, pid)
|
|
|
|
Table.set(tbl, cr, 3, r, cpu)
|
|
|
|
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 21:22:17 -04:00
|
|
|
for _, this_core in pairs(cores) do
|
|
|
|
Common.text_ring_draw_static(this_core.coretemp, cr)
|
|
|
|
CompoundDial.draw_static(this_core.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 21:22:17 -04:00
|
|
|
for _, this_core in pairs(cores) do
|
|
|
|
CompoundDial.draw_dynamic(this_core.loads, cr)
|
|
|
|
Common.text_ring_draw_dynamic(this_core.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
|