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")
12 local gmatch = string.gmatch
13 local lines = io.lines
14 local floor = math.floor
15 local setmetatable = setmetatable
17 -- Memory usage (ignoring caches)
19 local mem = helpers.make_widget_textbox()
21 local function worker(args)
22 local args = args or {}
23 local timeout = args.timeout or 2
24 local settings = args.settings or function() end
28 for line in lines("/proc/meminfo") do
29 for k, v in gmatch(line, "([%a]+):[%s]+([%d]+).+") do
30 if k == "MemTotal" then mem_now.total = floor(v / 1024 + 0.5)
31 elseif k == "MemFree" then mem_now.free = floor(v / 1024 + 0.5)
32 elseif k == "Buffers" then mem_now.buf = floor(v / 1024 + 0.5)
33 elseif k == "Cached" then mem_now.cache = floor(v / 1024 + 0.5)
34 elseif k == "SwapTotal" then mem_now.swap = floor(v / 1024 + 0.5)
35 elseif k == "SwapFree" then mem_now.swapf = floor(v / 1024 + 0.5)
36 elseif k == "SReclaimable" then mem_now.srec = floor(v / 1024 + 0.5)
41 mem_now.used = mem_now.total - mem_now.free - mem_now.buf - mem_now.cache - mem_now.srec
42 mem_now.swapused = mem_now.swap - mem_now.swapf
43 mem_now.perc = math.floor(mem_now.used / mem_now.total * 100)
49 helpers.newtimer("mem", timeout, update)
54 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })