2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
2009-08-06 18:18:45 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local tonumber = tonumber
|
2010-03-13 02:11:41 +01:00
|
|
|
local io = { lines = io.lines }
|
2009-08-06 18:18:45 +02:00
|
|
|
local setmetatable = setmetatable
|
2010-03-13 03:24:37 +01:00
|
|
|
local string = { gmatch = string.gmatch }
|
2009-08-06 18:18:45 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Cpuinf: provides speed and cache information for all available CPUs/cores
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.cpuinf
|
|
|
|
local cpuinf = {}
|
2009-08-06 18:18:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- {{{ CPU Information widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format)
|
2010-03-13 03:24:37 +01:00
|
|
|
local id = nil
|
2009-08-06 18:18:45 +02:00
|
|
|
|
2010-03-15 17:55:25 +01:00
|
|
|
local cpu_info = {} -- Get CPU info
|
2010-03-13 02:11:41 +01:00
|
|
|
for line in io.lines("/proc/cpuinfo") do
|
2010-03-13 03:24:37 +01:00
|
|
|
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
|
2009-08-06 18:18:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return cpu_info
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2012-06-15 18:07:05 +02:00
|
|
|
return setmetatable(cpuinf, { __call = function(_, ...) return worker(...) end })
|