-
-
Notifications
You must be signed in to change notification settings - Fork 6
Home
The sys-cpu library provides an interface for gathering information about your system's CPU.
require 'sys/cpu' include Sys puts CPU.architecture # CPU architecture, e.g. "i386". puts CPU.freq # CPU frequency. puts CPU.load_avg # Array containing load average for 1, 5 and 15 minute periods. puts CPU.model # CPU model. puts CPU.machine # CPU class. May be identical to architecture. puts CPU.num_cpu # Number of CPU's (cores).
puts CPU.state(0) # The state of CPU 0 (the default if no arg is provided). puts CPU.cpu_type # The CPU architecture. puts CPU.fpu_type # The type of floating point unit, if any.
The CPU.architecture and CPU.machine methods are not supported on Solaris.
puts CPU.num_active_cpu # The number of active processors on the system.
The CPU.model and CPU.machine methods are not supported on HP-UX.
The CPU.freq method is not supported on OS X.
Also, the CPU.model method doesn't seem to necessarily refer to the model of the CPU so much as the overall hardware model.
The Windows version of this library supports the standard CPU methods and adds the CPU.type and CPU.processors methods. The CPU.type methods merely returns the CPU type (brand), while CPU.processors yields a struct containing more detailed information, derived from the Win32_Processor WMI class, than the standard methods do.
puts CPU.type # CPU brand/type. CPU.processors{ |cpu| p cpu } # Display full information for each processor.
The methods available on Linux are mostly derived from the available information in /proc/cpuinfo. Below is some sample code to see all available information. The Linux version also adds the CPU.cpu_stats method.
p CPU.cpu_stats CPU.processors{ |cs| cs.members.each{ |m| puts "#{m}: " + cs[m].to_s } }