Module: RbBCC::CPUHelper
- Included in:
- TableBase
- Defined in:
- lib/rbbcc/cpu_helper.rb
Class Method Summary collapse
-
._read_cpu_range(path) ⇒ Object
formatted like: ‘0,2-4,7-10’.
- .get_online_cpus ⇒ Object
- .get_possible_cpus ⇒ Object
Class Method Details
._read_cpu_range(path) ⇒ Object
formatted like: ‘0,2-4,7-10’
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbbcc/cpu_helper.rb', line 13 def _read_cpu_range(path) cpus = nil File.open(path, 'r') do |f| tmp = f.read.split(',').map do |range| if range.include?('-') start, end_ = *range.split('-') (start.to_i..end_.to_i).to_a else range.to_i end end cpus = tmp.flatten end cpus end |
.get_online_cpus ⇒ Object
4 5 6 |
# File 'lib/rbbcc/cpu_helper.rb', line 4 def get_online_cpus return _read_cpu_range('/sys/devices/system/cpu/online') end |
.get_possible_cpus ⇒ Object
8 9 10 |
# File 'lib/rbbcc/cpu_helper.rb', line 8 def get_possible_cpus return _read_cpu_range('/sys/devices/system/cpu/possible') end |