sys-cpu 0.6.2-x86-linux → 0.6.3-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +9 -1
- data/MANIFEST +2 -2
- data/README +58 -61
- data/Rakefile +48 -45
- data/examples/example_sys_cpu_linux.rb +5 -6
- data/ext/bsd/bsd.c +1 -1
- data/ext/extconf.rb +5 -4
- data/ext/hpux/hpux.c +1 -1
- data/ext/sunos/sunos.c +1 -1
- data/ext/version.h +1 -1
- data/install.rb +34 -33
- data/lib/linux/sys/cpu.rb +1 -1
- data/lib/windows/sys/cpu.rb +759 -753
- data/sys-cpu.gemspec +2 -2
- data/test/test_sys_cpu_version.rb +3 -3
- data/test/test_sys_cpu_windows.rb +47 -47
- metadata +27 -9
data/CHANGES
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
== 0.6.
|
1
|
+
== 0.6.3 - 9-Oct-2010
|
2
|
+
* Fixed a bug in the install.rb file and refactored it a bit. Thanks go
|
3
|
+
to Di-an Jan for the spot. Note, however, that this file will eventually
|
4
|
+
be removed and/or integrated into the Linux source file.
|
5
|
+
* Fixed the example Rake task, and refactored some of the other tasks.
|
6
|
+
* Fixed and updated the CPU.architecture method on MS Windows to handle IA64
|
7
|
+
and x64 architectures.
|
8
|
+
|
9
|
+
== 0.6.2 - 1-Jan-2010
|
2
10
|
* Fixed a bug in the cpu_freq function (which would only be noticed on
|
3
11
|
certain platforms in cases where the CPU.freq method failed). Thanks
|
4
12
|
go to Edho P Arief for the spot.
|
data/MANIFEST
CHANGED
data/README
CHANGED
@@ -1,79 +1,76 @@
|
|
1
|
-
|
1
|
+
= Description
|
2
2
|
A Ruby interface for getting cpu information.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
= Installation
|
5
|
+
gem install sys-cpu
|
6
|
+
gem install sys-cpu --platform mswin32 # MS Windows
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
I do not support any Ruby 1.8.x branch after 1.8.6. It should work on those
|
14
|
-
versions of Ruby but if it breaks I'm not going to go out of my way to fix
|
15
|
-
it. I will, however, support the 1.9.x/2.x branch.
|
8
|
+
= Notes
|
9
|
+
== All Platforms
|
10
|
+
I do not support any Ruby 1.8.x branch after 1.8.6. It should work on those
|
11
|
+
versions of Ruby but if it breaks I'm not going to go out of my way to fix
|
12
|
+
it. I will, however, support the 1.9.x/2.x branch.
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
== Solaris
|
15
|
+
Currently there is no 'processors()' iterative method for multi-cpu systems.
|
16
|
+
I plan to add it this in a future release.
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
== OS X
|
19
|
+
The CPU.freq method is not supported at the moment. The sysctl() approach
|
20
|
+
returns a bogus, hard coded value of some sort. I suspect it's possible
|
21
|
+
by using kernel modules via kldload(), but I'm not sure how yet.
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
== Linux
|
24
|
+
This is pure Ruby. This version reads information out of /proc/cpuinfo and
|
25
|
+
/proc/loadavg, so if /proc isn't mounted it won't work.
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
The key-value information in /proc/cpuinfo is stored internally (i.e. in
|
28
|
+
memory) as an array of hashes when you first 'require' this package. This
|
29
|
+
overhead is exceptionally minimal, given that your average cpuinfo file
|
30
|
+
contains less than 1k of text (and I don't store whitespace or newlines).
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
The text documentation for Linux is dynamically generated during the
|
33
|
+
build process because the fields vary depending on your setup. So, don't
|
34
|
+
look at it until *after* you've installed it. You will see a doc/linux.txt
|
35
|
+
file after you run 'rake install' (via install.rb).
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
== HP-UX
|
38
|
+
Unlike other platforms, you can get load averages for an individual cpu in
|
39
|
+
multi-cpu systems. See documentation for more details.
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
== MS Windows
|
42
|
+
This is a pure Ruby implementation using the win32ole package + WMI. The C
|
43
|
+
version has been scrapped.
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
As of version 0.5.0, the CPU.usage method has been removed in favor of the
|
46
|
+
CPU.load_avg method. This does not (currently) use a perf counter, so there
|
47
|
+
is no longer any delay. Also, the 'processors' method has been
|
48
|
+
added and the 'supported' method has been dropped. See the documentation
|
49
|
+
for other changes.
|
53
50
|
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
= Acknowledgements
|
52
|
+
Thanks go to the MPlayer team for some source code that helped me on
|
53
|
+
certain versions of FreeBSD.
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
= Known Bugs
|
56
|
+
None that I'm aware of. Please report bugs on the project page at
|
57
|
+
http://www.rubyforge.org/projects/sysutils.
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
= Future Plans
|
60
|
+
Add iterative CPU.processors method.
|
61
|
+
Make CPU.freq work on OS X.
|
62
|
+
Add more information in general, such as what 'prtdiag' shows.
|
66
63
|
|
67
|
-
|
68
|
-
|
64
|
+
= License
|
65
|
+
Artistic 2.0
|
69
66
|
|
70
|
-
|
71
|
-
|
67
|
+
= Copyright
|
68
|
+
(C) 2003-2009 Daniel J. Berger, All Rights Reserved
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
= Warranty
|
71
|
+
This package is provided "as is" and without any express or
|
72
|
+
implied warranties, including, without limitation, the implied
|
73
|
+
warranties of merchantability and fitness for a particular purpose.
|
77
74
|
|
78
|
-
|
79
|
-
|
75
|
+
= Author
|
76
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -3,50 +3,50 @@ require 'rake/clean'
|
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rbconfig'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
namespace 'C' do
|
7
|
+
desc "Clean the build files for the sys-cpu source for UNIX systems"
|
8
|
+
task :clean do
|
9
|
+
Dir["*.gem"].each{ |f| File.delete(f) }
|
10
|
+
|
11
|
+
rm_rf('sys') if File.exists?('sys')
|
12
|
+
rm_rf('lib/sys/cpu.rb') if File.exists?('lib/sys/cpu.rb')
|
13
|
+
|
14
|
+
Dir.chdir('ext') do
|
15
|
+
unless Config::CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|linux/i
|
16
|
+
rm_rf('conftest.dSYM') if File.exists?('conftest.dSYM') # OS X
|
17
|
+
rm_rf('sys') if File.exists?('sys')
|
18
|
+
rm_rf('cpu.c') if File.exists?('cpu.c')
|
19
|
+
build_file = 'cpu.' + Config::CONFIG['DLEXT']
|
20
|
+
sh 'make distclean' if File.exists?(build_file)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
|
-
end
|
19
24
|
|
20
|
-
desc "Build the sys-cpu library on UNIX systems
|
21
|
-
task :build => [:clean] do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
desc "Build the sys-cpu library on UNIX systems"
|
26
|
+
task :build => [:clean] do
|
27
|
+
Dir.chdir('ext') do
|
28
|
+
unless Config::CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|linux/i
|
29
|
+
ruby 'extconf.rb'
|
30
|
+
sh 'make'
|
31
|
+
build_file = 'cpu.' + Config::CONFIG['DLEXT']
|
32
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
33
|
+
FileUtils.cp(build_file, 'sys')
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if Config::CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|linux/i
|
40
|
-
desc "Install the sys-cpu library"
|
41
|
-
task :install do
|
42
|
-
sh 'ruby install.rb'
|
39
|
+
namespace 'gem' do
|
40
|
+
desc "Create the sys-cpu gem"
|
41
|
+
task :create => ['C:clean'] do
|
42
|
+
spec = eval(IO.read('sys-cpu.gemspec'))
|
43
|
+
Gem::Builder.new(spec).build
|
43
44
|
end
|
44
|
-
|
45
|
-
desc "Install the sys-cpu
|
46
|
-
task :install => [:
|
47
|
-
Dir.
|
48
|
-
|
49
|
-
end
|
45
|
+
|
46
|
+
desc "Install the sys-cpu gem"
|
47
|
+
task :install => [:create] do
|
48
|
+
file = Dir["*.gem"].first
|
49
|
+
sh "gem install #{file}"
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -55,26 +55,26 @@ task :example => [:build] do
|
|
55
55
|
Dir.mkdir('sys') unless File.exists?('sys')
|
56
56
|
if Config::CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|linux/i
|
57
57
|
if Config::CONFIG['host_os'].match('linux')
|
58
|
-
|
58
|
+
cp 'lib/linux/sys/cpu.rb', 'sys'
|
59
59
|
else
|
60
|
-
|
60
|
+
cp 'lib/windows/sys/cpu.rb', 'sys'
|
61
61
|
end
|
62
62
|
else
|
63
63
|
build_file = 'ext/cpu.' + Config::CONFIG['DLEXT']
|
64
|
-
|
64
|
+
cp build_file, 'sys'
|
65
65
|
end
|
66
66
|
|
67
67
|
case Config::CONFIG['host_os']
|
68
68
|
when /bsd|darwin|mach|osx/i
|
69
|
-
file = 'examples/
|
69
|
+
file = 'examples/example_sys_cpu_bsd.rb'
|
70
70
|
when /hpux/i
|
71
|
-
file = 'examples/
|
71
|
+
file = 'examples/example_sys_cpu_hpux.rb'
|
72
72
|
when /linux/i
|
73
|
-
file = 'examples/
|
73
|
+
file = 'examples/example_sys_cpu_linux.rb'
|
74
74
|
when /sunos|solaris/i
|
75
|
-
file = 'examples/
|
75
|
+
file = 'examples/example_sys_cpu_sunos.rb'
|
76
76
|
when /mswin|win32|cygwin|mingw|dos/i
|
77
|
-
file = 'examples/
|
77
|
+
file = 'examples/example_sys_cpu_windows.rb'
|
78
78
|
end
|
79
79
|
sh "ruby -I. -Iext -Ilib #{file}"
|
80
80
|
end
|
@@ -85,7 +85,7 @@ Rake::TestTask.new do |t|
|
|
85
85
|
elsif Config::CONFIG['host_os'] =~ /linux/i
|
86
86
|
t.libs << 'lib/linux'
|
87
87
|
else
|
88
|
-
task :test => :build
|
88
|
+
task :test => 'C:build'
|
89
89
|
t.libs << 'ext'
|
90
90
|
t.libs.delete('lib')
|
91
91
|
end
|
@@ -93,3 +93,6 @@ Rake::TestTask.new do |t|
|
|
93
93
|
t.libs << 'test'
|
94
94
|
t.test_files = FileList['test/test_sys_cpu.rb']
|
95
95
|
end
|
96
|
+
|
97
|
+
task :default => :test
|
98
|
+
task :clean => 'C:clean'
|
@@ -1,25 +1,24 @@
|
|
1
1
|
#######################################################################
|
2
2
|
# example_sys_cpu_linux.rb
|
3
3
|
#
|
4
|
-
# Sample cript for general futzing. You
|
4
|
+
# Sample cript for general futzing. You should run this code via the
|
5
5
|
# 'rake example' task.
|
6
6
|
#
|
7
7
|
# Modify as you see fit.
|
8
8
|
#######################################################################
|
9
9
|
require "sys/cpu"
|
10
10
|
require "pp"
|
11
|
-
include Sys
|
12
11
|
|
13
|
-
puts "VERSION: " + CPU::VERSION
|
12
|
+
puts "VERSION: " + Sys::CPU::VERSION
|
14
13
|
puts "========"
|
15
14
|
|
16
|
-
puts "Load Average: " + CPU.load_avg.join(", ")
|
15
|
+
puts "Load Average: " + Sys::CPU.load_avg.join(", ")
|
17
16
|
|
18
17
|
puts "Processor Info:"
|
19
18
|
puts "==============="
|
20
|
-
pp CPU.processors
|
19
|
+
pp Sys::CPU.processors
|
21
20
|
|
22
21
|
puts "CPU STATS:"
|
23
22
|
puts "=========:"
|
24
23
|
|
25
|
-
pp CPU.cpu_stats
|
24
|
+
pp Sys::CPU.cpu_stats
|
data/ext/bsd/bsd.c
CHANGED
@@ -281,7 +281,7 @@ void Init_cpu()
|
|
281
281
|
*/
|
282
282
|
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
283
283
|
|
284
|
-
/* 0.6.
|
284
|
+
/* 0.6.3: The version of the sys-cpu library */
|
285
285
|
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
286
286
|
|
287
287
|
/* Class Methods */
|
data/ext/extconf.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'mkmf'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rbconfig'
|
3
4
|
|
4
5
|
File.delete('cpu.c') if File.exists?('cpu.c')
|
5
6
|
|
6
|
-
case
|
7
|
+
case Config::CONFIG['host_os']
|
7
8
|
when /hpux/i
|
8
9
|
FileUtils.cp("hpux/hpux.c", "cpu.c")
|
9
10
|
when /sunos|solaris/i
|
@@ -17,7 +18,7 @@ case RUBY_PLATFORM
|
|
17
18
|
have_library("kvm")
|
18
19
|
have_header("kvm.h")
|
19
20
|
when /linux|dos|windows|win32|mingw|cygwin/i
|
20
|
-
STDERR.puts "Run '
|
21
|
+
STDERR.puts "Run 'rake gem:install' instead for this platform"
|
21
22
|
else
|
22
23
|
STDERR.puts "This platform is not currently supported. Exiting..."
|
23
24
|
end
|
data/ext/hpux/hpux.c
CHANGED
@@ -203,7 +203,7 @@ void Init_cpu()
|
|
203
203
|
*/
|
204
204
|
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
205
205
|
|
206
|
-
/* 0.6.
|
206
|
+
/* 0.6.3: The version of the sys-cpu library */
|
207
207
|
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
208
208
|
|
209
209
|
/* Class Methods */
|
data/ext/sunos/sunos.c
CHANGED
@@ -262,7 +262,7 @@ void Init_cpu()
|
|
262
262
|
*/
|
263
263
|
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
264
264
|
|
265
|
-
/* 0.6.
|
265
|
+
/* 0.6.3: The version of the sys-cpu library */
|
266
266
|
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
267
267
|
|
268
268
|
/* Class Methods */
|
data/ext/version.h
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/* version.h - one version to rule them all */
|
2
|
-
#define SYS_CPU_VERSION "0.6.
|
2
|
+
#define SYS_CPU_VERSION "0.6.3"
|
data/install.rb
CHANGED
@@ -30,42 +30,43 @@ end
|
|
30
30
|
# has already been written at some point previously and skip it.
|
31
31
|
#######################################################################
|
32
32
|
if CONFIG['host_os'] =~ /linux/
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
cpu_file = "/proc/cpuinfo"
|
34
|
+
text_file = "doc/linux.txt"
|
35
|
+
rb_file = "lib/linux/sys/cpu.rb"
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
if File.size(text_file) > 1400
|
38
|
+
puts "You appear to have already created the documentation."
|
39
|
+
puts "Skipping..."
|
40
|
+
else
|
41
|
+
puts "Dynamically generating documentation..."
|
42
|
+
fh = File.open(text_file, 'a')
|
43
|
+
|
44
|
+
IO.foreach(cpu_file){ |line|
|
45
|
+
next if line =~ /^$/
|
46
|
+
k,v = line.split(":")
|
47
|
+
|
48
|
+
v = v.strip.chomp
|
49
|
+
k = k.strip.gsub(/\s+/, '_').downcase
|
50
|
+
|
51
|
+
k += "?" if v =~ /yes|no/i
|
43
52
|
|
44
|
-
|
45
|
-
next if line =~ /^$/
|
46
|
-
k,v = line.split(":")
|
47
|
-
v.strip!.chomp!
|
48
|
-
k.strip!.gsub!(/\s+/,"_")
|
49
|
-
k.downcase!
|
50
|
-
if v =~ /yes|no/i
|
51
|
-
k += "?"
|
52
|
-
end
|
53
|
-
fh.puts("CPU.#{k}")
|
54
|
-
if v =~ /yes|no/i
|
55
|
-
k.chop!
|
56
|
-
msg = " Returns true if a " + k.gsub(/_/," ") + "exists on"
|
57
|
-
msg << " this system"
|
58
|
-
fh.puts(msg)
|
59
|
-
else
|
60
|
-
fh.puts(" Returns the " + k.gsub(/_/," "))
|
61
|
-
end
|
62
|
-
fh.puts # Add a blank line
|
63
|
-
}
|
53
|
+
fh.puts("CPU.#{k}")
|
64
54
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
55
|
+
if v =~ /yes|no/i
|
56
|
+
k.chop!
|
57
|
+
msg = " Returns true if a " + k.gsub(/_/," ") + "exists on"
|
58
|
+
msg << " this system"
|
59
|
+
fh.puts(msg)
|
60
|
+
else
|
61
|
+
fh.puts(" Returns the " + k.gsub(/_/," "))
|
62
|
+
end
|
63
|
+
|
64
|
+
fh.puts # Add a blank line
|
65
|
+
}
|
66
|
+
|
67
|
+
fh.close
|
68
|
+
puts "Documentation creation complete"
|
69
|
+
end
|
69
70
|
end
|
70
71
|
|
71
72
|
# Create the 'sys' toplevel directory if it doesn't already exist
|