REF make updater code cleaner

This commit is contained in:
Nathan Dwarshuis 2022-07-17 22:30:38 -04:00
parent 73fd89a6f5
commit 7ade617e80
10 changed files with 30 additions and 35 deletions

View File

@ -11,17 +11,20 @@ local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
if type(new) == "number" then
acc.next_y = acc.next_y + new
else
-- gross...
local m = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
local secs = {}
for i = 1, #m do
secs[i] = m[i]
end
local r = common.compile_module(m.header, m.point, m.width, m.top, table.unpack(secs))
if m.update_wrapper ~= nil then
r = pure.map_at("update", m.update_wrapper, r)
end
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic})
local r = common.compile_module(
m.header,
m.point,
m.width,
m.top,
table.unpack(pure.table_array(m))
)
local update = pure.maybe(
r.update,
function(f) return function() f() r.update() end end,
m.set_state
)
table.insert(acc.fgroups, {update = update, static = r.static, dynamic = r.dynamic})
acc.next_x = math.max(acc.next_x, r.next_x)
acc.next_y = r.next_y
end

View File

@ -71,7 +71,7 @@ return function(config, main_state, common, width, point)
header = 'FILE SYSTEMS',
point = point,
width = width,
update_wrapper = nil,
set_state = nil,
top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
common.mk_section(SEPARATOR_SPACING, {mk_bars, true, 0})
}

View File

@ -212,7 +212,7 @@ return function(update_freq, config, common, width, point)
header = 'NVIDIA GRAPHICS',
point = point,
width = width,
update_wrapper = function(f) return function(_) update_state() f() end end,
set_state = update_state,
top = {{mk_status, true, SEPARATOR_SPACING}},
common.mk_section(
SEPARATOR_SPACING,

View File

@ -182,7 +182,7 @@ return function(update_freq, config, common, width, point)
header = 'MEMORY',
point = point,
width = width,
update_wrapper = function(f) return function(_) read_state() f() end end,
set_state = read_state,
top = {
{mk_stats, config.show_stats, PLOT_SECTION_BREAK},
{mk_plot, config.show_plot, TABLE_SECTION_BREAK},

View File

@ -68,7 +68,7 @@ return function(update_freq, common, width, point)
header = 'NETWORK',
point = point,
width = width,
update_wrapper = function(f) return function(_) read_interfaces() f() end end,
set_state = read_interfaces,
top = {
{mk_rx, true, PLOT_SEC_BREAK},
{mk_tx, true, 0},

View File

@ -44,7 +44,7 @@ return function(main_state, common, width, point)
header = 'PACMAN',
point = point,
width = width,
update_wrapper = nil,
set_state = nil,
top = {{mk_stats, true, 0}}
}
end

View File

@ -109,7 +109,7 @@ return function(update_freq, config, common, width, point)
header = 'POWER',
point = point,
width = width,
update_wrapper = nil,
set_state = nil,
top = pure.concat(
pure.map(mk_rate_blockspec, config.rapl_specs),
-- TODO what happens if this is nil?

View File

@ -208,12 +208,7 @@ return function(update_freq, config, main_state, common, width, point)
header = 'PROCESSOR',
point = point,
width = width,
update_wrapper = function(f)
return function()
update_state()
f()
end
end,
set_state = update_state,
top = {
{mk_cores, config.show_cores, TEXT_SPACING},
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},

View File

@ -5,11 +5,13 @@ local sys = require 'sys'
return function(update_freq, config, common, width, point)
local PLOT_SEC_BREAK = 20
local PLOT_HEIGHT = 56
-- TODO currently this will find any block device
local DEVICE_PATHS = sys.get_disk_paths(config.devices)
local state = {read = 0, write = 0}
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
local mod_state = {read = 0, write = 0}
local device_paths = sys.get_disk_paths(config.devices)
local update_state = function()
mod_state.read, mod_state.write = sys.get_total_disk_io(device_paths)
end
local format_value_function = function(bps)
local unit, value = format.convert_data_val(bps)
@ -31,13 +33,13 @@ return function(update_freq, config, common, width, point)
label,
2,
update_freq,
state[key]
mod_state[key]
)
return common.mk_acc(
-- TODO construct this more sanely without referring to hardcoded vars
width,
PLOT_HEIGHT + PLOT_SEC_BREAK,
function() common.update_rate_timeseries(obj, state[key]) end,
function() common.update_rate_timeseries(obj, mod_state[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
)
@ -53,12 +55,7 @@ return function(update_freq, config, common, width, point)
header = 'INPUT / OUTPUT',
point = point,
width = width,
update_wrapper = function(f)
return function(_)
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
f()
end
end,
set_state = update_state,
top = {
{mk_reads, true, PLOT_SEC_BREAK},
{mk_writes, true, 0},

View File

@ -43,7 +43,7 @@ return function(main_state, common, width, point)
header = 'SYSTEM',
point = point,
width = width,
update_wrapper = nil,
set_state = nil,
top = {{mk_stats, true, 0}}
}
end