sys-cpu 0.6.3 → 0.6.4
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 +8 -0
- data/README +8 -11
- data/Rakefile +28 -37
- data/ext/bsd/bsd.c +77 -40
- data/ext/hpux/hpux.c +1 -1
- data/ext/sunos/sunos.c +1 -1
- data/ext/version.h +1 -1
- data/lib/linux/sys/cpu.rb +4 -4
- data/lib/windows/sys/cpu.rb +26 -26
- data/sys-cpu.gemspec +10 -7
- data/test/test_sys_cpu_bsd.rb +0 -1
- data/test/test_sys_cpu_version.rb +1 -1
- metadata +10 -12
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.6.4 - 27-Sep-2011
|
2
|
+
* The CPU.freq method now works on OSX.
|
3
|
+
* The CPU.model method on OSX has been altered. Previously it
|
4
|
+
returned the machine model. However, the information is limited.
|
5
|
+
* Fixed a couple unused variable warnings for the BSD/OSX code.
|
6
|
+
* The Linux and Windows gems now have a 'universal' architecture.
|
7
|
+
* Refactored the clean task in the Rakefile.
|
8
|
+
|
1
9
|
== 0.6.3 - 9-Oct-2010
|
2
10
|
* Fixed a bug in the install.rb file and refactored it a bit. Thanks go
|
3
11
|
to Di-an Jan for the spot. Note, however, that this file will eventually
|
data/README
CHANGED
@@ -3,22 +3,20 @@
|
|
3
3
|
|
4
4
|
= Installation
|
5
5
|
gem install sys-cpu
|
6
|
-
gem install sys-cpu --platform mswin32 # MS Windows
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it. I will, however, support the 1.9.x/2.x branch.
|
7
|
+
If that doesn't work try one of these:
|
8
|
+
|
9
|
+
gem install sys-cpu --platform linux # Linux
|
10
|
+
gem install sys-cpu --platform mingw32 # MS Windows
|
13
11
|
|
12
|
+
= Notes
|
14
13
|
== Solaris
|
15
14
|
Currently there is no 'processors()' iterative method for multi-cpu systems.
|
16
15
|
I plan to add it this in a future release.
|
17
16
|
|
18
17
|
== OS X
|
19
|
-
The CPU.
|
20
|
-
|
21
|
-
by using kernel modules via kldload(), but I'm not sure how yet.
|
18
|
+
The CPU.model method returns very limited information. I do not yet know
|
19
|
+
how to get more detailed information.
|
22
20
|
|
23
21
|
== Linux
|
24
22
|
This is pure Ruby. This version reads information out of /proc/cpuinfo and
|
@@ -58,14 +56,13 @@
|
|
58
56
|
|
59
57
|
= Future Plans
|
60
58
|
Add iterative CPU.processors method.
|
61
|
-
Make CPU.freq work on OS X.
|
62
59
|
Add more information in general, such as what 'prtdiag' shows.
|
63
60
|
|
64
61
|
= License
|
65
62
|
Artistic 2.0
|
66
63
|
|
67
64
|
= Copyright
|
68
|
-
(C) 2003-
|
65
|
+
(C) 2003-2011 Daniel J. Berger, All Rights Reserved
|
69
66
|
|
70
67
|
= Warranty
|
71
68
|
This package is provided "as is" and without any express or
|
data/Rakefile
CHANGED
@@ -2,43 +2,35 @@ require 'rake'
|
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rbconfig'
|
5
|
+
include Config
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
CLEAN.include(
|
8
|
+
'**/*.gem', # Gem files
|
9
|
+
'**/*.rbc', # Rubinius
|
10
|
+
'ext/cpu.c', # Temporary file
|
11
|
+
'**/*.o', # C object file
|
12
|
+
'**/*.log', # Ruby extension build log
|
13
|
+
'**/Makefile', # C Makefile
|
14
|
+
'**/conftest.dSYM', # OS X build directory
|
15
|
+
"**/*.#{CONFIG['DLEXT']}" # C shared object
|
16
|
+
)
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
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
|
18
|
+
desc "Build the sys-cpu library on UNIX systems"
|
19
|
+
task :build => [:clean] do
|
20
|
+
Dir.chdir('ext') do
|
21
|
+
unless CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|windows|linux/i
|
22
|
+
ruby 'extconf.rb'
|
23
|
+
sh 'make'
|
24
|
+
build_file = 'cpu.' + CONFIG['DLEXT']
|
25
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
26
|
+
FileUtils.cp(build_file, 'sys')
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
38
30
|
|
39
31
|
namespace 'gem' do
|
40
32
|
desc "Create the sys-cpu gem"
|
41
|
-
task :create => [
|
33
|
+
task :create => [:clean] do
|
42
34
|
spec = eval(IO.read('sys-cpu.gemspec'))
|
43
35
|
Gem::Builder.new(spec).build
|
44
36
|
end
|
@@ -53,18 +45,18 @@ end
|
|
53
45
|
desc "Run the example program"
|
54
46
|
task :example => [:build] do
|
55
47
|
Dir.mkdir('sys') unless File.exists?('sys')
|
56
|
-
if
|
57
|
-
if
|
48
|
+
if CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|windows|linux/i
|
49
|
+
if CONFIG['host_os'].match('linux')
|
58
50
|
cp 'lib/linux/sys/cpu.rb', 'sys'
|
59
51
|
else
|
60
52
|
cp 'lib/windows/sys/cpu.rb', 'sys'
|
61
53
|
end
|
62
54
|
else
|
63
|
-
build_file = 'ext/cpu.' +
|
55
|
+
build_file = 'ext/cpu.' + CONFIG['DLEXT']
|
64
56
|
cp build_file, 'sys'
|
65
57
|
end
|
66
58
|
|
67
|
-
case
|
59
|
+
case CONFIG['host_os']
|
68
60
|
when /bsd|darwin|mach|osx/i
|
69
61
|
file = 'examples/example_sys_cpu_bsd.rb'
|
70
62
|
when /hpux/i
|
@@ -80,12 +72,12 @@ task :example => [:build] do
|
|
80
72
|
end
|
81
73
|
|
82
74
|
Rake::TestTask.new do |t|
|
83
|
-
if
|
75
|
+
if CONFIG['host_os'] =~ /mswin|win32|mingw|cygwin|dos|windows/i
|
84
76
|
t.libs << 'lib/windows'
|
85
|
-
elsif
|
77
|
+
elsif CONFIG['host_os'] =~ /linux/i
|
86
78
|
t.libs << 'lib/linux'
|
87
79
|
else
|
88
|
-
task :test =>
|
80
|
+
task :test => :build
|
89
81
|
t.libs << 'ext'
|
90
82
|
t.libs.delete('lib')
|
91
83
|
end
|
@@ -95,4 +87,3 @@ Rake::TestTask.new do |t|
|
|
95
87
|
end
|
96
88
|
|
97
89
|
task :default => :test
|
98
|
-
task :clean => 'C:clean'
|
data/ext/bsd/bsd.c
CHANGED
@@ -30,6 +30,10 @@
|
|
30
30
|
#include <unistd.h>
|
31
31
|
#endif
|
32
32
|
|
33
|
+
#if defined(__MACH__) && defined(__APPLE__)
|
34
|
+
#include <mach/machine.h>
|
35
|
+
#endif
|
36
|
+
|
33
37
|
VALUE cCPUError;
|
34
38
|
|
35
39
|
/****************************************************************************
|
@@ -53,45 +57,45 @@ static int64_t rdtsc(void){
|
|
53
57
|
* average.
|
54
58
|
*/
|
55
59
|
static VALUE cpu_load_avg(VALUE klass){
|
56
|
-
|
57
|
-
int n, max = 3;
|
60
|
+
int n;
|
58
61
|
VALUE v_num_array = rb_ary_new();
|
59
62
|
|
60
63
|
#ifdef HAVE_KVM_H
|
61
|
-
|
64
|
+
int max = 3;
|
65
|
+
kvm_t* k;
|
66
|
+
double avgs[3];
|
62
67
|
|
63
|
-
|
68
|
+
k = malloc(sizeof(kvm_t*));
|
64
69
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
if(!kvm_getloadavg(k, avgs, max)){
|
71
|
+
free(k);
|
72
|
+
rb_raise(cCPUError, "error calling kvm_getloadavg(): %s", strerror(errno));
|
73
|
+
}
|
69
74
|
|
70
|
-
|
71
|
-
|
75
|
+
for(n = 0; n < 3; n++)
|
76
|
+
rb_ary_push(v_num_array, rb_float_new(avgs[n]));
|
72
77
|
|
73
|
-
|
78
|
+
free(k);
|
74
79
|
#else
|
75
80
|
struct loadavg k;
|
76
81
|
size_t len = sizeof(k);
|
77
82
|
|
78
83
|
#ifdef HAVE_SYSCTLBYNAME
|
79
|
-
|
80
|
-
|
84
|
+
if(sysctlbyname("vm.loadavg", &k, &len, NULL, 0))
|
85
|
+
rb_raise(cCPUError, "error calling sysctlbyname(): %s", strerror(errno));
|
81
86
|
#else
|
82
|
-
|
83
|
-
|
84
|
-
|
87
|
+
int mib[2];
|
88
|
+
mib[0] = CTL_HW;
|
89
|
+
mib[1] = VM_LOADAVG;
|
85
90
|
|
86
|
-
|
87
|
-
|
91
|
+
if(sysctl(mib, 2, &k, &len, NULL, 0))
|
92
|
+
rb_raise(cCPUError, "error calling sysctl(): %s", strerror(errno));
|
88
93
|
#endif
|
89
|
-
|
90
|
-
|
91
|
-
rb_ary_push(v_num_array, rb_float_new(k.ldavg[n] / (float)k.fscale));
|
94
|
+
for(n = 0; n < 3; n++)
|
95
|
+
rb_ary_push(v_num_array, rb_float_new(k.ldavg[n] / (float)k.fscale));
|
92
96
|
#endif
|
93
97
|
|
94
|
-
|
98
|
+
return v_num_array;
|
95
99
|
}
|
96
100
|
|
97
101
|
/*
|
@@ -126,24 +130,54 @@ static VALUE cpu_num(VALUE klass){
|
|
126
130
|
* CPU.model
|
127
131
|
*
|
128
132
|
* Returns a string indicating the cpu model.
|
133
|
+
*--
|
134
|
+
* On OSX I use the hw.cputype instead of hw.model because OSX returns the
|
135
|
+
* machine model instead of the cpu model for some reason. Initial attempts
|
136
|
+
* to add the cpusubtype as well were unreliable.
|
129
137
|
*/
|
130
138
|
static VALUE cpu_model(VALUE klass){
|
131
|
-
|
132
|
-
|
139
|
+
char model[64];
|
140
|
+
size_t len = sizeof(model);
|
133
141
|
|
134
142
|
#ifdef HAVE_SYSCTLBYNAME
|
135
|
-
|
136
|
-
|
143
|
+
#if defined(__MACH__) && defined(__APPLE__)
|
144
|
+
int cpu_type;
|
145
|
+
len = sizeof(cpu_type);
|
146
|
+
|
147
|
+
if(sysctlbyname("hw.cputype", &cpu_type, &len, NULL, 0))
|
137
148
|
#else
|
138
|
-
|
139
|
-
|
140
|
-
|
149
|
+
if(sysctlbyname("hw.model", &model, &len, NULL, 0))
|
150
|
+
#endif
|
151
|
+
rb_raise(cCPUError, "error calling sysctlbyname(): %s", strerror(errno));
|
152
|
+
#else
|
153
|
+
int mib[2];
|
141
154
|
|
142
|
-
|
143
|
-
|
155
|
+
mib[0] = CTL_HW;
|
156
|
+
mib[1] = HW_MODEL;
|
157
|
+
|
158
|
+
if(sysctl(mib, 2, &model, &len, NULL, 0))
|
159
|
+
rb_raise(cCPUError, "error calling sysctl(): %s", strerror(errno));
|
160
|
+
#endif
|
161
|
+
|
162
|
+
#if defined(__MACH__) && defined(__APPLE__)
|
163
|
+
// Intel and PowerPC only.
|
164
|
+
switch(cpu_type){
|
165
|
+
case CPU_TYPE_X86:
|
166
|
+
case CPU_TYPE_X86_64:
|
167
|
+
strcpy(model, "Intel");
|
168
|
+
break;
|
169
|
+
case CPU_TYPE_POWERPC:
|
170
|
+
case CPU_TYPE_POWERPC64:
|
171
|
+
strcpy(model, "PowerPC");
|
172
|
+
break;
|
173
|
+
default:
|
174
|
+
strcpy(model, "Unknown");
|
175
|
+
}
|
176
|
+
|
177
|
+
// TODO: Add the subtype.
|
144
178
|
#endif
|
145
179
|
|
146
|
-
|
180
|
+
return rb_str_new2(model);
|
147
181
|
}
|
148
182
|
|
149
183
|
/*
|
@@ -218,13 +252,6 @@ static VALUE cpu_machine(VALUE klass){
|
|
218
252
|
* CPU.freq
|
219
253
|
*
|
220
254
|
* Returns an integer indicating the speed (i.e. frequency in Mhz) of the cpu.
|
221
|
-
*
|
222
|
-
* Not supported on OS X.
|
223
|
-
*--
|
224
|
-
* Not supported on OS X currently. The sysctl() approach returns a bogus
|
225
|
-
* hard-coded value.
|
226
|
-
*
|
227
|
-
* TODO: Fix for OS X.
|
228
255
|
*/
|
229
256
|
static VALUE cpu_freq(VALUE klass){
|
230
257
|
int mhz;
|
@@ -250,8 +277,18 @@ static VALUE cpu_freq(VALUE klass){
|
|
250
277
|
#else
|
251
278
|
size_t len = sizeof(mhz);
|
252
279
|
#ifdef HAVE_SYSCTLBYNAME
|
280
|
+
#if defined(__MACH__) && defined(__APPLE__)
|
281
|
+
size_t freq;
|
282
|
+
len = sizeof(freq);
|
283
|
+
|
284
|
+
if(sysctlbyname("hw.cpufrequency", &freq, &len, 0, 0))
|
285
|
+
rb_raise(cCPUError, "error calling sysctlbyname(): %s", strerror(errno));
|
286
|
+
|
287
|
+
mhz = freq / 1000000;
|
288
|
+
#else
|
253
289
|
if(sysctlbyname("hw.clockrate", &mhz, &len, 0, 0))
|
254
290
|
rb_raise(cCPUError, "error calling sysctlbyname(): %s", strerror(errno));
|
291
|
+
#endif
|
255
292
|
#else
|
256
293
|
int mib[2];
|
257
294
|
|
@@ -281,7 +318,7 @@ void Init_cpu()
|
|
281
318
|
*/
|
282
319
|
cCPUError = rb_define_class_under(cCPU, "Error", rb_eStandardError);
|
283
320
|
|
284
|
-
/* 0.6.
|
321
|
+
/* 0.6.4: The version of the sys-cpu library */
|
285
322
|
rb_define_const(cCPU, "VERSION", rb_str_new2(SYS_CPU_VERSION));
|
286
323
|
|
287
324
|
/* Class Methods */
|
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.4: 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.4: 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.4"
|
data/lib/linux/sys/cpu.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
module Sys
|
5
5
|
|
6
6
|
# :stopdoc:
|
7
|
-
|
7
|
+
|
8
8
|
cpu_file = "/proc/cpuinfo"
|
9
9
|
cpu_hash = {}
|
10
10
|
$cpu_array = []
|
@@ -24,7 +24,7 @@ module Sys
|
|
24
24
|
$cpu_array.push(cpu_hash.dup)
|
25
25
|
cpu_hash.clear
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Turn yes/no attributes into booleans
|
29
29
|
if val == 'yes'
|
30
30
|
val = true
|
@@ -42,7 +42,7 @@ module Sys
|
|
42
42
|
class CPU
|
43
43
|
|
44
44
|
# The version of the sys-cpu library.
|
45
|
-
VERSION = '0.6.
|
45
|
+
VERSION = '0.6.4'
|
46
46
|
|
47
47
|
# :stopdoc:
|
48
48
|
|
@@ -105,7 +105,7 @@ module Sys
|
|
105
105
|
lines.each_with_index{ |line, i|
|
106
106
|
array = line.split
|
107
107
|
break unless array[0] =~ /cpu/ # 'cpu' entries always on top
|
108
|
-
|
108
|
+
|
109
109
|
# Some machines list a 'cpu' and a 'cpu0'. In this case only
|
110
110
|
# return values for the numbered cpu entry.
|
111
111
|
if lines[i].split[0] == "cpu" && lines[i+1].split[0] =~ /cpu\d/
|
data/lib/windows/sys/cpu.rb
CHANGED
@@ -9,7 +9,7 @@ module Sys
|
|
9
9
|
class Error < StandardError; end
|
10
10
|
|
11
11
|
# The version of the sys-cpu library
|
12
|
-
VERSION = '0.6.
|
12
|
+
VERSION = '0.6.4'
|
13
13
|
|
14
14
|
private
|
15
15
|
|
@@ -63,17 +63,17 @@ module Sys
|
|
63
63
|
version
|
64
64
|
voltage_caps
|
65
65
|
/
|
66
|
-
|
66
|
+
|
67
67
|
# The struct returned by the CPU.processors method
|
68
68
|
CPUStruct = Struct.new("CPUStruct", *fields) # :nodoc:
|
69
69
|
|
70
70
|
public
|
71
|
-
|
71
|
+
|
72
72
|
# Returns the +host+ CPU's architecture, or nil if it cannot be
|
73
73
|
# determined.
|
74
74
|
#
|
75
75
|
def self.architecture(host=Socket.gethostname)
|
76
|
-
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
76
|
+
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
77
77
|
begin
|
78
78
|
wmi = WIN32OLE.connect(cs)
|
79
79
|
rescue WIN32OLERuntimeError => e
|
@@ -82,14 +82,14 @@ module Sys
|
|
82
82
|
self.get_cpu_arch(wmi.Architecture)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# Returns an integer indicating the speed (i.e. frequency in Mhz) of
|
87
87
|
# +cpu_num+ on +host+, or the localhost if no +host+ is specified.
|
88
88
|
# If +cpu_num+ +1 is greater than the number of cpu's on your system
|
89
89
|
# or this call fails for any other reason, a Error is raised.
|
90
90
|
#
|
91
91
|
def self.freq(cpu_num = 0, host = Socket.gethostname)
|
92
|
-
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'"
|
92
|
+
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'"
|
93
93
|
begin
|
94
94
|
wmi = WIN32OLE.connect(cs)
|
95
95
|
rescue WIN32OLERuntimeError => e
|
@@ -98,7 +98,7 @@ module Sys
|
|
98
98
|
return wmi.CurrentClockSpeed
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
# Returns the load capacity for +cpu_num+ on +host+, or the localhost
|
103
103
|
# if no host is specified, averaged to the last second. Processor
|
104
104
|
# loading refers to the total computing burden for each processor at
|
@@ -108,20 +108,20 @@ module Sys
|
|
108
108
|
# one of the Win32_Perf* classes in the future.
|
109
109
|
#
|
110
110
|
def self.load_avg(cpu_num = 0, host = Socket.gethostname)
|
111
|
-
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'"
|
111
|
+
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu#{cpu_num}'"
|
112
112
|
begin
|
113
113
|
wmi = WIN32OLE.connect(cs)
|
114
114
|
rescue WIN32OLERuntimeError => e
|
115
115
|
raise Error, e
|
116
116
|
else
|
117
117
|
return wmi.LoadPercentage
|
118
|
-
end
|
118
|
+
end
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
# Returns a string indicating the cpu model, e.g. Intel Pentium 4.
|
122
122
|
#
|
123
123
|
def self.model(host = Socket.gethostname)
|
124
|
-
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
124
|
+
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
125
125
|
begin
|
126
126
|
wmi = WIN32OLE.connect(cs)
|
127
127
|
rescue WIN32OLERuntimeError => e
|
@@ -130,7 +130,7 @@ module Sys
|
|
130
130
|
return wmi.Name
|
131
131
|
end
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
# Returns an integer indicating the number of cpu's on the system.
|
135
135
|
#--
|
136
136
|
# This (oddly) requires a different class.
|
@@ -145,7 +145,7 @@ module Sys
|
|
145
145
|
return wmi.NumberOfProcessors
|
146
146
|
end
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
# Returns a CPUStruct for each CPU on +host+, or the localhost if no
|
150
150
|
# +host+ is specified. A CPUStruct contains the following members:
|
151
151
|
#
|
@@ -250,13 +250,13 @@ module Sys
|
|
250
250
|
self.get_voltage_caps(cpu.VoltageCaps)
|
251
251
|
)
|
252
252
|
}
|
253
|
-
end
|
253
|
+
end
|
254
254
|
end
|
255
255
|
|
256
256
|
# Returns a string indicating the type of processor, e.g. GenuineIntel.
|
257
257
|
#
|
258
258
|
def self.type(host = Socket.gethostname)
|
259
|
-
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
259
|
+
cs = BASE_CS + "//#{host}/root/cimv2:Win32_Processor='cpu0'"
|
260
260
|
begin
|
261
261
|
wmi = WIN32OLE.connect(cs)
|
262
262
|
rescue WIN32OLERuntimeError => e
|
@@ -265,9 +265,9 @@ module Sys
|
|
265
265
|
return wmi.Manufacturer
|
266
266
|
end
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
private
|
270
|
-
|
270
|
+
|
271
271
|
# Convert the ConfigManagerErrorCode number to its corresponding string
|
272
272
|
# Note that this value returns nil on my system.
|
273
273
|
#
|
@@ -391,7 +391,7 @@ module Sys
|
|
391
391
|
return nil
|
392
392
|
end
|
393
393
|
end
|
394
|
-
|
394
|
+
|
395
395
|
# Convert an cpu architecture number to a string
|
396
396
|
def self.get_cpu_arch(num)
|
397
397
|
case num
|
@@ -411,7 +411,7 @@ module Sys
|
|
411
411
|
return nil
|
412
412
|
end
|
413
413
|
end
|
414
|
-
|
414
|
+
|
415
415
|
# convert an Availability number into a string
|
416
416
|
def self.get_availability(num)
|
417
417
|
case num
|
@@ -459,9 +459,9 @@ module Sys
|
|
459
459
|
return "Quiesced"
|
460
460
|
else
|
461
461
|
return nil
|
462
|
-
end
|
462
|
+
end
|
463
463
|
end
|
464
|
-
|
464
|
+
|
465
465
|
# convert CpuStatus to a string form. Note that values 5 and 6 are
|
466
466
|
# skipped because they're reserved.
|
467
467
|
def self.get_status(num)
|
@@ -482,7 +482,7 @@ module Sys
|
|
482
482
|
return nil
|
483
483
|
end
|
484
484
|
end
|
485
|
-
|
485
|
+
|
486
486
|
# Convert a family number into the equivalent string
|
487
487
|
def self.get_family(num)
|
488
488
|
case num
|
@@ -696,7 +696,7 @@ module Sys
|
|
696
696
|
return nil
|
697
697
|
end
|
698
698
|
end
|
699
|
-
|
699
|
+
|
700
700
|
# Convert power management capabilities number to its equivalent string
|
701
701
|
def self.get_pmc(num)
|
702
702
|
case num
|
@@ -720,7 +720,7 @@ module Sys
|
|
720
720
|
return nil
|
721
721
|
end
|
722
722
|
end
|
723
|
-
|
723
|
+
|
724
724
|
# Convert a processor type into its equivalent string
|
725
725
|
def self.get_processor_type(num)
|
726
726
|
case num
|
@@ -740,7 +740,7 @@ module Sys
|
|
740
740
|
return nil
|
741
741
|
end
|
742
742
|
end
|
743
|
-
|
743
|
+
|
744
744
|
# Convert an upgrade method into its equivalent string
|
745
745
|
def self.get_upgrade_method(num)
|
746
746
|
case num
|
@@ -772,7 +772,7 @@ module Sys
|
|
772
772
|
return nil
|
773
773
|
end
|
774
774
|
end
|
775
|
-
|
775
|
+
|
776
776
|
# Convert return values to voltage cap values (floats)
|
777
777
|
def self.get_voltage_caps(num)
|
778
778
|
case num
|
data/sys-cpu.gemspec
CHANGED
@@ -2,20 +2,19 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'sys-cpu'
|
5
|
-
spec.version = '0.6.
|
5
|
+
spec.version = '0.6.4'
|
6
6
|
spec.author = 'Daniel J. Berger'
|
7
7
|
spec.email = 'djberg96 at nospam at gmail dot com'
|
8
8
|
spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
9
9
|
spec.platform = Gem::Platform::RUBY
|
10
10
|
spec.summary = 'A Ruby interface for providing CPU information'
|
11
|
-
spec.has_rdoc = true
|
12
11
|
spec.test_file = 'test/test_sys_cpu.rb'
|
13
12
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
13
|
|
15
14
|
spec.rubyforge_project = 'sysutils'
|
16
15
|
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
|
17
16
|
|
18
|
-
spec.add_development_dependency('test-unit', '>= 2.
|
17
|
+
spec.add_development_dependency('test-unit', '>= 2.1.2')
|
19
18
|
|
20
19
|
spec.description = <<-EOF
|
21
20
|
The sys-cpu library provides an interface for gathering information
|
@@ -25,11 +24,11 @@ Gem::Specification.new do |spec|
|
|
25
24
|
|
26
25
|
case Config::CONFIG['host_os']
|
27
26
|
when /hpux/i
|
28
|
-
|
27
|
+
spec.extra_rdoc_files += ['ext/hpux/hpux.c']
|
29
28
|
when /sunos|solaris/i
|
30
|
-
|
29
|
+
spec.extra_rdoc_files += ['ext/sunos/sunos.c']
|
31
30
|
when /bsd|darwin|mach|osx/i
|
32
|
-
|
31
|
+
spec.extra_rdoc_files += ['ext/bsd/bsd.c']
|
33
32
|
end
|
34
33
|
|
35
34
|
case Config::CONFIG['host_os']
|
@@ -37,10 +36,14 @@ Gem::Specification.new do |spec|
|
|
37
36
|
spec.require_paths = ['lib', 'lib/windows']
|
38
37
|
spec.extra_rdoc_files << 'lib/windows/sys/cpu.rb'
|
39
38
|
spec.platform = Gem::Platform::CURRENT
|
39
|
+
spec.platform.cpu = 'universal'
|
40
|
+
spec.platform.version = nil
|
41
|
+
spec.original_platform = spec.platform
|
40
42
|
when /linux/i
|
41
43
|
spec.require_paths = ['lib', 'lib/linux']
|
42
44
|
spec.extra_rdoc_files << 'lib/linux/sys/cpu.rb'
|
43
|
-
spec.platform = Gem::Platform
|
45
|
+
spec.platform = Gem::Platform.new('universal-linux')
|
46
|
+
spec.original_platform = spec.platform
|
44
47
|
else
|
45
48
|
spec.extensions = ['ext/extconf.rb']
|
46
49
|
end
|
data/test/test_sys_cpu_bsd.rb
CHANGED
@@ -24,7 +24,6 @@ class TC_Sys_CPU_BSD < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_cpu_freq
|
27
|
-
omit_if(Config::CONFIG['host_os'] =~ /darwin/i, 'CPU.freq test skipped on OS X')
|
28
27
|
assert_respond_to(CPU, :freq)
|
29
28
|
assert_nothing_raised{ CPU.freq }
|
30
29
|
assert_kind_of(Integer, CPU.freq)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-cpu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2011-09-27 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: test-unit
|
@@ -26,12 +25,12 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 15
|
30
29
|
segments:
|
31
30
|
- 2
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 2.
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
version: 2.1.2
|
35
34
|
type: :development
|
36
35
|
version_requirements: *id001
|
37
36
|
description: " The sys-cpu library provides an interface for gathering information\n about your system's processor(s). Information includes speed, type,\n and load average.\n"
|
@@ -76,7 +75,6 @@ files:
|
|
76
75
|
- test/test_sys_cpu_sunos.rb
|
77
76
|
- test/test_sys_cpu_version.rb
|
78
77
|
- test/test_sys_cpu_windows.rb
|
79
|
-
has_rdoc: true
|
80
78
|
homepage: http://www.rubyforge.org/projects/sysutils
|
81
79
|
licenses: []
|
82
80
|
|
@@ -106,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
104
|
requirements: []
|
107
105
|
|
108
106
|
rubyforge_project: sysutils
|
109
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.8.10
|
110
108
|
signing_key:
|
111
109
|
specification_version: 3
|
112
110
|
summary: A Ruby interface for providing CPU information
|