cpu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 2011-07-04 (0.0.2)
2
+ * Raise NoSampleDataError if temperature couldn't be read, also catch it in
3
+ sum_processor_usage method.
1
4
  2011-07-03 (0.0.1)
2
5
  * Add documentation and license information.
3
6
  2011-07-03 (0.0.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/cpu.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cpu}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [%q{Florian Frank}]
9
- s.date = %q{2011-07-03}
9
+ s.date = %q{2011-07-04}
10
10
  s.description = %q{Library to gather CPU information (load averages, usage, temperature) in Ruby on Linux}
11
11
  s.email = %q{flori@ping.de}
12
12
  s.executables = [%q{coretemp}]
data/lib/cpu.rb CHANGED
@@ -5,6 +5,7 @@ require 'cpu/msr'
5
5
  require 'cpu/load'
6
6
  require 'cpu/usage_sampler'
7
7
  require 'cpu/usage'
8
+ require 'cpu/version'
8
9
 
9
10
  # This module provides (read) access to the Model Specific Registers of Intel
10
11
  # CPUs on Linux.
@@ -121,7 +122,11 @@ module CPU
121
122
  processors = usage(interval, &block)
122
123
  processor = Processor.new -1, -1
123
124
  processor.num_processors = processor.num_cores = 1
124
- processor.temperature = processors.map(&:temperature).max
125
+ begin
126
+ processor.temperature = processors.map(&:temperature).max
127
+ rescue NoSampleDataError
128
+ processor.temperature = nil
129
+ end
125
130
  processor.usage = processors.map(&:usage).inject { |s, u| s + u }
126
131
  processor.usage.num_processors = processor.usage.num_cores = 1
127
132
  processor.freeze
data/lib/cpu/msr.rb CHANGED
@@ -17,9 +17,12 @@ module CPU
17
17
  def initialize(processor_id)
18
18
  self.class.available? or self.class.load_module
19
19
  begin
20
- @io = IO.new IO.sysopen('/dev/cpu/%d/msr' % processor_id, 'rb')
20
+ name = '/dev/cpu/%d/msr' % processor_id
21
+ @io = IO.new IO.sysopen(name, 'rb')
21
22
  rescue Errno::ENOENT
22
23
  raise InvalidProcessorIdError, "'#{processor_id}' is not a valid processor_id on this machine"
24
+ rescue StandardError => e
25
+ raise NoSampleDataError, "could not read temperature from #{name}: #{e}"
23
26
  end
24
27
  end
25
28
 
data/lib/cpu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module CPU
2
2
  # CPU version
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Florian Frank
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-03 00:00:00 Z
18
+ date: 2011-07-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: spruz