ENH use func lib

This commit is contained in:
Nathan Dwarshuis 2021-07-23 01:41:06 -04:00
parent 1fb0ebe60b
commit 709845dd8d
5 changed files with 30 additions and 28 deletions

2
core

@ -1 +1 @@
Subproject commit d10599afc4b851673cdb788a7184361816822656
Subproject commit 532a808bd316237644e763c7af80487fa6a36d8f

View File

@ -3,6 +3,7 @@ local Table = require 'Table'
local Util = require 'Util'
local Common = require 'Common'
local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq)
local MODULE_Y = 712
@ -111,14 +112,15 @@ return function(update_freq)
-- memory top table
local NUM_ROWS = 5
local TABLE_CONKY = {}
for r = 1, NUM_ROWS do
TABLE_CONKY[r] = {
comm = '${top_mem name '..r..'}',
pid = '${top_mem pid '..r..'}',
mem = '${top_mem mem '..r..'}',
local TABLE_CONKY = func.map(
function(i)
return {
comm = '${top_mem name '..i..'}',
pid = '${top_mem pid '..i..'}',
mem = '${top_mem mem '..i..'}',
}
end
end,
func.seq(NUM_ROWS))
local tbl = Common.initTable(
Geometry.RIGHT_X,

View File

@ -1,6 +1,7 @@
local Util = require 'Util'
local Common = require 'Common'
local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq)
local PLOT_SEC_BREAK = 20
@ -17,14 +18,13 @@ return function(update_freq)
local INTERFACES = get_interfaces()
local INTERFACE_PATHS = {}
for i = 1, #INTERFACES do
local dir = string.format('/sys/class/net/%s/statistics/', INTERFACES[i])
INTERFACE_PATHS[i] = {
rx = dir..'rx_bytes',
tx = dir..'tx_bytes',
}
end
local INTERFACE_PATHS = func.map(
function(s)
local dir = string.format('/sys/class/net/%s/statistics/', s)
return {rx = dir..'rx_bytes', tx = dir..'tx_bytes'}
end,
INTERFACES
)
local get_bits = function(path)
return Util.read_file(path, nil, '*n') * 8

View File

@ -5,6 +5,7 @@ local Util = require 'Util'
local Common = require 'Common'
local Geometry = require 'Geometry'
local CPU = require 'CPU'
local func = require 'func'
local __math_floor = math.floor
@ -116,13 +117,10 @@ return function(update_freq)
-- cpu top table
local NUM_ROWS = 5
local TABLE_CONKY = {}
for r = 1, NUM_ROWS do
TABLE_CONKY[r] = {
pid = '${top pid '..r..'}',
cpu = '${top cpu '..r..'}'
}
end
local TABLE_CONKY = func.map(
function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
func.seq(NUM_ROWS)
)
local tbl = Common.initTable(
Geometry.LEFT_X,

View File

@ -1,6 +1,7 @@
local Util = require 'Util'
local Common = require 'Common'
local Geometry = require 'Geometry'
local func = require 'func'
return function(update_freq)
local PLOT_SEC_BREAK = 20
@ -17,10 +18,11 @@ return function(update_freq)
local __tonumber = tonumber
local __string_match = string.match
local DEVICE_PATHS = {}
for i = 1, #DEVICES do
DEVICE_PATHS[i] = string.format('/sys/block/%s/stat', DEVICES[i])
end
-- TODO any way to make better lambda functions?
local DEVICE_PATHS = func.map(
function(s) return string.format('/sys/block/%s/stat', s) end,
DEVICES
)
local read_devices = function()
local read_bytes = 0