| 1 | -- CPU information widget type for GNU/Linux |
| 2 | -- Copyright (C) 2010 Adrian C. <[email protected]> |
| 3 | -- Copyright (C) 2017 mutlusun <[email protected]> |
| 4 | -- |
| 5 | -- This file is part of Vicious. |
| 6 | -- |
| 7 | -- Vicious is free software: you can redistribute it and/or modify |
| 8 | -- it under the terms of the GNU General Public License as |
| 9 | -- published by the Free Software Foundation, either version 2 of the |
| 10 | -- License, or (at your option) any later version. |
| 11 | -- |
| 12 | -- Vicious is distributed in the hope that it will be useful, |
| 13 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | -- GNU General Public License for more details. |
| 16 | -- |
| 17 | -- You should have received a copy of the GNU General Public License |
| 18 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 19 | |
| 20 | -- {{{ Grab environment |
| 21 | local tonumber = tonumber |
| 22 | local io = { lines = io.lines } |
| 23 | local string = { gmatch = string.gmatch } |
| 24 | local helpers = require"vicious.helpers" |
| 25 | -- }}} |
| 26 | |
| 27 | -- {{{ CPU Information widget type |
| 28 | return helpers.setcall(function () |
| 29 | local id = nil |
| 30 | |
| 31 | local cpu_info = {} -- Get CPU info |
| 32 | for line in io.lines("/proc/cpuinfo") do |
| 33 | for k, v in string.gmatch(line, "([%a%s]+)[%s]+:[%s]([%d]+).-$") do |
| 34 | if k == "processor" then |
| 35 | id = v |
| 36 | elseif k == "cpu MHz\t" or k == "cpu MHz" then |
| 37 | local speed = tonumber(v) |
| 38 | cpu_info["{cpu"..id.." mhz}"] = speed |
| 39 | cpu_info["{cpu"..id.." ghz}"] = speed / 1000 |
| 40 | elseif k == "cache size" then |
| 41 | local cache = tonumber(v) |
| 42 | cpu_info["{cpu"..id.." kb}"] = cache |
| 43 | cpu_info["{cpu"..id.." mb}"] = cache / 1024 |
| 44 | end |
| 45 | end |
| 46 | end |
| 47 | |
| 48 | return cpu_info |
| 49 | end) |
| 50 | -- }}} |