lib/cpu.rb in cpu-0.0.1 vs lib/cpu.rb in cpu-0.0.2
- old
+ new
@@ -3,10 +3,11 @@
require 'cpu/processor'
require 'cpu/msr'
require 'cpu/load'
require 'cpu/usage_sampler'
require 'cpu/usage'
+require 'cpu/version'
# This module provides (read) access to the Model Specific Registers of Intel
# CPUs on Linux.
module CPU
class << self
@@ -119,10 +120,14 @@
# sum up the CPU usage in this instance.
def sum_usage_processor(interval = 1, &block)
processors = usage(interval, &block)
processor = Processor.new -1, -1
processor.num_processors = processor.num_cores = 1
- processor.temperature = processors.map(&:temperature).max
+ begin
+ processor.temperature = processors.map(&:temperature).max
+ rescue NoSampleDataError
+ processor.temperature = nil
+ end
processor.usage = processors.map(&:usage).inject { |s, u| s + u }
processor.usage.num_processors = processor.usage.num_cores = 1
processor.freeze
processor
end