Class: ScoutRailsProxy::Instruments::Process::ProcessCpu
- Inherits:
-
Object
- Object
- ScoutRailsProxy::Instruments::Process::ProcessCpu
- Defined in:
- lib/scout_rails_proxy/instruments/process/process_cpu.rb
Instance Method Summary collapse
-
#initialize(num_processors) ⇒ ProcessCpu
constructor
A new instance of ProcessCpu.
- #run ⇒ Object
Constructor Details
#initialize(num_processors) ⇒ ProcessCpu
Returns a new instance of ProcessCpu.
4 5 6 |
# File 'lib/scout_rails_proxy/instruments/process/process_cpu.rb', line 4 def initialize(num_processors) @num_processors = num_processors || 1 end |
Instance Method Details
#run ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/scout_rails_proxy/instruments/process/process_cpu.rb', line 8 def run res=nil now = Time.now t = ::Process.times if @last_run elapsed_time = now - @last_run if elapsed_time >= 1 user_time_since_last_sample = t.utime - @last_utime system_time_since_last_sample = t.stime - @last_stime res = ((user_time_since_last_sample + system_time_since_last_sample)/(elapsed_time * @num_processors))*100 end end @last_utime = t.utime @last_stime = t.stime @last_run = now return res end |