2019-09-05 07:41:38 +02:00
|
|
|
-- 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/>.
|
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 }
|
2010-03-13 03:24:37 +01:00
|
|
|
local string = { gmatch = string.gmatch }
|
2019-09-05 07:41:38 +02:00
|
|
|
local helpers = require"vicious.helpers"
|
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
|
2017-01-25 17:49:57 +01:00
|
|
|
local cpuinf_linux = {}
|
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
|
|
|
|
-- }}}
|
|
|
|
|
2019-09-05 07:41:38 +02:00
|
|
|
return helpers.setcall(cpuinf_linux, worker)
|