struct Hardware::CPU

Overview

CPU related informations of your system.

cpu = Hardware::CPU.new
loop do
  sleep 1
  cpu.used.to_i # => 17
end

Defined in:

hardware/cpu.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

Creates a new Hardware::CPU based on the current memory state.


[View source]

Class Method Detail

def self.previous_info : NamedTuple(used: Int32, idle: Int32, total: Int32) #

Returns the previous used, idle and total CPU time. Used to store the previous CPU time informations to calculate the percentage in.used.


[View source]
def self.previous_info=(previous_info : NamedTuple(used: Int32, idle: Int32, total: Int32)) #

Returns the previous used, idle and total CPU time. Used to store the previous CPU time informations to calculate the percentage in.used.


[View source]

Instance Method Detail

def guest : Int32 #

Returns the "guest" field of #stat.


[View source]
def guest_nice : Int32 #

Returns the "guest_nice" field of #stat.


[View source]
def idle : Int32 #

Returns the "idle" field of #stat.


[View source]
def info : NamedTuple(used: Int32, idle: Int32, total: Int32) #

Returns the current used, idle and total CPU time.


[View source]
def iowait : Int32 #

Returns the "iowait" field of #stat.


[View source]
def irq : Int32 #

Returns the "irq" field of #stat.


[View source]
def nice : Int32 #

Returns the "nice" field of #stat.


[View source]
def softirq : Int32 #

Returns the "softirq" field of #stat.


[View source]
def stat : Array(Int32) #

Returns a parsed /proc/stat.


[View source]
def steal : Int32 #

Returns the "steal" field of #stat.


[View source]
def system : Int32 #

Returns the "system" field of #stat.


[View source]
def used(update = true) : Float32 #

Returns the CPU used in percentage based on .previous_info.


[View source]
def user : Int32 #

Returns the "user" field of #stat.


[View source]