diff --git a/drawing/compile.lua b/drawing/compile.lua index b2e09c8..5585299 100644 --- a/drawing/compile.lua +++ b/drawing/compile.lua @@ -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 diff --git a/drawing/filesystem.lua b/drawing/filesystem.lua index e97bad2..4cb173a 100644 --- a/drawing/filesystem.lua +++ b/drawing/filesystem.lua @@ -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}) } diff --git a/drawing/graphics.lua b/drawing/graphics.lua index ddb423a..6a7cf9f 100644 --- a/drawing/graphics.lua +++ b/drawing/graphics.lua @@ -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, diff --git a/drawing/memory.lua b/drawing/memory.lua index 8099814..a751467 100644 --- a/drawing/memory.lua +++ b/drawing/memory.lua @@ -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}, diff --git a/drawing/network.lua b/drawing/network.lua index 3712ccf..91cd687 100644 --- a/drawing/network.lua +++ b/drawing/network.lua @@ -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}, diff --git a/drawing/pacman.lua b/drawing/pacman.lua index 8d84440..8c6d8ff 100644 --- a/drawing/pacman.lua +++ b/drawing/pacman.lua @@ -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 diff --git a/drawing/power.lua b/drawing/power.lua index 6c62b1b..8906e80 100644 --- a/drawing/power.lua +++ b/drawing/power.lua @@ -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? diff --git a/drawing/processor.lua b/drawing/processor.lua index f37467f..95dc495 100644 --- a/drawing/processor.lua +++ b/drawing/processor.lua @@ -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}, diff --git a/drawing/readwrite.lua b/drawing/readwrite.lua index fcbe0a1..f2f1777 100644 --- a/drawing/readwrite.lua +++ b/drawing/readwrite.lua @@ -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}, diff --git a/drawing/system.lua b/drawing/system.lua index 506cb91..39238ae 100644 --- a/drawing/system.lua +++ b/drawing/system.lua @@ -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