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
)
M.initThemedLabelPlot = function(x, y, w, h, label_style)
M.initThemedLabelPlot = function(x, y, w, h, label_style, update_freq)
return Startup.LabelPlot(
Startup.make_box(x, y, w, h),
1 / _G_INIT_DATA_.UPDATE_INTERVAL,
update_freq,
M.default_plot_style,
label_style
)
@ -149,7 +149,7 @@ end
--------------------------------------------------------------------------------
-- 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 {
label = _left_text(Startup.make_point(x, y), label),
value = Startup.formattedThresholdText(
@ -164,13 +164,14 @@ M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, format)
y + spacing,
w,
h,
M.percent_label_style
M.percent_label_style,
update_freq
),
}
end
M.initPercentPlot = function(x, y, w, h, spacing, label)
return M.initPercentPlot_formatted(x, y, w, h, spacing, label, '%s%%')
M.initPercentPlot = function(x, y, w, h, spacing, label, update_freq)
return M.initPercentPlot_formatted(x, y, w, h, spacing, label, update_freq, '%s%%')
end
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)
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(
Startup.make_box(x, y, w, h),
1 / _G_INIT_DATA_.UPDATE_INTERVAL,
update_freq,
M.default_plot_style,
Startup.label_style(
Theme.INACTIVE_TEXT_FG,
@ -221,7 +222,7 @@ end
-- scaled plot (with textual data above it)
M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
label, min_domain)
label, min_domain, update_freq)
return {
label = _left_text(Startup.make_point(x, y), label),
value = Startup.formatted_text(
@ -230,7 +231,7 @@ M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
M.right_text_style,
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

View File

@ -79,39 +79,13 @@ local separator3 = Common.initSeparator(
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 = 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 = 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
@ -136,19 +110,67 @@ local NV_REGEX = '(%d+)\n'..
'(%d+),(%d+)\n'..
'graphics=(%d+), memory=%d+, video=(%d+), PCIe=%d+\n'
local nvidia_off = function(cr)
local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control'
-- _MODULE_Y_ = nil
-- _SEPARATOR_SPACING_ = nil
-- _TEXT_SPACING_ = nil
-- _PLOT_SEC_BREAK_ = nil
-- _PLOT_HEIGHT_ = nil
-- _SEP_Y_1_ = nil
-- _SEP_Y_2_ = nil
-- _SEP_Y_3_ = nil
-- _INTERNAL_TEMP_Y_ = nil
-- _CLOCK_SPEED_Y_ = nil
-- _GPU_UTIL_Y_ = nil
-- _MEM_UTIL_Y_ = nil
-- _VID_UTIL_Y_ = nil
return function(update_freq)
local gpu_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_GPU_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'GPU Utilization',
update_freq,
na_percent_format
)
local mem_util = Common.initPercentPlot_formatted(
Geometry.LEFT_X,
_MEM_UTIL_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SEC_BREAK_,
'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
local gpu_bus_ctrl = '/sys/bus/pci/devices/0000:01:00.0/power/control'
local update = function(cr)
local update = function(cr)
if Util.read_file(gpu_bus_ctrl, nil, '*l') == 'on' then
local nvidia_settings_glob = Util.execute_cmd(NV_QUERY)
if nvidia_settings_glob == '' then
@ -173,23 +195,9 @@ local update = function(cr)
Text.set(status.value, cr, 'Off')
nvidia_off(cr)
end
end
end
_MODULE_Y_ = nil
_SEPARATOR_SPACING_ = nil
_TEXT_SPACING_ = nil
_PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil
_SEP_Y_1_ = nil
_SEP_Y_2_ = nil
_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 draw_static = function(cr)
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_row_draw_static(status, cr)
@ -204,9 +212,9 @@ local draw_static = function(cr)
Common.percent_plot_draw_static(gpu_util, cr)
Common.percent_plot_draw_static(mem_util, cr)
Common.percent_plot_draw_static(vid_util, cr)
end
end
local draw_dynamic = function(cr)
local draw_dynamic = function(cr)
update(cr)
Common.text_row_draw_dynamic(status, cr)
@ -215,8 +223,7 @@ local draw_dynamic = function(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
end
return function()
return {static = draw_static, dynamic = draw_dynamic}
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 = Common.initThemedLabelPlot(
Geometry.RIGHT_X,
_PLOT_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
Common.percent_label_style
)
local tbl = Common.initTable(
Geometry.RIGHT_X,
@ -113,7 +106,34 @@ local tbl = Common.initTable(
{'Name', 'PID', 'Mem (%)'}
)
local update = function(cr)
-- _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
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
@ -153,24 +173,9 @@ local update = function(cr)
Table.set(tbl, cr, 2, r, pid)
Table.set(tbl, cr, 3, r, mem)
end
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)
local draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_ring_draw_static(text_ring, cr)
@ -181,9 +186,9 @@ local draw_static = function(cr)
LabelPlot.draw_static(plot, cr)
Table.draw_static(tbl, cr)
end
end
local draw_dynamic = function(cr)
local draw_dynamic = function(cr)
update(cr)
Dial.draw_dynamic(dial, cr)
@ -196,8 +201,7 @@ local draw_dynamic = function(cr)
LabelPlot.draw_dynamic(plot, cr)
Table.draw_dynamic(tbl, cr)
end
end
return function(update_freq)
return {dynamic = draw_dynamic, static = draw_static}
end

View File

@ -18,14 +18,26 @@ local value_format_function = function(bits)
return Util.precision_round_to_string(value, 3)..' '..unit..'b/s'
end
local header = Common.Header(
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(
local dnload = Common.initLabeledScalePlot(
Geometry.CENTER_RIGHT_X,
header.bottom_y,
Geometry.SECTION_WIDTH,
@ -34,10 +46,11 @@ local dnload = Common.initLabeledScalePlot(
network_label_function,
_PLOT_SEC_BREAK_,
'Download',
2
)
2,
update_freq
)
local upload = Common.initLabeledScalePlot(
local upload = Common.initLabeledScalePlot(
Geometry.CENTER_RIGHT_X,
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
Geometry.SECTION_WIDTH,
@ -46,25 +59,10 @@ local upload = Common.initLabeledScalePlot(
network_label_function,
_PLOT_SEC_BREAK_,
'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 dspeed, uspeed = 0, 0
@ -108,6 +106,12 @@ return function(update_freq)
Common.annotated_scale_plot_set(upload, cr, uspeed)
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)
_update(cr)
Common.annotated_scale_plot_draw_dynamic(dnload, cr)

View File

@ -36,7 +36,24 @@ local header = Common.Header(
'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,
header.bottom_y,
Geometry.SECTION_WIDTH,
@ -45,12 +62,11 @@ local pkg0 = Common.initLabeledScalePlot(
power_label_function,
_PLOT_SEC_BREAK_,
'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,
_CORE_Y_,
Geometry.SECTION_WIDTH,
@ -59,11 +75,11 @@ local dram = Common.initLabeledScalePlot(
power_label_function,
_PLOT_SEC_BREAK_,
'DRAM',
0
)
dram.value.append_end = ' W'
0,
update_freq
)
local battery_draw = Common.initLabeledScalePlot(
local battery_draw = Common.initLabeledScalePlot(
Geometry.RIGHT_X,
_CORE_Y_ + _PLOT_SEC_BREAK_ * 2 + _PLOT_HEIGHT_,
Geometry.SECTION_WIDTH,
@ -72,30 +88,9 @@ local battery_draw = Common.initLabeledScalePlot(
power_label_function,
_PLOT_SEC_BREAK_,
'Battery Draw',
0
)
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)
0,
update_freq
)
local _update = function(cr, is_using_ac)
local pkg0_uj_cnt = Util.read_file(PKG0_PATH, nil, '*n')
@ -122,6 +117,13 @@ return function(update_freq)
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)
_update(cr, is_using_ac)
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 total_load = Common.initPercentPlot(
Geometry.LEFT_X,
_LOAD_Y_,
Geometry.SECTION_WIDTH,
_PLOT_HEIGHT_,
_PLOT_SECTION_BREAK_,
"Total Load"
)
local tbl = Common.initTable(
Geometry.LEFT_X,
@ -197,7 +189,39 @@ local _read_hwp = function()
end
end
local update = function(cr, trigger)
-- _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)
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
@ -246,27 +270,9 @@ local update = function(cr, trigger)
Table.set(tbl, cr, 3, r, cpu)
end
end
end
end
_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
local draw_static = function(cr)
local draw_static = function(cr)
Common.drawHeader(cr, header)
for c = 1, NUM_PHYSICAL_CORES do
@ -281,9 +287,9 @@ local draw_static = function(cr)
Common.percent_plot_draw_static(total_load, cr)
Table.draw_static(tbl, cr)
end
end
local draw_dynamic = function(cr, trigger)
local draw_dynamic = function(cr, trigger)
update(cr, trigger)
for c = 1, NUM_PHYSICAL_CORES do
@ -296,8 +302,7 @@ local draw_dynamic = function(cr, trigger)
Common.percent_plot_draw_dynamic(total_load, cr)
Table.draw_dynamic(tbl, cr)
end
end
return function()
return {static = draw_static, dynamic = draw_dynamic}
end

View File

@ -30,14 +30,15 @@ local format_value_function = function(bps)
return Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
end
local header = Common.Header(
return function(update_freq)
local header = Common.Header(
Geometry.CENTER_LEFT_X,
Geometry.TOP_Y,
Geometry.SECTION_WIDTH,
'INPUT / OUTPUT'
)
)
local reads = Common.initLabeledScalePlot(
local reads = Common.initLabeledScalePlot(
Geometry.CENTER_LEFT_X,
header.bottom_y,
Geometry.SECTION_WIDTH,
@ -46,11 +47,11 @@ local reads = Common.initLabeledScalePlot(
io_label_function,
_PLOT_SEC_BREAK_,
'Reads',
2
2,
update_freq
)
)
local writes = Common.initLabeledScalePlot(
local writes = Common.initLabeledScalePlot(
Geometry.CENTER_LEFT_X,
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
Geometry.SECTION_WIDTH,
@ -59,23 +60,13 @@ local writes = Common.initLabeledScalePlot(
io_label_function,
_PLOT_SEC_BREAK_,
'Writes',
2
)
2,
update_freq
)
_PLOT_SEC_BREAK_ = nil
_PLOT_HEIGHT_ = nil
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)
reads.byte_cnt = 0
writes.byte_cnt = 0
reads.prev_byte_cnt, writes.prev_byte_cnt = read_stat_file()
local update_stat = function(cr, stat, 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)
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)
update(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
--
@ -102,8 +93,8 @@ function conky_start(update_interval)
local pwr = Power(update_freq)
local fs = FileSystem()
local sys = System()
local gfx = Graphics()
local proc = Processor()
local gfx = Graphics(update_freq)
local proc = Processor(update_freq)
local pcm = Pacman()
local cs_left = _make_static_surface(