/usr/lib/ruby/vendor_ruby/celluloid/cpu_counter.rb is in ruby-celluloid 0.16.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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
|