Sha256: 09865b10a30c1eb1e7e56c247aa5ad8eefe13d28b06081c97d22bbbdb1f3b73d

Contents?: true

Size: 748 Bytes

Versions: 2

Compression:

Stored size: 748 Bytes

Contents

module ScoutRailsProxy::Instruments
  module Process
    class ProcessCpu
      def initialize(num_processors)
        @num_processors = num_processors || 1
      end

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
scout_rails_proxy-1.0.6 lib/scout_rails_proxy/instruments/process/process_cpu.rb
scout_rails_proxy_proxy-1.0.5 lib/scout_rails_proxy/instruments/process/process_cpu.rb