Class: System::CPU

Inherits:
Object
  • Object
show all
Defined in:
lib/system/cpu.rb

Overview

Information about the current CPU(s) running on the current system.

Since:

  • 0.1.1

Class Method Summary collapse

Class Method Details

.countInteger

The CPU count of the system, including individual CPU cores.

Returns:

  • (Integer)

    Count of CPU cores.

Since:

  • 0.1.1



14
15
16
17
18
19
20
21
# File 'lib/system/cpu.rb', line 14

def count
  return Java::Java.lang.Runtime.getRuntime.availableProcessors if System::Ruby.java? # defined? Java::Java
  return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist?('/proc/cpuinfo')
  require 'win32ole'
  WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
  Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
end