vicious/widgets/cpuinf_linux.lua

57 lines
1.9 KiB
Lua
Raw Normal View History

-- CPU information widget type for GNU/Linux
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
--
-- This file is part of Vicious.
--
-- Vicious is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as
-- published by the Free Software Foundation, either version 2 of the
-- License, or (at your option) any later version.
--
-- Vicious is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
-- {{{ Grab environment
local tonumber = tonumber
local io = { lines = io.lines }
2010-03-13 03:24:37 +01:00
local string = { gmatch = string.gmatch }
local helpers = require"vicious.helpers"
-- }}}
-- Cpuinf: provides speed and cache information for all available CPUs/cores
-- vicious.widgets.cpuinf
2017-01-25 17:49:57 +01:00
local cpuinf_linux = {}
-- {{{ 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
local cpu_info = {} -- Get CPU info
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
end
end
return cpu_info
end
-- }}}
return helpers.setcall(cpuinf_linux, worker)