sys-cpu 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -5
- data/{CHANGES → CHANGES.rdoc} +24 -0
- data/Gemfile +7 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.rdoc} +11 -9
- data/README.rdoc +75 -0
- data/Rakefile +5 -7
- data/lib/sys/cpu.rb +1 -1
- data/lib/sys/linux/sys/cpu.rb +32 -0
- data/lib/sys/windows/sys/cpu.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/sys_cpu_bsd_spec.rb +94 -0
- data/spec/sys_cpu_hpux_spec.rb +50 -0
- data/spec/sys_cpu_linux_spec.rb +53 -0
- data/spec/sys_cpu_spec.rb +18 -0
- data/spec/sys_cpu_sunos_spec.rb +80 -0
- data/spec/sys_cpu_windows_spec.rb +61 -0
- data/sys-cpu.gemspec +15 -6
- metadata +62 -49
- metadata.gz.sig +0 -0
- data/README +0 -72
- data/test/test_sys_cpu.rb +0 -23
- data/test/test_sys_cpu_bsd.rb +0 -97
- data/test/test_sys_cpu_hpux.rb +0 -49
- data/test/test_sys_cpu_linux.rb +0 -31
- data/test/test_sys_cpu_sunos.rb +0 -81
- data/test/test_sys_cpu_version.rb +0 -19
- data/test/test_sys_cpu_windows.rb +0 -72
metadata.gz.sig
CHANGED
Binary file
|
data/README
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
= Description
|
2
|
-
A Ruby interface for getting cpu information.
|
3
|
-
|
4
|
-
= Installation
|
5
|
-
gem install sys-cpu
|
6
|
-
|
7
|
-
= Notes
|
8
|
-
== Solaris
|
9
|
-
Currently there is no 'processors()' iterative method for multi-cpu systems.
|
10
|
-
I plan to add it this in a future release.
|
11
|
-
|
12
|
-
== OS X
|
13
|
-
The CPU.model method returns very limited information. I do not yet know
|
14
|
-
how to get more detailed information.
|
15
|
-
|
16
|
-
== Linux
|
17
|
-
This is pure Ruby. This version reads information out of /proc/cpuinfo and
|
18
|
-
/proc/loadavg, so if /proc isn't mounted it won't work.
|
19
|
-
|
20
|
-
The key-value information in /proc/cpuinfo is stored internally (i.e. in
|
21
|
-
memory) as an array of hashes when you first 'require' this package. This
|
22
|
-
overhead is exceptionally minimal, given that your average cpuinfo file
|
23
|
-
contains less than 1k of text (and I don't store whitespace or newlines).
|
24
|
-
|
25
|
-
The text documentation for Linux is dynamically generated during the
|
26
|
-
build process because the fields vary depending on your setup. So, don't
|
27
|
-
look at it until *after* you've installed it. You will see a doc/linux.txt
|
28
|
-
file after you run 'rake install' (via install.rb).
|
29
|
-
|
30
|
-
== HP-UX
|
31
|
-
Unlike other platforms, you can get load averages for an individual cpu in
|
32
|
-
multi-cpu systems. See documentation for more details.
|
33
|
-
|
34
|
-
Note that version 0.7.x and later will not work on HP-UX because of the
|
35
|
-
switch to FFI and the lack of a testing platform. However, version 0.6.x
|
36
|
-
will work just fine.
|
37
|
-
|
38
|
-
== MS Windows
|
39
|
-
This is a pure Ruby implementation using the win32ole package + WMI. The C
|
40
|
-
version has been scrapped.
|
41
|
-
|
42
|
-
As of version 0.5.0, the CPU.usage method has been removed in favor of the
|
43
|
-
CPU.load_avg method. This does not (currently) use a perf counter, so there
|
44
|
-
is no longer any delay. Also, the 'processors' method has been
|
45
|
-
added and the 'supported' method has been dropped. See the documentation
|
46
|
-
for other changes.
|
47
|
-
|
48
|
-
= Acknowledgements
|
49
|
-
Thanks go to the MPlayer team for some source code that helped me on
|
50
|
-
certain versions of FreeBSD in the original C version.
|
51
|
-
|
52
|
-
= Known Bugs
|
53
|
-
None that I'm aware of. Please report bugs on the project page at
|
54
|
-
https://github.com/djberg96/sys-cpu
|
55
|
-
|
56
|
-
= Future Plans
|
57
|
-
Add iterative CPU.processors method.
|
58
|
-
Add more information in general, such as what 'prtdiag' shows.
|
59
|
-
|
60
|
-
= License
|
61
|
-
Artistic 2.0
|
62
|
-
|
63
|
-
= Copyright
|
64
|
-
(C) 2003-2015 Daniel J. Berger, All Rights Reserved
|
65
|
-
|
66
|
-
= Warranty
|
67
|
-
This package is provided "as is" and without any express or
|
68
|
-
implied warranties, including, without limitation, the implied
|
69
|
-
warranties of merchantability and fitness for a particular purpose.
|
70
|
-
|
71
|
-
= Author
|
72
|
-
Daniel J. Berger
|
data/test/test_sys_cpu.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# test_sys_cpu.rb
|
3
|
-
#
|
4
|
-
# This isn't a test file, just a file that require's the appropriate
|
5
|
-
# test file base on the platform you're on.
|
6
|
-
#######################################################################
|
7
|
-
require 'rbconfig'
|
8
|
-
require 'test_sys_cpu_version'
|
9
|
-
|
10
|
-
case RbConfig::CONFIG['host_os']
|
11
|
-
when /bsd|darwin|mach|osx/i
|
12
|
-
require 'test_sys_cpu_bsd'
|
13
|
-
when /hpux/i
|
14
|
-
require 'test_sys_cpu_hpux'
|
15
|
-
when /linux/i
|
16
|
-
require 'test_sys_cpu_linux'
|
17
|
-
when /sunos|solaris/i
|
18
|
-
require 'test_sys_cpu_sunos'
|
19
|
-
when /mswin|win32|dos|mingw|cygwin/i
|
20
|
-
require 'test_sys_cpu_windows'
|
21
|
-
else
|
22
|
-
raise "Platform not supported"
|
23
|
-
end
|
data/test/test_sys_cpu_bsd.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
#############################################################
|
2
|
-
# test_sys_cpu_bsd.rb
|
3
|
-
#
|
4
|
-
# The test case for sys-cpu on BSD flavors, including OS X.
|
5
|
-
#############################################################
|
6
|
-
require 'sys/cpu'
|
7
|
-
require 'rbconfig'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'test_sys_cpu_version'
|
10
|
-
include Sys
|
11
|
-
|
12
|
-
class TC_Sys_CPU_BSD < Test::Unit::TestCase
|
13
|
-
test "architecture method basic functionality" do
|
14
|
-
assert_respond_to(CPU, :architecture)
|
15
|
-
assert_nothing_raised{ CPU.architecture }
|
16
|
-
end
|
17
|
-
|
18
|
-
test "architecture method returns a sane value" do
|
19
|
-
assert_kind_of(String, CPU.architecture)
|
20
|
-
assert_true(CPU.architecture.size > 0)
|
21
|
-
end
|
22
|
-
|
23
|
-
test "architecture method does not accept any arguments" do
|
24
|
-
assert_raises(ArgumentError){ CPU.architecture(0) }
|
25
|
-
end
|
26
|
-
|
27
|
-
test "freq method basic functionality" do
|
28
|
-
assert_respond_to(CPU, :freq)
|
29
|
-
assert_nothing_raised{ CPU.freq }
|
30
|
-
end
|
31
|
-
|
32
|
-
test "freq method returns expected value" do
|
33
|
-
assert_kind_of(Integer, CPU.freq)
|
34
|
-
assert_true(CPU.freq > 0)
|
35
|
-
end
|
36
|
-
|
37
|
-
test "freq method does not accept any arguments" do
|
38
|
-
assert_raises(ArgumentError){ CPU.freq(0) }
|
39
|
-
end
|
40
|
-
|
41
|
-
test "load_avg method basic functionality" do
|
42
|
-
assert_respond_to(CPU, :load_avg)
|
43
|
-
assert_nothing_raised{ CPU.load_avg }
|
44
|
-
end
|
45
|
-
|
46
|
-
test "load_avg returns the expected results" do
|
47
|
-
assert_kind_of(Array, CPU.load_avg)
|
48
|
-
assert_equal(3, CPU.load_avg.length)
|
49
|
-
assert_kind_of(Float, CPU.load_avg[0])
|
50
|
-
end
|
51
|
-
|
52
|
-
test "load_avg does not accept any arguments" do
|
53
|
-
assert_raises(ArgumentError){ CPU.load_avg(0) }
|
54
|
-
end
|
55
|
-
|
56
|
-
test "machine method basic functionality" do
|
57
|
-
assert_respond_to(CPU, :machine)
|
58
|
-
assert_nothing_raised{ CPU.machine }
|
59
|
-
end
|
60
|
-
|
61
|
-
test "machine method returns sane value" do
|
62
|
-
assert_kind_of(String, CPU.machine)
|
63
|
-
assert_true(CPU.machine.size > 0)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "machine method does not accept any arguments" do
|
67
|
-
assert_raises(ArgumentError){ CPU.machine(0) }
|
68
|
-
end
|
69
|
-
|
70
|
-
test "model method basic functionality" do
|
71
|
-
assert_respond_to(CPU, :model)
|
72
|
-
assert_nothing_raised{ CPU.model }
|
73
|
-
end
|
74
|
-
|
75
|
-
test "model method returns sane value" do
|
76
|
-
assert_kind_of(String, CPU.model)
|
77
|
-
assert_true(CPU.model.length > 0)
|
78
|
-
end
|
79
|
-
|
80
|
-
test "model method does not accept any arguments" do
|
81
|
-
assert_raises(ArgumentError){ CPU.model(0) }
|
82
|
-
end
|
83
|
-
|
84
|
-
test "num_cpu method basic functionality" do
|
85
|
-
assert_respond_to(CPU, :num_cpu)
|
86
|
-
assert_nothing_raised{ CPU.num_cpu }
|
87
|
-
end
|
88
|
-
|
89
|
-
test "num_cpu method returns expected value" do
|
90
|
-
assert_kind_of(Integer, CPU.num_cpu)
|
91
|
-
assert_true(CPU.num_cpu > 0)
|
92
|
-
end
|
93
|
-
|
94
|
-
test "num_cpu method does not accept any arguments" do
|
95
|
-
assert_raises(ArgumentError){ CPU.num_cpu(0) }
|
96
|
-
end
|
97
|
-
end
|
data/test/test_sys_cpu_hpux.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
#####################################################################
|
2
|
-
# test_sys_cpu_hpux.rb
|
3
|
-
#
|
4
|
-
# Test suite for the HP-UX platform. This should be run via the
|
5
|
-
# 'rake test' task.
|
6
|
-
#####################################################################
|
7
|
-
require 'sys/cpu'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'test_sys_cpu_version'
|
10
|
-
include Sys
|
11
|
-
|
12
|
-
class TC_Sys_CPU_HPUX < Test::Unit::TestCase
|
13
|
-
def test_cpu_freq
|
14
|
-
assert_respond_to(CPU, :freq)
|
15
|
-
assert_nothing_raised{ CPU.freq }
|
16
|
-
assert_nothing_raised{ CPU.freq(0) }
|
17
|
-
assert_kind_of(Integer, CPU.freq, 'Invalid Type')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_num_cpu
|
21
|
-
assert_respond_to(CPU, :num_cpu)
|
22
|
-
assert_nothing_raised{ CPU.num_cpu }
|
23
|
-
assert_kind_of(Integer, CPU.num_cpu, 'Invalid Type')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_num_active_cpu
|
27
|
-
assert_respond_to(CPU, :num_active_cpu)
|
28
|
-
assert_nothing_raised{ CPU.num_active_cpu }
|
29
|
-
assert_kind_of(Integer, CPU.num_active_cpu, 'Invalid Type')
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_cpu_architecture
|
33
|
-
assert_respond_to(CPU, :architecture)
|
34
|
-
assert_nothing_raised{ CPU.architecture }
|
35
|
-
assert_kind_of(String, CPU.architecture, 'Invalid Type')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_load_avg
|
39
|
-
assert_respond_to(CPU, :load_avg)
|
40
|
-
assert_nothing_raised{ CPU.load_avg }
|
41
|
-
assert_nothing_raised{ CPU.load_avg(0) }
|
42
|
-
assert_nothing_raised{ CPU.load_avg{ |e| } }
|
43
|
-
assert_raises(ArgumentError){ CPU.load_avg(0){ } }
|
44
|
-
assert_kind_of(Array, CPU.load_avg, 'Invalid Type')
|
45
|
-
assert_kind_of(Array, CPU.load_avg(0), 'Invalid Type')
|
46
|
-
assert_equal(3, CPU.load_avg.length, 'Bad number of elements')
|
47
|
-
assert_equal(3, CPU.load_avg(0).length, 'Bad number of elements')
|
48
|
-
end
|
49
|
-
end
|
data/test/test_sys_cpu_linux.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
###########################################################
|
2
|
-
# test_sys_cpu_linux.rb
|
3
|
-
#
|
4
|
-
# Test Suite for sys-cpu for Linux. This should be run via
|
5
|
-
# the 'rake test' task.
|
6
|
-
###########################################################
|
7
|
-
require 'sys/cpu'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'test_sys_cpu_version'
|
10
|
-
include Sys
|
11
|
-
|
12
|
-
class TC_Sys_CPU_Linux < Test::Unit::TestCase
|
13
|
-
def test_all_dynamic_methods
|
14
|
-
assert_nothing_raised{
|
15
|
-
CPU.processors{ |cs|
|
16
|
-
cs.members.each{ |m| cs[m].to_s }
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_load_avg
|
22
|
-
assert_nothing_raised{ CPU.load_avg }
|
23
|
-
assert_equal(3, CPU.load_avg.length)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_cpu_stats
|
27
|
-
assert_nothing_raised{ CPU.cpu_stats }
|
28
|
-
assert_kind_of(Hash, CPU.cpu_stats)
|
29
|
-
assert_equal(true, CPU.cpu_stats['cpu0'].length >= 4)
|
30
|
-
end
|
31
|
-
end
|
data/test/test_sys_cpu_sunos.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
###########################################################
|
2
|
-
# test_sys_cpu_sunos.rb
|
3
|
-
#
|
4
|
-
# Test suite for sys-cpu on Solaris. This should be run
|
5
|
-
# via the 'rake test' task.
|
6
|
-
###########################################################
|
7
|
-
require 'sys/cpu'
|
8
|
-
require 'test-unit'
|
9
|
-
include Sys
|
10
|
-
|
11
|
-
class TC_Sys_CPU_SunOS < Test::Unit::TestCase
|
12
|
-
test "freq method basic functionality" do
|
13
|
-
assert_respond_to(CPU, :freq)
|
14
|
-
assert_nothing_raised{ CPU.freq }
|
15
|
-
end
|
16
|
-
|
17
|
-
test "freq method does not accept any arguments" do
|
18
|
-
assert_raise(ArgumentError){ CPU.freq(0) }
|
19
|
-
end
|
20
|
-
|
21
|
-
test "freq method returns a sane value" do
|
22
|
-
assert_kind_of(Integer, CPU.freq)
|
23
|
-
assert_true(CPU.freq > 100)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "fpu_type basic functionality" do
|
27
|
-
assert_respond_to(CPU, :fpu_type)
|
28
|
-
assert_nothing_raised{ CPU.fpu_type }
|
29
|
-
end
|
30
|
-
|
31
|
-
test "fpu_type returns a sane value" do
|
32
|
-
assert_kind_of(String, CPU.fpu_type)
|
33
|
-
assert_false(CPU.fpu_type.empty?)
|
34
|
-
end
|
35
|
-
|
36
|
-
test "load_avg basic functionality" do
|
37
|
-
assert_respond_to(CPU, :load_avg)
|
38
|
-
assert_nothing_raised{ CPU.load_avg }
|
39
|
-
end
|
40
|
-
|
41
|
-
test "load_avg method returns the expected values" do
|
42
|
-
assert_kind_of(Array, CPU.load_avg)
|
43
|
-
assert_equal(3, CPU.load_avg.length)
|
44
|
-
assert_kind_of(Float, CPU.load_avg.first)
|
45
|
-
end
|
46
|
-
|
47
|
-
test "model method basic functionality" do
|
48
|
-
assert_respond_to(CPU, :model)
|
49
|
-
assert_nothing_raised{ CPU.model }
|
50
|
-
end
|
51
|
-
|
52
|
-
test "model method returns a sane value" do
|
53
|
-
assert_kind_of(String, CPU.model)
|
54
|
-
assert_false(CPU.model.empty?)
|
55
|
-
end
|
56
|
-
|
57
|
-
test "num_cpu method basic functionalty" do
|
58
|
-
assert_respond_to(CPU, :num_cpu)
|
59
|
-
assert_nothing_raised{ CPU.num_cpu }
|
60
|
-
end
|
61
|
-
|
62
|
-
test "num_cpu method returns a sane value" do
|
63
|
-
assert_kind_of(Integer, CPU.num_cpu)
|
64
|
-
assert_true(CPU.num_cpu > 0)
|
65
|
-
end
|
66
|
-
|
67
|
-
test "state basic functionality" do
|
68
|
-
assert_respond_to(CPU, :state)
|
69
|
-
assert_nothing_raised{ CPU.state }
|
70
|
-
end
|
71
|
-
|
72
|
-
test "state method accepts one optional argument" do
|
73
|
-
assert_nothing_raised{ CPU.state(0) }
|
74
|
-
assert_raise(ArgumentError){ CPU.state(0,0) }
|
75
|
-
end
|
76
|
-
|
77
|
-
test "state method returns a sane value" do
|
78
|
-
assert_kind_of(String, CPU.state(0))
|
79
|
-
assert_false(CPU.state.empty?)
|
80
|
-
end
|
81
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
#######################################################################
|
2
|
-
# test_sys_cpu_version.rb
|
3
|
-
#
|
4
|
-
# The sole purpose of this test case is to verify the version number.
|
5
|
-
# This reduces the pain of having separate tests for the VERSION
|
6
|
-
# constant in every single test case.
|
7
|
-
#######################################################################
|
8
|
-
require 'sys/cpu'
|
9
|
-
require 'test-unit'
|
10
|
-
|
11
|
-
class TC_Sys_CPU_VERSION < Test::Unit::TestCase
|
12
|
-
test "version number is set to the expected value" do
|
13
|
-
assert_equal('0.8.0', Sys::CPU::VERSION)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "version number is frozen" do
|
17
|
-
assert_true(Sys::CPU::VERSION.frozen?)
|
18
|
-
end
|
19
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
######################################################################
|
2
|
-
# test_sys_cpu_windows.rb
|
3
|
-
#
|
4
|
-
# Test suite for MS Windows systems. This should be run via the
|
5
|
-
# 'rake test' task.
|
6
|
-
######################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
gem 'test-unit'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'sys/cpu'
|
12
|
-
require 'test_sys_cpu_version'
|
13
|
-
require 'socket'
|
14
|
-
include Sys
|
15
|
-
|
16
|
-
class TC_Sys_CPU_Windows < Test::Unit::TestCase
|
17
|
-
def self.startup
|
18
|
-
@@host = Socket.gethostname
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_architecture
|
22
|
-
assert_respond_to(CPU, :architecture)
|
23
|
-
assert_nothing_raised{ CPU.architecture }
|
24
|
-
assert_nothing_raised{ CPU.architecture(@@host) }
|
25
|
-
assert_kind_of(String, CPU.architecture, 'Invalid Type')
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_freq
|
29
|
-
assert_respond_to(CPU, :freq)
|
30
|
-
assert_nothing_raised{ CPU.freq }
|
31
|
-
assert_nothing_raised{ CPU.freq(0) }
|
32
|
-
assert_nothing_raised{ CPU.freq(0, @@host) }
|
33
|
-
assert_kind_of(Integer, CPU.freq, 'Invalid Type')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_model
|
37
|
-
assert_respond_to(CPU, :model)
|
38
|
-
assert_nothing_raised{ CPU.model }
|
39
|
-
assert_nothing_raised{ CPU.model(@@host) }
|
40
|
-
assert_kind_of(String, CPU.model, 'Invalid Type')
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_num_cpu
|
44
|
-
assert_respond_to(CPU, :num_cpu)
|
45
|
-
assert_nothing_raised{ CPU.num_cpu }
|
46
|
-
assert_nothing_raised{ CPU.num_cpu(@@host) }
|
47
|
-
assert_kind_of(Integer, CPU.num_cpu, 'Invalid Type')
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_cpu_type
|
51
|
-
assert_respond_to(CPU, :cpu_type)
|
52
|
-
assert_nothing_raised{ CPU.cpu_type }
|
53
|
-
assert_nothing_raised{ CPU.cpu_type(@@host) }
|
54
|
-
assert_kind_of(String, CPU.cpu_type, 'Invalid Type')
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_load_avg
|
58
|
-
assert_respond_to(CPU, :load_avg)
|
59
|
-
assert_nothing_raised{ CPU.load_avg }
|
60
|
-
assert_nothing_raised{ CPU.load_avg(0, @@host) }
|
61
|
-
assert_kind_of(Integer, CPU.load_avg, 'Invalid Type')
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_processors
|
65
|
-
assert_respond_to(CPU, :processors)
|
66
|
-
assert_nothing_raised{ CPU.processors{} }
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.shutdown
|
70
|
-
@@host = nil
|
71
|
-
end
|
72
|
-
end
|