Sha256: fea6b38c89077f24658d527a299e276bcf5aee5d39392c0f163a6b5f6284c8a8

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

require 'socket'

module Kymera

  def self.processor_count
    @processor_count ||= case RbConfig::CONFIG['host_os']
       when /darwin9/
         `hwprefs cpu_count`.to_i
       when /darwin/
         (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
       when /linux|cygwin/
         `grep -c ^processor /proc/cpuinfo`.to_i
       when /(net|open|free)bsd/
         `sysctl -n hw.ncpu`.to_i
       when /mswin|mingw/
         require 'win32ole'
         wmi = WIN32OLE.connect("winmgmts://")
         cpu = wmi.ExecQuery("select NumberOfLogicalProcessors from Win32_Processor")
         cpu.to_enum.first.NumberOfLogicalProcessors
       when /solaris2/
         `psrinfo -p`.to_i # this is physical cpus afaik
       else
         $stderr.puts "Unknown architecture ( #{RbConfig::CONFIG["host_os"]} ) assuming one processor."
         1
     end
  end

  def self.hwprefs_available?
    avail = true
    begin
      `hwprefs`
    rescue
      avail = false
    end
    avail
  end

  def self.is_linux?
    case RbConfig::CONFIG['host_os']
      when /linux|darwin/
        true
      else
        false
    end

  end

  def self.is_windows?
    case RbConfig::CONFIG['host_os']
      when /mswin|mingw/
        true
      else
        false
    end
  end


  def self.ip_address
    ips = Socket.ip_address_list
    ip = ''
    ips.each do |i|
      ip = i.ip_address if i.ipv4? && i.ip_address.start_with?("10")
    end
    ip
  end



  def self.host_name
    Socket.gethostname
  end

  def self.wait_for(&block)
    found = false
    i = 0
    until i == 60 || found
      found = yield
      sleep 1
      i +=1
    end
    found
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kymera-0.1.7 lib/kymera/platform_utils.rb
kymera-0.1.6 lib/kymera/platform_utils.rb
kymera-0.1.5 lib/kymera/platform_utils.rb
kymera-0.1.4 lib/kymera/platform_utils.rb
kymera-0.1.3 lib/kymera/platform_utils.rb
kymera-0.1.2 lib/kymera/platform_utils.rb