REF make updater code cleaner
This commit is contained in:
parent
73fd89a6f5
commit
7ade617e80
|
@ -11,17 +11,20 @@ local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
|
||||||
if type(new) == "number" then
|
if type(new) == "number" then
|
||||||
acc.next_y = acc.next_y + new
|
acc.next_y = acc.next_y + new
|
||||||
else
|
else
|
||||||
-- gross...
|
|
||||||
local m = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
|
local m = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
|
||||||
local secs = {}
|
local r = common.compile_module(
|
||||||
for i = 1, #m do
|
m.header,
|
||||||
secs[i] = m[i]
|
m.point,
|
||||||
end
|
m.width,
|
||||||
local r = common.compile_module(m.header, m.point, m.width, m.top, table.unpack(secs))
|
m.top,
|
||||||
if m.update_wrapper ~= nil then
|
table.unpack(pure.table_array(m))
|
||||||
r = pure.map_at("update", m.update_wrapper, r)
|
)
|
||||||
end
|
local update = pure.maybe(
|
||||||
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic})
|
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_x = math.max(acc.next_x, r.next_x)
|
||||||
acc.next_y = r.next_y
|
acc.next_y = r.next_y
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,7 +71,7 @@ return function(config, main_state, common, width, point)
|
||||||
header = 'FILE SYSTEMS',
|
header = 'FILE SYSTEMS',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = nil,
|
set_state = nil,
|
||||||
top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
|
top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
|
||||||
common.mk_section(SEPARATOR_SPACING, {mk_bars, true, 0})
|
common.mk_section(SEPARATOR_SPACING, {mk_bars, true, 0})
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,7 +212,7 @@ return function(update_freq, config, common, width, point)
|
||||||
header = 'NVIDIA GRAPHICS',
|
header = 'NVIDIA GRAPHICS',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = function(f) return function(_) update_state() f() end end,
|
set_state = update_state,
|
||||||
top = {{mk_status, true, SEPARATOR_SPACING}},
|
top = {{mk_status, true, SEPARATOR_SPACING}},
|
||||||
common.mk_section(
|
common.mk_section(
|
||||||
SEPARATOR_SPACING,
|
SEPARATOR_SPACING,
|
||||||
|
|
|
@ -182,7 +182,7 @@ return function(update_freq, config, common, width, point)
|
||||||
header = 'MEMORY',
|
header = 'MEMORY',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = function(f) return function(_) read_state() f() end end,
|
set_state = read_state,
|
||||||
top = {
|
top = {
|
||||||
{mk_stats, config.show_stats, PLOT_SECTION_BREAK},
|
{mk_stats, config.show_stats, PLOT_SECTION_BREAK},
|
||||||
{mk_plot, config.show_plot, TABLE_SECTION_BREAK},
|
{mk_plot, config.show_plot, TABLE_SECTION_BREAK},
|
||||||
|
|
|
@ -68,7 +68,7 @@ return function(update_freq, common, width, point)
|
||||||
header = 'NETWORK',
|
header = 'NETWORK',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = function(f) return function(_) read_interfaces() f() end end,
|
set_state = read_interfaces,
|
||||||
top = {
|
top = {
|
||||||
{mk_rx, true, PLOT_SEC_BREAK},
|
{mk_rx, true, PLOT_SEC_BREAK},
|
||||||
{mk_tx, true, 0},
|
{mk_tx, true, 0},
|
||||||
|
|
|
@ -44,7 +44,7 @@ return function(main_state, common, width, point)
|
||||||
header = 'PACMAN',
|
header = 'PACMAN',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = nil,
|
set_state = nil,
|
||||||
top = {{mk_stats, true, 0}}
|
top = {{mk_stats, true, 0}}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -109,7 +109,7 @@ return function(update_freq, config, common, width, point)
|
||||||
header = 'POWER',
|
header = 'POWER',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = nil,
|
set_state = nil,
|
||||||
top = pure.concat(
|
top = pure.concat(
|
||||||
pure.map(mk_rate_blockspec, config.rapl_specs),
|
pure.map(mk_rate_blockspec, config.rapl_specs),
|
||||||
-- TODO what happens if this is nil?
|
-- TODO what happens if this is nil?
|
||||||
|
|
|
@ -208,12 +208,7 @@ return function(update_freq, config, main_state, common, width, point)
|
||||||
header = 'PROCESSOR',
|
header = 'PROCESSOR',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = function(f)
|
set_state = update_state,
|
||||||
return function()
|
|
||||||
update_state()
|
|
||||||
f()
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
top = {
|
top = {
|
||||||
{mk_cores, config.show_cores, TEXT_SPACING},
|
{mk_cores, config.show_cores, TEXT_SPACING},
|
||||||
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
|
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
|
||||||
|
|
|
@ -5,11 +5,13 @@ local sys = require 'sys'
|
||||||
return function(update_freq, config, common, width, point)
|
return function(update_freq, config, common, width, point)
|
||||||
local PLOT_SEC_BREAK = 20
|
local PLOT_SEC_BREAK = 20
|
||||||
local PLOT_HEIGHT = 56
|
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}
|
local mod_state = {read = 0, write = 0}
|
||||||
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
|
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 format_value_function = function(bps)
|
||||||
local unit, value = format.convert_data_val(bps)
|
local unit, value = format.convert_data_val(bps)
|
||||||
|
@ -31,13 +33,13 @@ return function(update_freq, config, common, width, point)
|
||||||
label,
|
label,
|
||||||
2,
|
2,
|
||||||
update_freq,
|
update_freq,
|
||||||
state[key]
|
mod_state[key]
|
||||||
)
|
)
|
||||||
return common.mk_acc(
|
return common.mk_acc(
|
||||||
-- TODO construct this more sanely without referring to hardcoded vars
|
-- TODO construct this more sanely without referring to hardcoded vars
|
||||||
width,
|
width,
|
||||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
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_static, obj),
|
||||||
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, 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',
|
header = 'INPUT / OUTPUT',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = function(f)
|
set_state = update_state,
|
||||||
return function(_)
|
|
||||||
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
|
|
||||||
f()
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
top = {
|
top = {
|
||||||
{mk_reads, true, PLOT_SEC_BREAK},
|
{mk_reads, true, PLOT_SEC_BREAK},
|
||||||
{mk_writes, true, 0},
|
{mk_writes, true, 0},
|
||||||
|
|
|
@ -43,7 +43,7 @@ return function(main_state, common, width, point)
|
||||||
header = 'SYSTEM',
|
header = 'SYSTEM',
|
||||||
point = point,
|
point = point,
|
||||||
width = width,
|
width = width,
|
||||||
update_wrapper = nil,
|
set_state = nil,
|
||||||
top = {{mk_stats, true, 0}}
|
top = {{mk_stats, true, 0}}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue