Sha256: 44d267f52694b1e1b05a3903a57369a00159e664df6c5e85e4a3fca10ecb2b85

Contents?: true

Size: 765 Bytes

Versions: 6

Compression:

Stored size: 765 Bytes

Contents

module Celluloid
  module CPUCounter
    class << self
      def cores
        @cores ||= count_cores
      end

      private

      def count_cores
        result = from_env || from_sysdev || from_sysctl
        Integer(result.to_s[/\d+/], 10) if result
      end

      def from_env
        result = ENV['NUMBER_OF_PROCESSORS']
        result if result
      end

      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

      def from_sysctl
        result = `sysctl -n hw.ncpu`
        result if $?.success?
      rescue Errno::ENOENT
      end
    end
  end
end

Version data entries

6 entries across 4 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/lib/celluloid/cpu_counter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/cpu_counter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cpu_counter.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cpu_counter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/lib/celluloid/cpu_counter.rb
celluloid-0.16.0 lib/celluloid/cpu_counter.rb