All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
10 local helpers = require("lain.helpers")
11 local wibox = require("wibox")
13 local io = { lines = io.lines }
14 local math = { floor = math.floor }
15 local string = { gmatch = string.gmatch }
17 local setmetatable = setmetatable
23 local function worker(args)
24 local args = args or {}
25 local timeout = args.timeout or 1
26 local settings = args.settings or function() end
28 mem.widget = wibox.widget.textbox('')
30 helpers.set_map("mem_last_total", 0)
31 helpers.set_map("mem_last_free", 0)
32 helpers.set_map("mem_last_buf", 0)
33 helpers.set_map("mem_last_cache", 0)
34 helpers.set_map("mem_last_swap", 0)
35 helpers.set_map("mem_last_swapf", 0)
39 for line in io.lines("/proc/meminfo")
41 for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+")
43 if k == "MemTotal" then mem_now.total = math.floor(v / 1024)
44 elseif k == "MemFree" then mem_now.free = math.floor(v / 1024)
45 elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024)
46 elseif k == "Cached" then mem_now.cache = math.floor(v / 1024)
47 elseif k == "SwapTotal" then mem_now.swap = math.floor(v / 1024)
48 elseif k == "SwapFree" then mem_now.swapf = math.floor(v / 1024)
53 if mem_now.total ~= helpers.set_map("mem_last_total")
54 or mem_now.free ~= helpers.set_map("mem_last_free")
55 or mem_now.buf ~= helpers.set_map("mem_last_buf")
56 or mem_now.cache ~= helpers.set_map("mem_last_cache")
57 or mem_now.swap ~= helpers.set_map("mem_last_swap")
58 or mem_now.swapf ~= helpers.set_map("mem_last_swapf")
60 mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
61 mem_now.swapused = mem_now.swap - mem_now.swapf
66 helpers.set_map("mem_last_total", mem_now.total)
67 helpers.set_map("mem_last_free", mem_now.free)
68 helpers.set_map("mem_last_buf", mem_now.buf)
69 helpers.set_map("mem_last_cache", mem_now.cache)
70 helpers.set_map("mem_last_swap", mem_now.swap)
71 helpers.set_map("mem_last_swapf", mem_now.swapf)
75 helpers.newtimer("mem", timeout, update)
80 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })