REF simplify readwrite and network code
This commit is contained in:
parent
7c34e08bc1
commit
c4d2fb4ea2
|
@ -84,24 +84,31 @@ return function(update_freq)
|
||||||
return rx, tx
|
return rx, tx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local compute_speed = function(x0, x1)
|
||||||
|
-- mask overflow
|
||||||
|
if x1 > x0 then
|
||||||
|
return (x1 - x0) * update_freq
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local prev_rx_bits, prev_tx_bits = read_interfaces()
|
local prev_rx_bits, prev_tx_bits = read_interfaces()
|
||||||
|
|
||||||
local update = function(cr)
|
local update = function(cr)
|
||||||
local dspeed, uspeed = 0, 0
|
|
||||||
local rx_bits, tx_bits = read_interfaces()
|
local rx_bits, tx_bits = read_interfaces()
|
||||||
|
Common.annotated_scale_plot_set(
|
||||||
-- mask overflow
|
dnload,
|
||||||
if rx_bits > prev_rx_bits then
|
cr,
|
||||||
dspeed = (rx_bits - prev_rx_bits) * update_freq
|
compute_speed(prev_rx_bits, rx_bits)
|
||||||
end
|
)
|
||||||
if tx_bits > prev_tx_bits then
|
Common.annotated_scale_plot_set(
|
||||||
uspeed = (tx_bits - prev_tx_bits) * update_freq
|
upload,
|
||||||
end
|
cr,
|
||||||
|
compute_speed(prev_tx_bits, tx_bits)
|
||||||
|
)
|
||||||
prev_rx_bits = rx_bits
|
prev_rx_bits = rx_bits
|
||||||
prev_tx_bits = tx_bits
|
prev_tx_bits = tx_bits
|
||||||
|
|
||||||
Common.annotated_scale_plot_set(dnload, cr, dspeed)
|
|
||||||
Common.annotated_scale_plot_set(upload, cr, uspeed)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -85,26 +85,31 @@ return function(update_freq)
|
||||||
return read_bytes * BLOCK_SIZE_BYTES, write_bytes * BLOCK_SIZE_BYTES
|
return read_bytes * BLOCK_SIZE_BYTES, write_bytes * BLOCK_SIZE_BYTES
|
||||||
end
|
end
|
||||||
|
|
||||||
reads.byte_cnt = 0
|
local prev_read_bytes, prev_write_bytes = read_devices()
|
||||||
writes.byte_cnt = 0
|
|
||||||
reads.prev_byte_cnt, writes.prev_byte_cnt = read_devices()
|
|
||||||
|
|
||||||
local update_stat = function(cr, stat, byte_cnt)
|
local compute_rate = function(x0, x1)
|
||||||
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
-- mask overflow
|
||||||
stat.prev_byte_cnt = byte_cnt
|
if x1 > x0 then
|
||||||
|
return (x1 - x0) * update_freq
|
||||||
local plot_value = 0
|
else
|
||||||
if delta_bytes > 0 then
|
return 0
|
||||||
local bps = delta_bytes * update_freq
|
|
||||||
plot_value = bps
|
|
||||||
end
|
end
|
||||||
Common.annotated_scale_plot_set(stat, cr, plot_value)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local update = function(cr)
|
local update = function(cr)
|
||||||
local read_byte_cnt, write_byte_cnt = read_devices()
|
local read_bytes, write_bytes = read_devices()
|
||||||
update_stat(cr, reads, read_byte_cnt)
|
Common.annotated_scale_plot_set(
|
||||||
update_stat(cr, writes, write_byte_cnt)
|
reads,
|
||||||
|
cr,
|
||||||
|
compute_rate(prev_read_bytes, read_bytes)
|
||||||
|
)
|
||||||
|
Common.annotated_scale_plot_set(
|
||||||
|
writes,
|
||||||
|
cr,
|
||||||
|
compute_rate(prev_write_bytes, write_bytes)
|
||||||
|
)
|
||||||
|
prev_read_bytes = read_bytes
|
||||||
|
prev_write_bytes = write_bytes
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue