2018-08-05 11:22:07 -04:00
|
|
|
local M = {}
|
|
|
|
|
2017-07-19 00:43:44 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
local Common = require 'Common'
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local __tonumber = tonumber
|
|
|
|
local __string_match = string.match
|
2021-07-13 23:01:28 -04:00
|
|
|
local __math_floor = math.floor
|
2017-07-19 00:36:15 -04:00
|
|
|
|
|
|
|
local _PLOT_SEC_BREAK_ = 20
|
|
|
|
local _PLOT_HEIGHT_ = 56
|
|
|
|
|
|
|
|
local BLOCK_SIZE_BYTES = 512
|
|
|
|
local STAT_FILE = '/sys/block/sda/stat'
|
|
|
|
|
|
|
|
-- fields 3 and 7 (sectors read and written)
|
|
|
|
local RW_REGEX = '%s+%d+%s+%d+%s+(%d+)%s+%d+%s+%d+%s+%d+%s+(%d+)'
|
|
|
|
|
|
|
|
local read_stat_file = function()
|
2017-07-19 00:43:44 -04:00
|
|
|
local bytes_r, bytes_w = __string_match(Util.read_file(STAT_FILE), RW_REGEX)
|
2017-07-19 00:36:15 -04:00
|
|
|
return __tonumber(bytes_r) * BLOCK_SIZE_BYTES, __tonumber(bytes_w) * BLOCK_SIZE_BYTES
|
|
|
|
end
|
|
|
|
|
|
|
|
local update_stat = function(cr, stat, byte_cnt, update_frequency)
|
|
|
|
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
|
|
|
stat.prev_byte_cnt = byte_cnt
|
2019-09-01 15:34:10 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local plot_value = 0
|
2017-07-19 00:36:15 -04:00
|
|
|
if delta_bytes > 0 then
|
|
|
|
local bps = delta_bytes * update_frequency
|
2021-07-05 23:27:43 -04:00
|
|
|
plot_value = bps
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
2021-07-11 20:26:02 -04:00
|
|
|
Common.annotated_scale_plot_set(stat, cr, plot_value)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local io_label_function = function(bytes)
|
2021-06-17 18:18:09 -04:00
|
|
|
local new_unit, new_value = Util.convert_data_val(bytes)
|
2021-07-13 23:01:28 -04:00
|
|
|
return __math_floor(new_value)..' '..new_unit..'B/s'
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2021-07-11 20:26:02 -04:00
|
|
|
local format_value_function = function(bps)
|
|
|
|
local unit, value = Util.convert_data_val(bps)
|
|
|
|
return Util.precision_round_to_string(value, 3)..' '..unit..'B/s'
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
local header = Common.Header(
|
|
|
|
_G_INIT_DATA_.CENTER_LEFT_X,
|
|
|
|
_G_INIT_DATA_.TOP_Y,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
'INPUT / OUTPUT'
|
|
|
|
)
|
|
|
|
|
|
|
|
local reads = Common.initLabeledScalePlot(
|
|
|
|
_G_INIT_DATA_.CENTER_LEFT_X,
|
|
|
|
header.bottom_y,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
2021-07-11 20:26:02 -04:00
|
|
|
format_value_function,
|
2021-07-05 23:27:43 -04:00
|
|
|
io_label_function,
|
|
|
|
_PLOT_SEC_BREAK_,
|
2021-07-13 22:54:41 -04:00
|
|
|
'Reads',
|
|
|
|
2
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
local writes = Common.initLabeledScalePlot(
|
|
|
|
_G_INIT_DATA_.CENTER_LEFT_X,
|
|
|
|
header.bottom_y + _PLOT_HEIGHT_ + _PLOT_SEC_BREAK_ * 2,
|
|
|
|
_G_INIT_DATA_.SECTION_WIDTH,
|
|
|
|
_PLOT_HEIGHT_,
|
2021-07-11 20:26:02 -04:00
|
|
|
format_value_function,
|
2021-07-05 23:27:43 -04:00
|
|
|
io_label_function,
|
|
|
|
_PLOT_SEC_BREAK_,
|
2021-07-13 22:54:41 -04:00
|
|
|
'Writes',
|
|
|
|
2
|
2021-07-05 23:27:43 -04:00
|
|
|
)
|
2017-07-19 00:36:15 -04:00
|
|
|
|
2021-07-13 22:54:41 -04:00
|
|
|
|
2017-07-19 00:36:15 -04:00
|
|
|
_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 update = function(cr, update_frequency)
|
|
|
|
local read_byte_cnt, write_byte_cnt = read_stat_file()
|
|
|
|
update_stat(cr, reads, read_byte_cnt, update_frequency)
|
|
|
|
update_stat(cr, writes, write_byte_cnt, update_frequency)
|
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
local draw_static = function(cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.drawHeader(cr, header)
|
|
|
|
Common.annotated_scale_plot_draw_static(reads, cr)
|
|
|
|
Common.annotated_scale_plot_draw_static(writes, cr)
|
2018-08-05 11:22:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local draw_dynamic = function(cr, update_frequency)
|
2018-08-05 11:08:37 -04:00
|
|
|
update(cr, update_frequency)
|
2021-07-05 23:27:43 -04:00
|
|
|
Common.annotated_scale_plot_draw_dynamic(reads, cr)
|
|
|
|
Common.annotated_scale_plot_draw_dynamic(writes, cr)
|
2017-07-19 00:36:15 -04:00
|
|
|
end
|
|
|
|
|
2018-08-05 11:22:07 -04:00
|
|
|
M.draw_static = draw_static
|
|
|
|
M.draw_dynamic = draw_dynamic
|
|
|
|
|
|
|
|
return M
|