Sha256: 966a9486fc92ecef9cbf53e1dc37798421cbe981f9f079fd88436d25ee47304e

Contents?: true

Size: 1014 Bytes

Versions: 22

Compression:

Stored size: 1014 Bytes

Contents

#This class can manipulate the CPU behavior through "cpufreq".
class Knj::Cpufreq
  attr_reader :data
  
  def initialize(data)
    @data = data
    @allowed_govs = ["performance", "ondemand", "powersafe", "conservative"]
  end
  
  def self.list
    ret = []
    cont = File.read("/proc/cpuinfo")
    
    matches = cont.scan(/processor\s*:[\s\S]+?\n\n/)
    raise "Could not detect CPUs" if !matches or matches.empty?
    
    matches.each do |cpucont|
      cpu_features = {}
      features = cpucont.scan(/(.+)\s*:\s*(.+)\s*/)
      
      features.each do |data|
        cpu_features[data[0].strip] = data[1].strip
      end
      
      ret << Knj::Cpufreq.new(cpu_features)
    end
    
    return ret
  end
  
  def governor=(newgov)
    raise "Governor not found." if @allowed_govs.index(newgov) == nil
    
    cmd = "cpufreq-set --cpu #{@data["processor"]} --governor #{newgov}"
    res = Knj::Os::shellcmd(cmd)
    if res.index("Error setting new values") != nil
      raise res.strip
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
knjrbfw-0.0.30 lib/knj/cpufreq.rb
knjrbfw-0.0.29 lib/knj/cpufreq.rb
knjrbfw-0.0.28 lib/knj/cpufreq.rb
knjrbfw-0.0.27 lib/knj/cpufreq.rb
knjrbfw-0.0.26 lib/knj/cpufreq.rb
knjrbfw-0.0.25 lib/knj/cpufreq.rb
knjrbfw-0.0.24 lib/knj/cpufreq.rb
knjrbfw-0.0.23 lib/knj/cpufreq.rb
knjrbfw-0.0.22 lib/knj/cpufreq.rb
knjrbfw-0.0.21 lib/knj/cpufreq.rb
knjrbfw-0.0.20 lib/knj/cpufreq.rb
knjrbfw-0.0.19 lib/knj/cpufreq.rb
knjrbfw-0.0.18 lib/knj/cpufreq.rb
knjrbfw-0.0.17 lib/knj/cpufreq.rb
knjrbfw-0.0.16 lib/knj/cpufreq.rb
knjrbfw-0.0.15 lib/knj/cpufreq.rb
knjrbfw-0.0.14 lib/knj/cpufreq.rb
knjrbfw-0.0.13 lib/knj/cpufreq.rb
knjrbfw-0.0.12 lib/knj/cpufreq.rb
knjrbfw-0.0.11 lib/knj/cpufreq.rb