2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2009-11-04 23:39:38 +01:00
|
|
|
-- * (c) 2009, 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
|
|
|
|
local io = { open = io.open }
|
|
|
|
local setmetatable = setmetatable
|
2009-10-05 00:10:47 +02:00
|
|
|
local string = { match = string.match }
|
2009-08-06 18:18:45 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Cpuinf: provides speed and cache information for all available CPUs/cores
|
|
|
|
module("vicious.cpuinf")
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ CPU Information widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format)
|
2009-08-06 18:18:45 +02:00
|
|
|
-- Get cpuinfo
|
|
|
|
local f = io.open("/proc/cpuinfo")
|
2009-10-02 23:31:46 +02:00
|
|
|
local cpu_id = nil
|
2009-08-06 18:18:45 +02:00
|
|
|
local cpu_info = {}
|
|
|
|
|
|
|
|
for line in f:lines() do
|
2009-10-05 00:10:47 +02:00
|
|
|
if string.match(line, "^processor.*") then
|
|
|
|
cpu_id = string.match(line, "([%d]+)")
|
|
|
|
elseif string.match(line, "^cpu MHz.*") then
|
2009-10-26 20:32:48 +01:00
|
|
|
local cpu_speed = tonumber(string.match(line, "([%d]+)%."))
|
2009-10-02 23:31:46 +02:00
|
|
|
cpu_info["{cpu"..cpu_id.." mhz}"] = cpu_speed
|
2009-10-26 20:32:48 +01:00
|
|
|
cpu_info["{cpu"..cpu_id.." ghz}"] = cpu_speed / 1000
|
2009-10-05 00:10:47 +02:00
|
|
|
elseif string.match(line, "^cache size.*") then
|
2009-10-26 20:32:48 +01:00
|
|
|
local cpu_cache = tonumber(string.match(line, "([%d]+)[%s]KB"))
|
2009-10-02 23:31:46 +02:00
|
|
|
cpu_info["{cpu"..cpu_id.." kb}"] = cpu_cache
|
2009-10-26 20:32:48 +01:00
|
|
|
cpu_info["{cpu"..cpu_id.." mb}"] = cpu_cache / 1024
|
2009-08-06 18:18:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
return cpu_info
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|