REF make io module use setup framework

This commit is contained in:
Nathan Dwarshuis 2022-07-14 22:59:14 -04:00
parent 1e09124a0c
commit 088979312d
1 changed files with 35 additions and 44 deletions

View File

@ -1,4 +1,5 @@
local format = require 'format' local format = require 'format'
local pure = require 'pure'
local common = require 'common' local common = require 'common'
local geometry = require 'geometry' local geometry = require 'geometry'
local sys = require 'sys' local sys = require 'sys'
@ -9,15 +10,19 @@ return function(update_freq, devices, point)
-- TODO currently this will find any block device -- TODO currently this will find any block device
local DEVICE_PATHS = sys.get_disk_paths(devices) local DEVICE_PATHS = sys.get_disk_paths(devices)
local init_read_bytes, init_write_bytes = sys.get_total_disk_io(DEVICE_PATHS) local state = {read = 0, write = 0}
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
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)
return format.precision_round_to_string(value, 3)..' '..unit..'B/s' return format.precision_round_to_string(value, 3)..' '..unit..'B/s'
end end
local make_plot = function(y, label, init) -----------------------------------------------------------------------------
return common.make_rate_timeseries( -- r/w plots
local mk_plot = function(label, key, y)
local obj = common.make_rate_timeseries(
point.x, point.x,
y, y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
@ -28,53 +33,39 @@ return function(update_freq, devices, point)
label, label,
2, 2,
update_freq, update_freq,
init state[key]
)
return common.mk_acc(
PLOT_HEIGHT + PLOT_SEC_BREAK,
function() common.update_rate_timeseries(obj, state[key]) end,
pure.partial(common.tagged_scaled_timeseries_draw_static, obj),
pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj)
) )
end end
----------------------------------------------------------------------------- local mk_reads = pure.partial(mk_plot, 'Reads', 'read')
-- header local mk_writes = pure.partial(mk_plot, 'Writes', 'write')
local header = common.make_header(
point.x,
point.y,
geometry.SECTION_WIDTH,
'INPUT / OUTPUT'
)
-----------------------------------------------------------------------------
-- reads
local reads = make_plot(header.bottom_y, 'Reads', init_read_bytes)
-----------------------------------------------------------------------------
-- writes
local writes = make_plot(
header.bottom_y + PLOT_HEIGHT + PLOT_SEC_BREAK * 2,
'Writes',
init_write_bytes
)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local update = function() local rbs = common.reduce_blocks_(
local read_bytes, write_bytes = sys.get_total_disk_io(DEVICE_PATHS) 'INPUT / OUTPUT',
common.update_rate_timeseries(reads, read_bytes) point,
common.update_rate_timeseries(writes, write_bytes) geometry.SECTION_WIDTH,
end {
common.mk_block(mk_reads, true, 0),
common.mk_block(mk_writes, true, PLOT_SEC_BREAK),
}
)
local draw_static = function(cr) return pure.map_at(
common.draw_header(cr, header) "update",
common.tagged_scaled_timeseries_draw_static(reads, cr) function(f)
common.tagged_scaled_timeseries_draw_static(writes, cr) return function()
end state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
f()
local draw_dynamic = function(cr) end
common.tagged_scaled_timeseries_draw_dynamic(reads, cr) end,
common.tagged_scaled_timeseries_draw_dynamic(writes, cr) rbs)
end
return {static = draw_static, dynamic = draw_dynamic, update = update}
end end