1
1
Fork 0
mirror of https://github.com/vicious-widgets/vicious synced 2023-12-14 07:13:07 +01:00
vicious/widgets/cpuinf.lua
Arvydas Sidorenko 41cc2c0e27 Ported vicious.widgets module to lua 5.2
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
2012-06-18 01:26:31 +02:00

44 lines
1.3 KiB
Lua

---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { lines = io.lines }
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
-- }}}
-- Cpuinf: provides speed and cache information for all available CPUs/cores
-- vicious.widgets.cpuinf
local cpuinf = {}
-- {{{ CPU Information widget type
local function worker(format)
local id = nil
local cpu_info = {} -- Get CPU info
for line in io.lines("/proc/cpuinfo") do
for k, v in string.gmatch(line, "([%a%s]+)[%s]+:[%s]([%d]+).-$") do
if k == "processor" then
id = v
elseif k == "cpu MHz\t" or k == "cpu MHz" then
local speed = tonumber(v)
cpu_info["{cpu"..id.." mhz}"] = speed
cpu_info["{cpu"..id.." ghz}"] = speed / 1000
elseif k == "cache size" then
local cache = tonumber(v)
cpu_info["{cpu"..id.." kb}"] = cache
cpu_info["{cpu"..id.." mb}"] = cache / 1024
end
end
end
return cpu_info
end
-- }}}
return setmetatable(cpuinf, { __call = function(_, ...) return worker(...) end })