Sha256: 6876d32905a5d860ae5dc7540798b9eb1bec13433fe2608fd1e403a75c4febfd

Contents?: true

Size: 622 Bytes

Versions: 4

Compression:

Stored size: 622 Bytes

Contents

module Salus
  class CPU
    def self.count
      @count ||= self.get_count
    end

    private
    def self.get_count
      return Java::Java.lang.Runtime.getRuntime.availableProcessors if RUBY_PLATFORM == "java"
      return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist?('/proc/cpuinfo')
      require 'win32ole'
      WIN32OLE.connect("winmgmts://").ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
        .to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
    rescue LoadError
      Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
salus-0.2.1 lib/salus/thread/cpu.rb
salus-0.2.0 lib/salus/thread/cpu.rb
salus-0.1.3 lib/salus/thread/cpu.rb
salus-0.1.2 lib/salus/thread/cpu.rb