module Celluloid::CPUCounter - celluloid-0.16.0 Documentation

# module Celluloid::CPUCounter

### Public Class Methods

cores() click to toggle source

    # File lib/celluloid/cpu_counter.rb, line 4
    def cores
      @cores ||= count_cores
    end

### Private Class Methods

count_cores() click to toggle source

    # File lib/celluloid/cpu_counter.rb, line 10
    def count_cores
      result = from_env || from_sysdev || from_sysctl
      Integer(result.to_s[/\d+/], 10) if result
    end

from_env() click to toggle source

    # File lib/celluloid/cpu_counter.rb, line 15
    def from_env
      result = ENV['NUMBER_OF_PROCESSORS']
      result if result
    end

from_sysctl() click to toggle source

    # File lib/celluloid/cpu_counter.rb, line 27
    def from_sysctl
      result = %x`sysctl -n hw.ncpu`
      result if $?.success?
    rescue Errno::ENOENT
    end

from_sysdev() click to toggle source

    # File lib/celluloid/cpu_counter.rb, line 20
    def from_sysdev
      ::IO.read('/sys/devices/system/cpu/present').split('-').last.to_i + 1
    rescue Errno::ENOENT
      result = Dir['/sys/devices/system/cpu/cpu*'].count { |n| n =~ /cpu\d+/ }
      result unless result.zero?
    end