Class: CPU::Processor
Instance Attribute Summary collapse
-
#core_id ⇒ Object
readonly
Returns the core_id of this Processor.
-
#processor_id ⇒ Object
readonly
Returns the processor_id of this Processor, an integer in (0..(n - 1)) for a n-core machine.
-
#temperature ⇒ Object
Returns the core temperature of this Processor as an integer number.
-
#usage(interval = 1, &block) ⇒ Object
Measure CPU usage for this Processor instance during the next
interval
or during the runtime of the given block.
Attributes included from Shared
Instance Method Summary collapse
-
#initialize(processor_id, core_id = nil) ⇒ Processor
constructor
Returns a Processor instance for Processor
processor_id
. - #inspect ⇒ Object
-
#msr ⇒ Object
Returns an msr object and caches it.
-
#t_j_max ⇒ Object
This method returns the t_j_max temperature of this Processor if the processor supports it (e. g. Intel i7 architecture) as an integer number, otherwise 0 is returned.
-
#t_j_max_distance ⇒ Object
Returns the distance between the core temperature of this Processor and its t_j_max temperature as an integer number.
Constructor Details
#initialize(processor_id, core_id = nil) ⇒ Processor
Returns a Processor instance for Processor processor_id
. If this Processor doesn’t exist an InvalidProcessorIdError exception is thrown.
7 8 9 |
# File 'lib/cpu/processor.rb', line 7 def initialize(processor_id, core_id = nil) @processor_id, @core_id = processor_id, core_id end |
Instance Attribute Details
#core_id ⇒ Object (readonly)
Returns the core_id of this Processor.
16 17 18 |
# File 'lib/cpu/processor.rb', line 16 def core_id @core_id end |
#processor_id ⇒ Object (readonly)
Returns the processor_id of this Processor, an integer in (0..(n - 1)) for a n-core machine.
13 14 15 |
# File 'lib/cpu/processor.rb', line 13 def processor_id @processor_id end |
#temperature ⇒ Object
Returns the core temperature of this Processor as an integer number. This should work on all Core2 architecures if you set CPU.t_j_max to the correct value for your Processor. On i7 architectures (and newer?) it should work without any further configuration.
58 59 60 61 62 63 64 65 |
# File 'lib/cpu/processor.rb', line 58 def temperature if @temperature @temperature else my_t_j_max = t_j_max.nonzero? || CPU.t_j_max my_t_j_max - t_j_max_distance end end |
#usage(interval = 1, &block) ⇒ Object
Measure CPU usage for this Processor instance during the next interval
or during the runtime of the given block. Іf CPU usage on all processors of the system should be measured, it’s better (=faster) to use the CPU.usage method instead.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cpu/processor.rb', line 29 def usage(interval = 1, &block) unless @usage if processor = CPU.usage(interval, &block).find { |p| p.processor_id == processor_id } then @usage = processor.usage end end @usage end |
Instance Method Details
#inspect ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/cpu/processor.rb', line 69 def inspect if processor_id >= 0 result = "#<#{self.class}: #@processor_id" result << " (core#@core_id)" if @core_id result << '>' else "#<#{self.class}: total>" end end |
#msr ⇒ Object
Returns an msr object and caches it.
19 20 21 |
# File 'lib/cpu/processor.rb', line 19 def msr @msr ||= MSR.new(processor_id) end |
#t_j_max ⇒ Object
This method returns the t_j_max temperature of this Processor if the processor supports it (e. g. Intel i7 architecture) as an integer number, otherwise 0 is returned.
50 51 52 |
# File 'lib/cpu/processor.rb', line 50 def t_j_max (msr[0x1a2] >> 16) & 0x7f end |
#t_j_max_distance ⇒ Object
Returns the distance between the core temperature of this Processor and its t_j_max temperature as an integer number.
43 44 45 |
# File 'lib/cpu/processor.rb', line 43 def t_j_max_distance (msr[0x19c] >> 16) & 0x7f end |