Sha256: b153aaf98ee95a2e67395cb62c26aa0c01282dd7320ed36d42b835df74ac0a15

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

require 'rbconfig'

module Celluloid
  module CPUCounter
    case RbConfig::CONFIG['host_os'][/^[A-Za-z]+/]
    when 'darwin'
      @cores = Integer(`/usr/sbin/sysctl hw.ncpu`[/\d+/])
    when 'linux'
      @cores = if File.exists?("/sys/devices/system/cpu/present")
        File.read("/sys/devices/system/cpu/present").split('-').last.to_i+1
      else
        Dir["/sys/devices/system/cpu/cpu*"].select { |n| n=~/cpu\d+/ }.count
      end
    when 'mingw', 'mswin'
      @cores = Integer(ENV["NUMBER_OF_PROCESSORS"][/\d+/])
    when 'freebsd'
      @cores = Integer(`sysctl hw.ncpu`[/\d+/])
    else
      @cores = nil
    end

    def self.cores; @cores; end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celluloid-0.16.0.pre lib/celluloid/cpu_counter.rb