Class: Nitra::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/nitra/utils.rb

Class Method Summary collapse

Class Method Details

.capture_outputObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nitra/utils.rb', line 22

def self.capture_output
  old_stdout = $stdout
  old_stderr = $stderr
  $stdout = $stderr = io = StringIO.new
  begin
    yield
  ensure
    $stdout = old_stdout
    $stderr = old_stderr
  end
  io.string
end

.processor_countObject

The following taken and modified from the ‘parallel’ gem. Licensed under the MIT licence, copyright Michael Grosser.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nitra/utils.rb', line 7

def self.processor_count
  @processor_count ||= case `uname`
  when /darwin/i
    (`which hwprefs` != '' ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
  when /linux/i
    `grep -c processor /proc/cpuinfo`.to_i
  when /freebsd/i
    `sysctl -n hw.ncpu`.to_i
  when /solaris2/i
    `psrinfo -p`.to_i # this is physical cpus afaik
  else
    1
  end
end