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
|
||||
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 update = function(cr)
|
||||
local dspeed, uspeed = 0, 0
|
||||
local rx_bits, tx_bits = read_interfaces()
|
||||
|
||||
-- mask overflow
|
||||
if rx_bits > prev_rx_bits then
|
||||
dspeed = (rx_bits - prev_rx_bits) * update_freq
|
||||
end
|
||||
if tx_bits > prev_tx_bits then
|
||||
uspeed = (tx_bits - prev_tx_bits) * update_freq
|
||||
end
|
||||
Common.annotated_scale_plot_set(
|
||||
dnload,
|
||||
cr,
|
||||
compute_speed(prev_rx_bits, rx_bits)
|
||||
)
|
||||
Common.annotated_scale_plot_set(
|
||||
upload,
|
||||
cr,
|
||||
compute_speed(prev_tx_bits, tx_bits)
|
||||
)
|
||||
prev_rx_bits = rx_bits
|
||||
prev_tx_bits = tx_bits
|
||||
|
||||
Common.annotated_scale_plot_set(dnload, cr, dspeed)
|
||||
Common.annotated_scale_plot_set(upload, cr, uspeed)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
|
@ -85,26 +85,31 @@ return function(update_freq)
|
|||
return read_bytes * BLOCK_SIZE_BYTES, write_bytes * BLOCK_SIZE_BYTES
|
||||
end
|
||||
|
||||
reads.byte_cnt = 0
|
||||
writes.byte_cnt = 0
|
||||
reads.prev_byte_cnt, writes.prev_byte_cnt = read_devices()
|
||||
local prev_read_bytes, prev_write_bytes = read_devices()
|
||||
|
||||
local update_stat = function(cr, stat, byte_cnt)
|
||||
local delta_bytes = byte_cnt - stat.prev_byte_cnt
|
||||
stat.prev_byte_cnt = byte_cnt
|
||||
|
||||
local plot_value = 0
|
||||
if delta_bytes > 0 then
|
||||
local bps = delta_bytes * update_freq
|
||||
plot_value = bps
|
||||
local compute_rate = function(x0, x1)
|
||||
-- mask overflow
|
||||
if x1 > x0 then
|
||||
return (x1 - x0) * update_freq
|
||||
else
|
||||
return 0
|
||||
end
|
||||
Common.annotated_scale_plot_set(stat, cr, plot_value)
|
||||
end
|
||||
|
||||
local update = function(cr)
|
||||
local read_byte_cnt, write_byte_cnt = read_devices()
|
||||
update_stat(cr, reads, read_byte_cnt)
|
||||
update_stat(cr, writes, write_byte_cnt)
|
||||
local read_bytes, write_bytes = read_devices()
|
||||
Common.annotated_scale_plot_set(
|
||||
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
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue