Class: Snapshot::CPUInspector

Inherits:
Object
  • Object
show all
Defined in:
snapshot/lib/snapshot/simulator_launchers/simulator_launcher.rb

Class Method Summary collapse

Class Method Details

.cpu_countObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher.rb', line 10

def self.cpu_count
  @cpu_count ||=
    case RUBY_PLATFORM
    when /darwin9/
      `hwprefs cpu_count`.to_i
    when /darwin10/
      (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.physicalcpu_max`).to_i
    when /linux/
      UI.user_error!("We detected that you are running snapshot on Linux, but snapshot is only supported on macOS")
    when /freebsd/
      UI.user_error!("We detected that you are running snapshot on FreeBSD, but snapshot is only supported on macOS")
    else
      if RbConfig::CONFIG['host_os'] =~ /darwin/
        (hwprefs_available? ? `hwprefs thread_count` : `sysctl -n hw.physicalcpu_max`).to_i
      else
        UI.crash!("Cannot find the machine's processor count.")
      end
    end
end

.hwprefs_available?Boolean

Returns:



6
7
8
# File 'snapshot/lib/snapshot/simulator_launchers/simulator_launcher.rb', line 6

def self.hwprefs_available?
  `which hwprefs` != ''
end