Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find CPU frequencies #552

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion widget/cpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local function factory(args)
for index,time in pairs(helpers.lines_match("cpu","/proc/stat")) do
local coreid = index - 1
local core = cpu.core[coreid] or
{ last_active = 0 , last_total = 0, usage = 0 }
{ last_active = 0 , last_total = 0, usage = 0, frequency = 0 }
local at = 1
local idle = 0
local total = 0
Expand Down Expand Up @@ -60,8 +60,21 @@ local function factory(args)
end
end

-- Read the frequency at which the CPUs are operating
-- This info is found in /proc/cpuinfo
local freq_sum = 0
local cpu_count = 0
for coreid,line in pairs(helpers.lines_match("cpu MHz", "/proc/cpuinfo")) do
local frequency = tonumber(string.match(line, "%d+%.%d+"))
cpu.core[coreid].frequency = frequency
freq_sum = freq_sum + frequency
cpu_count = cpu_count + 1
end
cpu.core[0].frequency = freq_sum / cpu_count -- coreid 0 is for average

cpu_now = cpu.core
cpu_now.usage = cpu_now[0].usage
cpu_now.frequency = cpu_now[0].frequency
widget = cpu.widget

settings()
Expand Down