ENH add config option for swap
This commit is contained in:
parent
e5e83c5b79
commit
6a022c36c6
|
@ -20,6 +20,8 @@ return function(update_freq, config, common, width, point)
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- state
|
-- state
|
||||||
|
|
||||||
|
local use_swap = false
|
||||||
|
|
||||||
local MEMINFO_REGEX = '\nMemFree:%s+(%d+).+'..
|
local MEMINFO_REGEX = '\nMemFree:%s+(%d+).+'..
|
||||||
'\nBuffers:%s+(%d+).+'..
|
'\nBuffers:%s+(%d+).+'..
|
||||||
'\nCached:%s+(%d+).+'..
|
'\nCached:%s+(%d+).+'..
|
||||||
|
@ -60,12 +62,20 @@ return function(update_freq, config, common, width, point)
|
||||||
local mk_stats = function(y)
|
local mk_stats = function(y)
|
||||||
local MEM_X = point.x + DIAL_RADIUS + DIAL_THICKNESS / 2
|
local MEM_X = point.x + DIAL_RADIUS + DIAL_THICKNESS / 2
|
||||||
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
|
local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS
|
||||||
local SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING
|
local CACHE_X
|
||||||
local CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
|
local SWAP_X
|
||||||
|
if use_swap == true then
|
||||||
|
SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING
|
||||||
|
CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
|
||||||
|
else
|
||||||
|
CACHE_X = MEM_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2
|
||||||
|
end
|
||||||
local CACHE_WIDTH = point.x + width - CACHE_X
|
local CACHE_WIDTH = point.x + width - CACHE_X
|
||||||
local format_percent = function(x)
|
local format_percent = function(x)
|
||||||
return string.format('%i%%', x)
|
return string.format('%i%%', x)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- memory bits (used no matter what)
|
||||||
local mem = common.make_dial(
|
local mem = common.make_dial(
|
||||||
MEM_X,
|
MEM_X,
|
||||||
y + DIAL_RADIUS,
|
y + DIAL_RADIUS,
|
||||||
|
@ -75,15 +85,6 @@ return function(update_freq, config, common, width, point)
|
||||||
format_percent,
|
format_percent,
|
||||||
__math_floor
|
__math_floor
|
||||||
)
|
)
|
||||||
local swap = common.make_dial(
|
|
||||||
SWAP_X,
|
|
||||||
y + DIAL_RADIUS,
|
|
||||||
DIAL_RADIUS,
|
|
||||||
DIAL_THICKNESS,
|
|
||||||
80,
|
|
||||||
format_percent,
|
|
||||||
__math_floor
|
|
||||||
)
|
|
||||||
local cache = common.make_text_rows_formatted(
|
local cache = common.make_text_rows_formatted(
|
||||||
CACHE_X,
|
CACHE_X,
|
||||||
y + CACHE_Y_OFFSET,
|
y + CACHE_Y_OFFSET,
|
||||||
|
@ -92,28 +93,51 @@ return function(update_freq, config, common, width, point)
|
||||||
{'Page Cache', 'Buffers', 'Shared', 'Kernel Slab'},
|
{'Page Cache', 'Buffers', 'Shared', 'Kernel Slab'},
|
||||||
'%.1f%%'
|
'%.1f%%'
|
||||||
)
|
)
|
||||||
local update = function()
|
local update_mem = function()
|
||||||
local m = mod_state.mem
|
local m = mod_state.mem
|
||||||
local w = mod_state.swap
|
local mtot = m.total
|
||||||
common.dial_set(mem, m.used_percent * 100)
|
common.dial_set(mem, m.used_percent * 100)
|
||||||
common.dial_set(swap, (w.total - w.free) / w.total * 100)
|
|
||||||
|
|
||||||
common.text_rows_set(cache, 1, m.cached / m.total * 100)
|
common.text_rows_set(cache, 1, m.cached / mtot * 100)
|
||||||
common.text_rows_set(cache, 2, m.buffers / m.total * 100)
|
common.text_rows_set(cache, 2, m.buffers / mtot * 100)
|
||||||
common.text_rows_set(cache, 3, m.shmem / m.total * 100)
|
common.text_rows_set(cache, 3, m.shmem / mtot * 100)
|
||||||
common.text_rows_set(cache, 4, m.sreclaimable / m.total * 100)
|
common.text_rows_set(cache, 4, m.sreclaimable / mtot * 100)
|
||||||
end
|
end
|
||||||
local static = function(cr)
|
local static_mem = function(cr)
|
||||||
common.dial_draw_static(mem, cr)
|
common.dial_draw_static(mem, cr)
|
||||||
common.dial_draw_static(swap, cr)
|
|
||||||
common.text_rows_draw_static(cache, cr)
|
common.text_rows_draw_static(cache, cr)
|
||||||
end
|
end
|
||||||
local dynamic = function(cr)
|
local dynamic_mem = function(cr)
|
||||||
common.dial_draw_dynamic(mem, cr)
|
common.dial_draw_dynamic(mem, cr)
|
||||||
common.dial_draw_dynamic(swap, cr)
|
|
||||||
common.text_rows_draw_dynamic(cache, cr)
|
common.text_rows_draw_dynamic(cache, cr)
|
||||||
end
|
end
|
||||||
return common.mk_acc(width, DIAL_DIAMETER, update, static, dynamic)
|
local ret = pure.partial(common.mk_acc, width, DIAL_DIAMETER)
|
||||||
|
|
||||||
|
-- add swap bits if needed
|
||||||
|
if use_swap == true then
|
||||||
|
local swap = common.make_dial(
|
||||||
|
SWAP_X,
|
||||||
|
y + DIAL_RADIUS,
|
||||||
|
DIAL_RADIUS,
|
||||||
|
DIAL_THICKNESS,
|
||||||
|
80,
|
||||||
|
format_percent,
|
||||||
|
__math_floor
|
||||||
|
)
|
||||||
|
local update_swap = function()
|
||||||
|
local w = mod_state.swap
|
||||||
|
common.dial_set(swap, (w.total - w.free) / w.total * 100)
|
||||||
|
end
|
||||||
|
local static_swap = pure.partial(common.dial_draw_static, swap)
|
||||||
|
local dynamic_swap = pure.partial(common.dial_draw_dynamic, swap)
|
||||||
|
return ret(
|
||||||
|
pure.sequence(update_mem, update_swap),
|
||||||
|
pure.sequence(static_mem, static_swap),
|
||||||
|
pure.sequence(dynamic_mem, dynamic_swap)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
return ret(update_mem, static_mem, dynamic_mem)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue