REF get rid of global vars passed to modules

This commit is contained in:
Nathan Dwarshuis 2021-07-17 16:43:00 -04:00
parent 5875eeff98
commit 36c23df114
8 changed files with 397 additions and 386 deletions

View File

@ -137,10 +137,10 @@ M.percent_label_style = Startup.label_style(
function(z) return Util.round_to_string(z * 100)..'%' end function(z) return Util.round_to_string(z * 100)..'%' end
) )
M.initThemedLabelPlot = function(x, y, w, h, label_style) M.initThemedLabelPlot = function(x, y, w, h, label_style, update_freq)
return Startup.LabelPlot( return Startup.LabelPlot(
Startup.make_box(x, y, w, h), Startup.make_box(x, y, w, h),
1 / _G_INIT_DATA_.UPDATE_INTERVAL, update_freq,
M.default_plot_style, M.default_plot_style,
label_style label_style
) )
@ -149,7 +149,7 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- percent plot (label plot with percent signs and some indicator data above it) -- percent plot (label plot with percent signs and some indicator data above it)
M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format) M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, update_freq, format)
return { return {
label = _left_text(Startup.make_point(x, y), label), label = _left_text(Startup.make_point(x, y), label),
value = Startup.formattedThresholdText( value = Startup.formattedThresholdText(
@ -164,13 +164,14 @@ M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format)
y + spacing, y + spacing,
w, w,
h, h,
M.percent_label_style M.percent_label_style,
update_freq
), ),
} }
end end
M.initPercentPlot = function(x, y, w, h, spacing, label) M.initPercentPlot = function(x, y, w, h, spacing, label, update_freq)
return M.initPercentPlot_formatted(x, y, w, h, spacing, label, '%s%%') return M.initPercentPlot_formatted(x, y, w, h, spacing, label, update_freq, '%s%%')
end end
M.percent_plot_draw_static = function(pp, cr) M.percent_plot_draw_static = function(pp, cr)
@ -203,10 +204,10 @@ M.base_2_scale_data = function(m)
return Startup.scale_data(2, m, 0.9) return Startup.scale_data(2, m, 0.9)
end end
M.initThemedScalePlot = function(x, y, w, h, f, min_domain) M.initThemedScalePlot = function(x, y, w, h, f, min_domain, update_freq)
return Startup.ScalePlot( return Startup.ScalePlot(
Startup.make_box(x, y, w, h), Startup.make_box(x, y, w, h),
1 / _G_INIT_DATA_.UPDATE_INTERVAL, update_freq,
M.default_plot_style, M.default_plot_style,
Startup.label_style( Startup.label_style(
Theme.INACTIVE_TEXT_FG, Theme.INACTIVE_TEXT_FG,
@ -221,7 +222,7 @@ end
-- scaled plot (with textual data above it) -- scaled plot (with textual data above it)
M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing, M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
label, min_domain) label, min_domain, update_freq)
return { return {
label = _left_text(Startup.make_point(x, y), label), label = _left_text(Startup.make_point(x, y), label),
value = Startup.formatted_text( value = Startup.formatted_text(
@ -230,7 +231,7 @@ M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
M.right_text_style, M.right_text_style,
format_fun format_fun
), ),
plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain), plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq),
} }
end end

View File

@ -79,39 +79,13 @@ local separator3 = Common.initSeparator(
local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_ local _GPU_UTIL_Y_ = _SEP_Y_3_ + _SEPARATOR_SPACING_
local gpu_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_GPU_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'GPU Utilization',
na_percent_format
)
local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local _MEM_UTIL_Y_ = _GPU_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local mem_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_MEM_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'Memory Utilization',
na_percent_format
)
local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2 local _VID_UTIL_Y_ = _MEM_UTIL_Y_ + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2
local vid_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_VID_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'Video Utilization',
na_percent_format
)
--[[ --[[
vars to process the nv settings glob vars to process the nv settings glob
@ -136,87 +110,120 @@ local NV_REGEX = '(%d+)\n'..
'(%d+),(%d+)\n'.. '(%d+),(%d+)\n'..
'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n' 'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n'
local nvidia_off = function(cr)
Common.text_row_crit_set(internal_temp, cr, -1)
Common.text_rows_set(clock_speed, cr, 1, NA)
Common.text_rows_set(clock_speed, cr, 2, NA)
Common.percent_plot_set(gpu_util, cr, nil)
Common.percent_plot_set(vid_util, cr, nil)
Common.percent_plot_set(mem_util, cr, nil)
end
local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control' local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control'
local update = function(cr) -- _MODULE_Y_ = nil
if Util.read_file(gpu_bus_ctrl, nil, '*l') == 'on' then -- _SEPARATOR_SPACING_ = nil
local nvidia_settings_glob = Util.execute_cmd(NV_QUERY) -- _TEXT_SPACING_ = nil
if nvidia_settings_glob == '' then -- _PLOT_SEC_BREAK_ = nil
Text.set(status.value, cr, 'Error') -- _PLOT_HEIGHT_ = nil
nvidia_off(cr) -- _SEP_Y_1_ = nil
else -- _SEP_Y_2_ = nil
Common.text_row_set(status, cr, 'On') -- _SEP_Y_3_ = nil
-- _INTERNAL_TEMP_Y_ = nil
-- _CLOCK_SPEED_Y_ = nil
-- _GPU_UTIL_Y_ = nil
-- _MEM_UTIL_Y_ = nil
-- _VID_UTIL_Y_ = nil
local used_memory, total_memory, temp_reading, gpu_frequency, return function(update_freq)
memory_frequency, gpu_utilization, vid_utilization
= __string_match(nvidia_settings_glob, NV_REGEX)
Common.text_row_crit_set(internal_temp, cr, temp_reading) local gpu_util = Common.initPercentPlot_formatted(
Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz') Geometry.LEFT_X,
Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz') _GPU_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'GPU Utilization',
update_freq,
na_percent_format
)
Common.percent_plot_set(gpu_util, cr, gpu_utilization) local mem_util = Common.initPercentPlot_formatted(
Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100) Geometry.LEFT_X,
Common.percent_plot_set(vid_util, cr, vid_utilization) _MEM_UTIL_Y_,
end Geometry.SECTION_WIDTH,
else _PLOT_HEIGHT_,
Text.set(status.value, cr, 'Off') _PLOT_SEC_BREAK_,
nvidia_off(cr) 'Memory Utilization',
update_freq,
na_percent_format
)
local vid_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_VID_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'Video Utilization',
update_freq,
na_percent_format
)
local nvidia_off = function(cr)
Common.text_row_crit_set(internal_temp, cr, -1)
Common.text_rows_set(clock_speed, cr, 1, NA)
Common.text_rows_set(clock_speed, cr, 2, NA)
Common.percent_plot_set(gpu_util, cr, nil)
Common.percent_plot_set(vid_util, cr, nil)
Common.percent_plot_set(mem_util, cr, nil)
end end
end
_MODULE_Y_ = nil local update = function(cr)
_SEPARATOR_SPACING_ = nil if Util.read_file(gpu_bus_ctrl, nil, '*l') == 'on' then
_TEXT_SPACING_ = nil local nvidia_settings_glob = Util.execute_cmd(NV_QUERY)
_PLOT_SEC_BREAK_ = nil if nvidia_settings_glob == '' then
_PLOT_HEIGHT_ = nil Text.set(status.value, cr, 'Error')
_SEP_Y_1_ = nil nvidia_off(cr)
_SEP_Y_2_ = nil else
_SEP_Y_3_ = nil Common.text_row_set(status, cr, 'On')
_INTERNAL_TEMP_Y_ = nil
_CLOCK_SPEED_Y_ = nil
_GPU_UTIL_Y_ = nil
_MEM_UTIL_Y_ = nil
_VID_UTIL_Y_ = nil
local draw_static = function(cr) local used_memory, total_memory, temp_reading, gpu_frequency,
Common.drawHeader(cr, header) memory_frequency, gpu_utilization, vid_utilization
= __string_match(nvidia_settings_glob, NV_REGEX)
Common.text_row_draw_static(status, cr) Common.text_row_crit_set(internal_temp, cr, temp_reading)
Line.draw(separator1, cr) Common.text_rows_set(clock_speed, cr, 1, gpu_frequency..' Mhz')
Common.text_rows_set(clock_speed, cr, 2, memory_frequency..' Mhz')
Common.text_row_crit_draw_static(internal_temp, cr) Common.percent_plot_set(gpu_util, cr, gpu_utilization)
Line.draw(separator2, cr) Common.percent_plot_set(mem_util, cr, used_memory / total_memory * 100)
Common.percent_plot_set(vid_util, cr, vid_utilization)
end
else
Text.set(status.value, cr, 'Off')
nvidia_off(cr)
end
end
Common.text_rows_draw_static(clock_speed, cr) local draw_static = function(cr)
Line.draw(separator3, cr) Common.drawHeader(cr, header)
Common.percent_plot_draw_static(gpu_util, cr) Common.text_row_draw_static(status, cr)
Common.percent_plot_draw_static(mem_util, cr) Line.draw(separator1, cr)
Common.percent_plot_draw_static(vid_util, cr)
end
local draw_dynamic = function(cr) Common.text_row_crit_draw_static(internal_temp, cr)
update(cr) Line.draw(separator2, cr)
Common.text_row_draw_dynamic(status, cr) Common.text_rows_draw_static(clock_speed, cr)
Common.text_row_crit_draw_dynamic(internal_temp, cr) Line.draw(separator3, cr)
Common.text_rows_draw_dynamic(clock_speed, cr)
Common.percent_plot_draw_dynamic(gpu_util, cr) Common.percent_plot_draw_static(gpu_util, cr)
Common.percent_plot_draw_dynamic(mem_util, cr) Common.percent_plot_draw_static(mem_util, cr)
Common.percent_plot_draw_dynamic(vid_util, cr) Common.percent_plot_draw_static(vid_util, cr)
end end
local draw_dynamic = function(cr)
update(cr)
Common.text_row_draw_dynamic(status, cr)
Common.text_row_crit_draw_dynamic(internal_temp, cr)
Common.text_rows_draw_dynamic(clock_speed, cr)
Common.percent_plot_draw_dynamic(gpu_util, cr)
Common.percent_plot_draw_dynamic(mem_util, cr)
Common.percent_plot_draw_dynamic(vid_util, cr)
end
return function()
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic}
end end

View File

@ -96,13 +96,6 @@ local cache = Common.initTextRows_color(
local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2 local _PLOT_Y_ = _PLOT_SECTION_BREAK_ + header.bottom_y + DIAL_RADIUS * 2
local plot = Common.initThemedLabelPlot(
Geometry.RIGHT_X,
_PLOT_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
Common.percent_label_style
)
local tbl = Common.initTable( local tbl = Common.initTable(
Geometry.RIGHT_X, Geometry.RIGHT_X,
@ -113,91 +106,102 @@ local tbl = Common.initTable(
{'Name', 'PID', 'Mem (%)'} {'Name', 'PID', 'Mem (%)'}
) )
local update = function(cr) -- _MODULE_Y_ = nil
local conky = Util.conky -- _DIAL_THICKNESS_ = nil
-- see source for the 'free' command (sysinfo.c) for formulas -- _DIAL_SPACING_ = nil
-- _TEXT_Y_OFFSET_ = nil
-- _TEXT_LEFT_X_OFFSET_ = nil
-- _TEXT_SPACING_ = nil
-- _PLOT_SECTION_BREAK_ = nil
-- _PLOT_HEIGHT_ = nil
-- _TABLE_SECTION_BREAK_ = nil
-- _TABLE_HEIGHT_ = nil
-- _LINE_1_Y_ = nil
-- _TEXT_LEFT_X_ = nil
-- _RIGHT_X_ = nil
-- _PLOT_Y_ = nil
local memfree_kb, buffers_kb, cached_kb, swap_total_kb, swap_free_kb,
slab_reclaimable_kb = __string_match(Util.read_file('/proc/meminfo'), MEMINFO_REGEX)
local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB
Dial.set(dial, used_percent)
Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100))
local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1
__cairo_path_destroy(cache_arc.path)
cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta)
Common.text_row_crit_set(swap, cr,
Util.precision_round_to_string(
(swap_total_kb - swap_free_kb)
/ swap_total_kb * 100))
Common.text_rows_set(cache, cr, 1, Util.precision_round_to_string(
cached_kb / MEM_TOTAL_KB * 100))
Common.text_rows_set(cache, cr, 2, Util.precision_round_to_string(
buffers_kb / MEM_TOTAL_KB * 100))
Common.text_rows_set(cache, cr, 3, Util.precision_round_to_string(
slab_reclaimable_kb / MEM_TOTAL_KB * 100))
LabelPlot.update(plot, used_percent)
for r = 1, NUM_ROWS do
local comm = conky(TABLE_CONKY[r].comm, '(%S+)') -- may have trailing space
local pid = conky(TABLE_CONKY[r].pid)
local mem = conky(TABLE_CONKY[r].mem)
Table.set(tbl, cr, 1, r, comm)
Table.set(tbl, cr, 2, r, pid)
Table.set(tbl, cr, 3, r, mem)
end
end
_MODULE_Y_ = nil
_DIAL_THICKNESS_ = nil
_DIAL_SPACING_ = nil
_TEXT_Y_OFFSET_ = nil
_TEXT_LEFT_X_OFFSET_ = nil
_TEXT_SPACING_ = nil
_PLOT_SECTION_BREAK_ = nil
_PLOT_HEIGHT_ = nil
_TABLE_SECTION_BREAK_ = nil
_TABLE_HEIGHT_ = nil
_LINE_1_Y_ = nil
_TEXT_LEFT_X_ = nil
_RIGHT_X_ = nil
_PLOT_Y_ = nil
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_ring_draw_static(text_ring, cr)
Dial.draw_static(dial, cr)
Common.text_row_crit_draw_static(swap, cr)
Common.text_rows_draw_static(cache, cr)
LabelPlot.draw_static(plot, cr)
Table.draw_static(tbl, cr)
end
local draw_dynamic = function(cr)
update(cr)
Dial.draw_dynamic(dial, cr)
Arc.draw(cache_arc, cr)
Common.text_ring_draw_dynamic(text_ring, cr)
Common.text_row_crit_draw_dynamic(swap, cr)
Common.text_rows_draw_dynamic(cache, cr)
LabelPlot.draw_dynamic(plot, cr)
Table.draw_dynamic(tbl, cr)
end
return function(update_freq) return function(update_freq)
local plot = Common.initThemedLabelPlot(
Geometry.RIGHT_X,
_PLOT_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
Common.percent_label_style,
update_freq
)
local update = function(cr)
local conky = Util.conky
-- see source for the 'free' command (sysinfo.c) for formulas
local memfree_kb, buffers_kb, cached_kb, swap_total_kb, swap_free_kb,
slab_reclaimable_kb = __string_match(Util.read_file('/proc/meminfo'), MEMINFO_REGEX)
local used_percent = (MEM_TOTAL_KB - memfree_kb - cached_kb - buffers_kb - slab_reclaimable_kb) / MEM_TOTAL_KB
Dial.set(dial, used_percent)
Common.text_ring_set(text_ring, cr, Util.round_to_string(used_percent * 100))
local cache_theta = (DIAL_THETA_0 - DIAL_THETA_1) / MEM_TOTAL_KB * memfree_kb + DIAL_THETA_1
__cairo_path_destroy(cache_arc.path)
cache_arc.path = Arc.create_path(cr, DIAL_X, DIAL_Y, DIAL_RADIUS, dial.dial_angle, cache_theta)
Common.text_row_crit_set(swap, cr,
Util.precision_round_to_string(
(swap_total_kb - swap_free_kb)
/ swap_total_kb * 100))
Common.text_rows_set(cache, cr, 1, Util.precision_round_to_string(
cached_kb / MEM_TOTAL_KB * 100))
Common.text_rows_set(cache, cr, 2, Util.precision_round_to_string(
buffers_kb / MEM_TOTAL_KB * 100))
Common.text_rows_set(cache, cr, 3, Util.precision_round_to_string(
slab_reclaimable_kb / MEM_TOTAL_KB * 100))
LabelPlot.update(plot, used_percent)
for r = 1, NUM_ROWS do
local comm = conky(TABLE_CONKY[r].comm, '(%S+)') -- may have trailing space
local pid = conky(TABLE_CONKY[r].pid)
local mem = conky(TABLE_CONKY[r].mem)
Table.set(tbl, cr, 1, r, comm)
Table.set(tbl, cr, 2, r, pid)
Table.set(tbl, cr, 3, r, mem)
end
end
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_ring_draw_static(text_ring, cr)
Dial.draw_static(dial, cr)
Common.text_row_crit_draw_static(swap, cr)
Common.text_rows_draw_static(cache, cr)
LabelPlot.draw_static(plot, cr)
Table.draw_static(tbl, cr)
end
local draw_dynamic = function(cr)
update(cr)
Dial.draw_dynamic(dial, cr)
Arc.draw(cache_arc, cr)
Common.text_ring_draw_dynamic(text_ring, cr)
Common.text_row_crit_draw_dynamic(swap, cr)
Common.text_rows_draw_dynamic(cache, cr)
LabelPlot.draw_dynamic(plot, cr)
Table.draw_dynamic(tbl, cr)
end
return {dynamic = draw_dynamic, static = draw_static} return {dynamic = draw_dynamic, static = draw_static}
end end

View File

@ -18,14 +18,26 @@ local value_format_function = function(bits)
return Util.precision_round_to_string(value, 3)..' '..unit..'b/s' return Util.precision_round_to_string(value, 3)..' '..unit..'b/s'
end end
local header = Common.Header(
Geometry.CENTER_RIGHT_X,
Geometry.TOP_Y,
Geometry.SECTION_WIDTH,
'NETWORK'
)
local dnload = Common.initLabeledScalePlot(
local interface_counters_tbl = {}
local get_bits = function(path)
return Util.read_file(path, nil, '*n') * 8
end
-- _PLOT_SEC_BREAK_ = nil
-- _PLOT_HEIGHT_ = nil
return function(update_freq)
local header = Common.Header(
Geometry.CENTER_RIGHT_X,
Geometry.TOP_Y,
Geometry.SECTION_WIDTH,
'NETWORK'
)
local dnload = Common.initLabeledScalePlot(
Geometry.CENTER_RIGHT_X, Geometry.CENTER_RIGHT_X,
header.bottom_y, header.bottom_y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -34,10 +46,11 @@ local dnload = Common.initLabeledScalePlot(
network_label_function, network_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'Download', 'Download',
2 2,
) update_freq
)
local upload = Common.initLabeledScalePlot( local upload = Common.initLabeledScalePlot(
Geometry.CENTER_RIGHT_X, Geometry.CENTER_RIGHT_X,
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -46,25 +59,10 @@ local upload = Common.initLabeledScalePlot(
network_label_function, network_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'Upload', 'Upload',
2 2,
) update_freq
)
local interface_counters_tbl = {}
local get_bits = function(path)
return Util.read_file(path, nil, '*n') * 8
end
_PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(dnload, cr)
Common.annotated_scale_plot_draw_static(upload, cr)
end
return function(update_freq)
local _update = function(cr) local _update = function(cr)
local dspeed, uspeed = 0, 0 local dspeed, uspeed = 0, 0
@ -108,6 +106,12 @@ return function(update_freq)
Common.annotated_scale_plot_set(upload, cr, uspeed) Common.annotated_scale_plot_set(upload, cr, uspeed)
end end
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(dnload, cr)
Common.annotated_scale_plot_draw_static(upload, cr)
end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
_update(cr) _update(cr)
Common.annotated_scale_plot_draw_dynamic(dnload, cr) Common.annotated_scale_plot_draw_dynamic(dnload, cr)

View File

@ -36,7 +36,24 @@ local header = Common.Header(
'POWER' 'POWER'
) )
local pkg0 = Common.initLabeledScalePlot( local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
-- _MODULE_Y_ = nil
-- _TEXT_SPACING_ = nil
-- _PLOT_SEC_BREAK_ = nil
-- _PLOT_HEIGHT_ = nil
-- _CORE_Y_ = nil
return function(update_freq)
local pkg0 = Common.initLabeledScalePlot(
Geometry.RIGHT_X, Geometry.RIGHT_X,
header.bottom_y, header.bottom_y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -45,12 +62,11 @@ local pkg0 = Common.initLabeledScalePlot(
power_label_function, power_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'PKG0', 'PKG0',
0 0,
) update_freq
)
local _CORE_Y_ = header.bottom_y + _TEXT_SPACING_ + _PLOT_SEC_BREAK_ + _PLOT_HEIGHT_ local dram = Common.initLabeledScalePlot(
local dram = Common.initLabeledScalePlot(
Geometry.RIGHT_X, Geometry.RIGHT_X,
_CORE_Y_, _CORE_Y_,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -59,11 +75,11 @@ local dram = Common.initLabeledScalePlot(
power_label_function, power_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'DRAM', 'DRAM',
0 0,
) update_freq
dram.value.append_end = ' W' )
local battery_draw = Common.initLabeledScalePlot( local battery_draw = Common.initLabeledScalePlot(
Geometry.RIGHT_X, Geometry.RIGHT_X,
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_, _CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -72,30 +88,9 @@ local battery_draw = Common.initLabeledScalePlot(
power_label_function, power_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'Battery Draw', 'Battery Draw',
0 0,
) update_freq
)
local PKG0_PATH = '/sys/class/powercap/intel-rapl:0/energy_uj'
local DRAM_PATH = '/sys/class/powercap/intel-rapl:0:2/energy_uj'
local prev_pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
local prev_dram_uj_cnt = Util.read_file(DRAM_PATH, nil, '*n')
_MODULE_Y_ = nil
_TEXT_SPACING_ = nil
_PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil
_CORE_Y_ = nil
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(pkg0, cr)
Common.annotated_scale_plot_draw_static(dram, cr)
Common.annotated_scale_plot_draw_static(battery_draw, cr)
end
return function(update_freq)
local _update = function(cr, is_using_ac) local _update = function(cr, is_using_ac)
local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n') local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
@ -122,6 +117,13 @@ return function(update_freq)
end end
end end
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(pkg0, cr)
Common.annotated_scale_plot_draw_static(dram, cr)
Common.annotated_scale_plot_draw_static(battery_draw, cr)
end
local draw_dynamic = function(cr, is_using_ac) local draw_dynamic = function(cr, is_using_ac)
_update(cr, is_using_ac) _update(cr, is_using_ac)
Common.annotated_scale_plot_draw_dynamic(pkg0, cr) Common.annotated_scale_plot_draw_dynamic(pkg0, cr)

View File

@ -113,14 +113,6 @@ local _LOAD_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_ local _PLOT_Y_ = _LOAD_Y_ + _PLOT_SECTION_BREAK_
local total_load = Common.initPercentPlot(
Geometry.LEFT_X,
_LOAD_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SECTION_BREAK_,
"Total Load"
)
local tbl = Common.initTable( local tbl = Common.initTable(
Geometry.LEFT_X, Geometry.LEFT_X,
@ -197,107 +189,120 @@ local _read_hwp = function()
end end
end end
local update = function(cr, trigger)
local conky = Util.conky
local load_sum = 0
-- TODO bundle all the crap down below into this function and make it return -- _MODULE_Y_ = nil
-- something useful rather than totally use a side effect (it will be mildly -- _DIAL_INNER_RADIUS_ = nil
-- slower) -- _DIAL_OUTER_RADIUS_ = nil
-- this entire loop is about 10% total execution time -- _DIAL_THICKNESS_ = nil
_read_cpu() -- _TEXT_Y_OFFSET_ = nil
for c = 1, NUM_PHYSICAL_CORES do -- _SEPARATOR_SPACING_ = nil
local core = cores[c] -- _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
for t = 1, NUM_THREADS_PER_CORE do
-- TODO these might not match the actual core numbers (if I care) return function(update_freq)
local cl = cpu_loads[(c - 1) * NUM_THREADS_PER_CORE + t]
-- this is necessary to prevent 1/0 errors local total_load = Common.initPercentPlot(
if cl.total > cl.total_prev then Geometry.LEFT_X,
local p = (cl.active - cl.active_prev) / (cl.total - cl.total_prev) _LOAD_Y_,
CompoundDial.set(core.dials, t, p) Geometry.SECTION_WIDTH,
load_sum = load_sum + p _PLOT_HEIGHT_,
_PLOT_SECTION_BREAK_,
"Total Load",
update_freq
)
local update = function(cr, trigger)
local conky = Util.conky
local load_sum = 0
-- TODO bundle all the crap down below into this function and make it return
-- something useful rather than totally use a side effect (it will be mildly
-- slower)
-- this entire loop is about 10% total execution time
_read_cpu()
for c = 1, NUM_PHYSICAL_CORES do
local core = cores[c]
for t = 1, NUM_THREADS_PER_CORE do
-- TODO these might not match the actual core numbers (if I care)
local cl = cpu_loads[(c - 1) * NUM_THREADS_PER_CORE + t]
-- this is necessary to prevent 1/0 errors
if cl.total > cl.total_prev then
local p = (cl.active - cl.active_prev) / (cl.total - cl.total_prev)
CompoundDial.set(core.dials, t, p)
load_sum = load_sum + p
end
end
Common.text_ring_set(
core.text_ring,
cr,
__math_floor(0.001 * Util.read_file(core.coretemp_path, nil, '*n'))
)
end
-- 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, cr, 1, _read_hwp())
end
Common.text_rows_set(cpu_status, cr, 2, _read_freq())
Common.percent_plot_set(total_load, cr, load_sum / NCPU * 100)
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 end
end end
Common.text_ring_set(
core.text_ring,
cr,
__math_floor(0.001 * Util.read_file(core.coretemp_path, nil, '*n'))
)
end end
-- For some reason this call is slow (querying anything with pstate in local draw_static = function(cr)
-- general seems slow), but I also don't need to see an update every cycle, Common.drawHeader(cr, header)
-- hence the trigger
if trigger == 0 then
Common.text_rows_set(cpu_status, cr, 1, _read_hwp())
end
Common.text_rows_set(cpu_status, cr, 2, _read_freq())
Common.percent_plot_set(total_load, cr, load_sum / NCPU * 100) for c = 1, NUM_PHYSICAL_CORES do
local this_core = cores[c]
for r = 1, NUM_ROWS do Common.text_ring_draw_static(this_core.text_ring, cr)
local pid = conky(TABLE_CONKY[r].pid, '(%d+)') -- may have leading spaces CompoundDial.draw_static(this_core.dials, cr)
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 end
end
end
_MODULE_Y_ = nil Common.text_rows_draw_static(cpu_status, cr)
_DIAL_INNER_RADIUS_ = nil Line.draw(separator, cr)
_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
local draw_static = function(cr) Common.percent_plot_draw_static(total_load, cr)
Common.drawHeader(cr, header)
for c = 1, NUM_PHYSICAL_CORES do Table.draw_static(tbl, cr)
local this_core = cores[c]
Common.text_ring_draw_static(this_core.text_ring, cr)
CompoundDial.draw_static(this_core.dials, cr)
end end
Common.text_rows_draw_static(cpu_status, cr) local draw_dynamic = function(cr, trigger)
Line.draw(separator, cr) update(cr, trigger)
Common.percent_plot_draw_static(total_load, cr) for c = 1, NUM_PHYSICAL_CORES do
local this_core = cores[c]
CompoundDial.draw_dynamic(this_core.dials, cr)
Common.text_ring_draw_dynamic(this_core.text_ring, cr)
end
Table.draw_static(tbl, cr) Common.text_rows_draw_dynamic(cpu_status, cr)
end Common.percent_plot_draw_dynamic(total_load, cr)
local draw_dynamic = function(cr, trigger) Table.draw_dynamic(tbl, cr)
update(cr, trigger)
for c = 1, NUM_PHYSICAL_CORES do
local this_core = cores[c]
CompoundDial.draw_dynamic(this_core.dials, cr)
Common.text_ring_draw_dynamic(this_core.text_ring, cr)
end end
Common.text_rows_draw_dynamic(cpu_status, cr)
Common.percent_plot_draw_dynamic(total_load, cr)
Table.draw_dynamic(tbl, cr)
end
return function()
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic}
end end

View File

@ -30,14 +30,15 @@ local format_value_function = function(bps)
return Util.precision_round_to_string(value, 3)..' '..unit..'B/s' return Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
end end
local header = Common.Header( return function(update_freq)
Geometry.CENTER_LEFT_X, local header = Common.Header(
Geometry.TOP_Y, Geometry.CENTER_LEFT_X,
Geometry.SECTION_WIDTH, Geometry.TOP_Y,
'INPUT / OUTPUT' Geometry.SECTION_WIDTH,
) 'INPUT / OUTPUT'
)
local reads = Common.initLabeledScalePlot( local reads = Common.initLabeledScalePlot(
Geometry.CENTER_LEFT_X, Geometry.CENTER_LEFT_X,
header.bottom_y, header.bottom_y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -46,11 +47,11 @@ local reads = Common.initLabeledScalePlot(
io_label_function, io_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'Reads', 'Reads',
2 2,
update_freq
)
) local writes = Common.initLabeledScalePlot(
local writes = Common.initLabeledScalePlot(
Geometry.CENTER_LEFT_X, Geometry.CENTER_LEFT_X,
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2, header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
@ -59,23 +60,13 @@ local writes = Common.initLabeledScalePlot(
io_label_function, io_label_function,
_PLOT_SEC_BREAK_, _PLOT_SEC_BREAK_,
'Writes', 'Writes',
2 2,
) update_freq
)
_PLOT_SEC_BREAK_ = nil reads.byte_cnt = 0
_PLOT_HEIGHT_ = nil writes.byte_cnt = 0
reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file()
reads.byte_cnt = 0
writes.byte_cnt = 0
reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file()
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(reads, cr)
Common.annotated_scale_plot_draw_static(writes, cr)
end
return function(update_freq)
local update_stat = function(cr, stat, byte_cnt) local update_stat = function(cr, stat, byte_cnt)
local delta_bytes = byte_cnt - stat.prev_byte_cnt local delta_bytes = byte_cnt - stat.prev_byte_cnt
@ -95,6 +86,12 @@ return function(update_freq)
update_stat(cr, writes, write_byte_cnt) update_stat(cr, writes, write_byte_cnt)
end end
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.annotated_scale_plot_draw_static(reads, cr)
Common.annotated_scale_plot_draw_static(writes, cr)
end
local draw_dynamic = function(cr) local draw_dynamic = function(cr)
update(cr) update(cr)
Common.annotated_scale_plot_draw_dynamic(reads, cr) Common.annotated_scale_plot_draw_dynamic(reads, cr)

View File

@ -1,12 +1,3 @@
--
-- initialialize global geometric data
--
local UPDATE_FREQUENCY = 1 --Hz
_G_INIT_DATA_ = {
UPDATE_INTERVAL = 1 / UPDATE_FREQUENCY,
}
-- --
-- init cairo -- init cairo
-- --
@ -102,8 +93,8 @@ function conky_start(update_interval)
local pwr = Power(update_freq) local pwr = Power(update_freq)
local fs = FileSystem() local fs = FileSystem()
local sys = System() local sys = System()
local gfx = Graphics() local gfx = Graphics(update_freq)
local proc = Processor() local proc = Processor(update_freq)
local pcm = Pacman() local pcm = Pacman()
local cs_left = _make_static_surface( local cs_left = _make_static_surface(