Module: Host::Linux::Processor

Includes:
Hashifier
Defined in:
lib/host/linux/processor.rb

Overview

Implements the gathering of processor information on a Linux system.

Instance Method Summary collapse

Methods included from Hashifier

#hashify

Instance Method Details

#core(id) ⇒ Object

returns an object containing the information of the core with the given id (as in /proc/cpuinfo for example). You can then get specific data on the returned object.

Example:

p = Host::Processor.core(1)
p.model_name #=> "GenuineIntel"


23
24
25
26
# File 'lib/host/linux/processor.rb', line 23

def core(id)
  @current_core = @info[id]
  self
end

#coresObject

Returns the number of cores identified on the system



12
13
14
# File 'lib/host/linux/processor.rb', line 12

def cores
  @info.size
end

#each_coreObject

Lets you iterate over the processor cores and get specific information. Similar to iterate on cores, using Host::Processor.core



30
31
32
33
34
35
# File 'lib/host/linux/processor.rb', line 30

def each_core
  @info.each { |processor|
    @current_core = processor
    yield self
  }
end

#flagsObject

Returns an array of flags for the processor



42
43
44
45
46
47
48
# File 'lib/host/linux/processor.rb', line 42

def flags
  if @current_core && @current_core.has_key?(:flags)
    @current_core[:flags].split
  else
    []
  end
end

#get(key) ⇒ Object

Retrieves a specific data stored on /proc/cpuinfo for the given key.



52
53
54
# File 'lib/host/linux/processor.rb', line 52

def get(key)
  @current_core && @current_core[key.to_sym]
end

#model_nameObject



37
38
39
# File 'lib/host/linux/processor.rb', line 37

def model_name
  @current_core && @current_core[:model_name]
end

#refreshObject

Refreshes your processor information, reading from /proc/cpuinfo once again



58
59
60
61
# File 'lib/host/linux/processor.rb', line 58

def refresh
  get_cpuinfo(true)
  self
end