Method: God::System::SlashProcPoller#percent_cpu

Defined in:
lib/god/system/slash_proc_poller.rb

#percent_cpuObject

TODO: Change this to calculate the wma instead



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/god/system/slash_proc_poller.rb', line 45

def percent_cpu
  stats = stat
  total_time = stats[:utime].to_i + stats[:stime].to_i # in jiffies
  seconds = uptime - stats[:starttime].to_i / @@hertz
  if seconds == 0
    0
  else
    ((total_time * 1000 / @@hertz) / seconds) / 10
  end
rescue # This shouldn't fail is there's an error (or proc doesn't exist)
  0
end