sys-cpu 0.6.1-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,131 @@
1
+ == 0.6.1 - 4-Jan-2009
2
+ * Fix for OS X 10.5.x. Thanks go to Victor Costan for the spot and the patch.
3
+ * Updated the gemspec and some other minor changes.
4
+ * On MS Windows the impersonation level is now explicitly set to 'impersonate'
5
+ to avoid issues where systems might be using an older version of WMI.
6
+
7
+ == 0.6.0 - 26-Apr-2007
8
+ * Added support for most BSD flavors, including OS X. The freebsd.c file is
9
+ now just bsd.c.
10
+ * The CPU.type method for Solaris has been changed to CPU.cpu_type to avoid
11
+ conflicting with the Object.type method.
12
+ * Added a Rakefile. There are now tasks for building, testing and installing,
13
+ among other things. Run 'rake -T' to check your options.
14
+ * Many internal directory layout changes - C source files are now under the
15
+ 'ext' directory.
16
+ * Improved RDoc comments in the C source files.
17
+ * Changed CPUError to CPU::Error.
18
+
19
+ == 0.5.5 - 17-Nov-2006
20
+ * Fixed a bug in the Linux version where there could be a key but no
21
+ associated value, causing a String#strip! call to fail. Now the value is
22
+ simply left at nil.
23
+ * Refactored the CPU.processors method on Linux, including the removal of '?'
24
+ from the CPUStruct members for the boolean methods (Ruby doesn't like them).
25
+ * Minor tweaks and updates to the documentation, including the README.
26
+ * Modified the gemspec so that it sets the platform properly for Linux
27
+ and Windows.
28
+
29
+ == 0.5.4 - 12-Jul-2006
30
+ * Added a gemspec (and a gem on RubyForge).
31
+ * The CPU.architecture method on HP-UX now returns nil if it cannot be
32
+ determined instead of "Unknown" for consistency with the other
33
+ platforms.
34
+ * Inlined the RDoc and made some minor cosmetic source code changes.
35
+
36
+ == 0.5.3 - 4-May-2006
37
+ * Fixed in a bug in the Solaris version where CPU.load_avg returned bad values
38
+ when compiled in 64 bit mode. Thanks go to James Hranicky for the spot and
39
+ both James Hranicky and Peter Tribble (via comp.unix.solaris) for patches.
40
+ * Made some modifications to the test suite. You know longer need to know
41
+ which test suite to run. All platforms now use 'ts_all.rb', which will run
42
+ the appropriate test case behind the scenes.
43
+
44
+ == 0.5.2 - 24-Jun-2005
45
+ * Bug fixed on Linux where empty lines could cause problems. This affected
46
+ both the install.rb and linux.rb files, though it only seems to have been
47
+ an issue on the 2.6+ kernel.
48
+ * Altered the behavior of the CPU.cpu_stats method on Linux. Now, only the
49
+ numbered cpu entries return associated data, unless the numberless entry
50
+ is the only entry.
51
+ * Added a sample program for Linux under the 'examples' directory.
52
+
53
+ == 0.5.1 - 5-May-2005
54
+ * Fixed a potential bug in the FreeBSD version of CPU.model.
55
+ * Eliminated some warnings in the FreeBSD version.
56
+ * Moved examples directory to the toplevel package directory.
57
+ * Renamed and updated the sample scripts.
58
+ * Added a sample script for FreeBSD.
59
+ * Removed the INSTALL file. That information is now included in the README.
60
+ * Made the CHANGES, README, and .txt files rdoc friendly.
61
+ * The dynamic documentation generation for Linux has been altered. Anything
62
+ relating to rd2 has been removed. The doc file generated is now
63
+ doc/linux.txt.
64
+ * Some $LOAD_PATH setup changes in the unit tests.
65
+
66
+ == 0.5.0 - 26-Jun-2004
67
+ * Now requires Ruby 1.8.0 or later.
68
+ * FreeBSD support added.
69
+ * Replaced 'CPUException' with 'CPUError'
70
+ * The MS Windows version has been completely revamped to use WMI instead of
71
+ the C API. Some method names have changed and some methods have been
72
+ dropped entirely. Please see the documentation for details.
73
+ * Corresponding documentation updates and test suite changes.
74
+ * Sample programs have been moved to doc/examples.
75
+ * Installation procedure somewhat revamped.
76
+ * No longer autogenerates test file.
77
+ * The .html files have been removed. You can generate the html on your own
78
+ if you like.
79
+
80
+ == 0.4.0 - 18-Sep-2003
81
+ * Added MS Windows support
82
+ * Changed some method names. The "cpu" has been dropped from most method
83
+ names. See documentation for details.
84
+ * The state() and freq() methods (where supported) now assume a default
85
+ value of zero.
86
+ * More unit tests added.
87
+ * Fixed minor issue with test.rb for those without TestUnit installed.
88
+ * Fixed issue with linux.rb file being auto-installed on non-Linux platforms.
89
+ * Minor API change for the load_avg() method on HP-UX. It now accepts a
90
+ CPU number as an argument.
91
+
92
+ == 0.3.1 - 16-Jul-2003
93
+ * Fixed a bug in the Solaris version that was using up and not
94
+ freeing file descriptors.
95
+ * Added html doc for Solaris under doc directory.
96
+ * Minor changes to test_hpux.rb and test_sunos.rb
97
+ * Minor README changes.
98
+
99
+ == 0.3.0 - 30-Jun-2003
100
+ * Added HP-UX support
101
+ * Removed the VERSION class method. Use the constant instead
102
+ * Changed license to "Artistic"
103
+ * Moved version info into its own file for convenience
104
+ * Some minor mods to the test suites
105
+ * Modified extconf.rb, moving some of the dynamic test generation
106
+ into separate files
107
+
108
+ == 0.2.2 - 25-Mar-2003
109
+ * fpu_type and cpu_type now return nil if not found (Solaris)
110
+ * CPUException is now a direct subclass of StandardError
111
+ * Modified extconf.rb script
112
+ * Minor doc updates
113
+ * Added another test to the solaris test suite
114
+ * Important note added to INSTALL file
115
+
116
+ == 0.2.1 - 12-Mar-2003
117
+ * Added the cpu_stats() class method for Linux, which contains the
118
+ data from the 'cpu' lines of /proc/stat
119
+ * Minor fix for extconf.rb (thanks Michael Granger)
120
+ * Some tests added to Linux test suite
121
+ * MANIFEST correction
122
+
123
+ == 0.2.0 - 13-Feb-2003
124
+ * Linux support added (pure Ruby only)
125
+ * Many changes to extconf.rb to support Linux version
126
+ * sys-uname prerequisite dropped
127
+ * rd2 documentation now kept separate from source
128
+
129
+ == 0.1.0 - 3-Feb-2003
130
+ * Initial release
131
+ * Currently supports Solaris (only)
data/MANIFEST ADDED
@@ -0,0 +1,28 @@
1
+ * install.rb
2
+ * MANIFEST
3
+ * CHANGES
4
+ * Rakefile
5
+ * README
6
+ * sys-cpu.gemspec
7
+ * doc/bsd.txt
8
+ * doc/hpux.txt
9
+ * doc/linux.txt
10
+ * doc/sunos.txt
11
+ * doc/windows.txt
12
+ * examples/test_cpu_freebsd.rb
13
+ * examples/test_cpu_hpux.rb
14
+ * examples/test_cpu_linux.rb
15
+ * examples/test_cpu_sunos.rb
16
+ * examples/test_cpu_windows.rb
17
+ * ext/extconf.rb
18
+ * ext/version.h
19
+ * ext/bsd/bsd.c
20
+ * ext/hpux/hpux.c
21
+ * ext/sunos/sunos.c
22
+ * lib/sys/linux.rb
23
+ * lib/sys/windows.rb
24
+ * test/tc_bsd.rb
25
+ * test/tc_hpux.rb
26
+ * test/tc_sunos.rb
27
+ * test/tc_linux.rb
28
+ * test/tc_windows.rb
data/README ADDED
@@ -0,0 +1,79 @@
1
+ = Description
2
+ A Ruby interface for getting cpu information.
3
+
4
+ = Installation
5
+ == Standard Installation
6
+ rake test (optional)
7
+ rake install (non-gem)
8
+ == Gem installation
9
+ rake test (optional)
10
+ ruby sys-cpu.gemspec
11
+ gem install sys-cpu-X.Y.Z.gem # where 'X.Y.Z' corresponds to the version.
12
+
13
+ = Notes
14
+ === All Platforms
15
+ As of version 0.5.0 Ruby 1.8.0 or later is required. It may work with
16
+ earlier versions, but I will not support it.
17
+
18
+ === Solaris
19
+ Currently there is no 'processors()' iterative method for multi-cpu systems.
20
+ I plan to add it this in a future release.
21
+
22
+ === OS X
23
+ The CPU.freq method is not supported at the moment. The sysctl() approach
24
+ returns a bogus, hard coded value of some sort. I suspect it's possible
25
+ by using kernel modules via kldload(), but I'm not sure how yet.
26
+
27
+ === Linux
28
+ This is pure Ruby. This version reads information out of /proc/cpuinfo and
29
+ /proc/loadavg, so if /proc isn't mounted it won't work.
30
+
31
+ The key-value information in /proc/cpuinfo is stored internally (i.e. in
32
+ memory) as an array of hashes when you first 'require' this package. This
33
+ overhead is exceptionally minimal, given that your average cpuinfo file
34
+ contains less than 1k of text (and I don't store whitespace or newlines).
35
+
36
+ The text documentation for Linux is dynamically generated during the
37
+ build process because the fields vary depending on your setup. So, don't
38
+ look at it until *after* you've installed it. You will see a doc/linux.txt
39
+ file after you run 'rake install' (via install.rb).
40
+
41
+ === HP-UX
42
+ Unlike other platforms, you can get load averages for an individual cpu (in
43
+ multi-cpu systems). See documentation for more details.
44
+
45
+ === MS Windows
46
+ This is a pure Ruby implementation using the win32ole package + WMI. The C
47
+ version has been scrapped.
48
+
49
+ As of version 0.5.0, the CPU.usage method has been removed in favor of the
50
+ CPU.load_avg method. This does not (currently) use a perf counter, so there
51
+ is no longer any delay. Also, the 'processors' method has been
52
+ added and the 'supported' method has been dropped. See the documentation
53
+ for other changes.
54
+
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.
58
+
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.
63
+
64
+ = License
65
+ Ruby's.
66
+
67
+ = Copyright
68
+ (C) 2003-2007 Daniel J. Berger
69
+ All Rights Reserved
70
+
71
+ = Warranty
72
+ This package is provided "as is" and without any express or
73
+ implied warranties, including, without limitation, the implied
74
+ warranties of merchantability and fitness for a particular purpose.
75
+
76
+ = Author
77
+ Daniel J. Berger
78
+ djberg96 at nospam at gmail dot com
79
+ imperator on IRC (irc.freenode.net)
data/doc/bsd.txt ADDED
@@ -0,0 +1,67 @@
1
+ = Description
2
+ Sys::CPU - An interface for various cpu statistics
3
+
4
+ = Synopsis
5
+ require "sys/cpu"
6
+ include Sys
7
+
8
+ # BSD and OS X
9
+ puts "Architecture: " + CPU.architecture
10
+ puts "Machine: " + CPU.machine
11
+ puts "Mhz: " + CPU.cpu_freq.to_s
12
+ puts "Number of cpu's on this system: " + CPU.num_cpu.to_s
13
+ puts "CPU model: " + CPU.model
14
+ puts "Load averages: " + CPU.load_avg.join(", ")
15
+
16
+ = Constants
17
+ VERSION
18
+ Returns the current version number for this package.
19
+
20
+ = Class Methods
21
+ CPU.architecture
22
+ Returns the cpu's architecture.
23
+
24
+ CPU.freq
25
+ Returns an integer indicating the speed (i.e. frequency in Mhz) of
26
+ the cpu.
27
+
28
+ Not supported on OS X.
29
+
30
+ CPU.load_avg
31
+ Returns an array of three floats indicating the 1, 5 and 15 minute load
32
+ average.
33
+
34
+ CPU.machine
35
+ Returns the class of cpu (probably identical to the architecture).
36
+
37
+ CPU.model
38
+ Returns a string indicating the cpu model.
39
+
40
+ CPU.num_cpu
41
+ Returns an integer indicating the number of cpu's on the system.
42
+
43
+ = Error Classes
44
+ CPU::Error < StandardError
45
+ Raised is response to internal function errors, usually relating to an
46
+ invalid cpu number.
47
+
48
+ = Known Bugs
49
+ None known. Please post bug reports to the SourceForge home page at
50
+ http://www.rubyforge.org/projects/sysutils
51
+
52
+ = Copyright
53
+ (C) 2003-2007 Daniel J. Berger
54
+ All Rights Reserved
55
+
56
+ = Warranty
57
+ This package is provided "as is" and without any express or
58
+ implied warranties, including, without limitation, the implied
59
+ warranties of merchantability and fitness for a particular purpose.
60
+
61
+ = License
62
+ Ruby's
63
+
64
+ = Author
65
+ Daniel J. Berger
66
+ djberg96 at nospam at gmail dot com
67
+ imperator on IRC (Freenode)
data/doc/hpux.txt ADDED
@@ -0,0 +1,75 @@
1
+ = Description
2
+ Sys::CPU - An interface for various cpu statistics
3
+
4
+ = Synopsis
5
+ require "sys/cpu"
6
+ include Sys
7
+
8
+ puts "Mhz: " + CPU.cpu_freq.to_s
9
+ puts "State: " + CPU.state(0)
10
+ puts "Number of cpu's on this system: " + CPU.num_cpu.to_s
11
+ puts "Number of active cpu's: " + CPU.num_active_cpu.to_s
12
+ puts "Load averages: " + CPU.load_avg.join(", ")
13
+
14
+ = Constants
15
+ VERSION
16
+ Returns the current version number for this package.
17
+
18
+ = Class Methods
19
+ CPU.architecture
20
+ Returns the cpu architecture, e.g. PA RISC 1.2, etc.
21
+
22
+ CPU.freq(cpu_num=0)
23
+ Returns an integer indicating the speed (i.e. frequency in Mhz) of
24
+ the cpu.
25
+
26
+ CPU.load_avg
27
+ CPU.load_avg(cpu_num)
28
+ CPU.load_avg{ |cpu| ... }
29
+
30
+ In non-block form returns an array of three floats indicating the 1, 5
31
+ and 15 minute overall load average.
32
+
33
+ In block form, it returns an array of three floats indicating the 1, 5
34
+ and 15 minute load average for each cpu. Only useful on multi-cpu
35
+ systems.
36
+
37
+ If 'cpu_num' is provided, returns the load average (as a 3-element
38
+ array) for that cpu only.
39
+
40
+ You cannot provide a cpu number and use block form at the same time.
41
+
42
+ CPU.num_cpu
43
+ Returns an integer indicating the number of cpu's on the system.
44
+
45
+ CPU.num_active_cpu
46
+ Returns an integer indicating the number of active cpu's on the system.
47
+
48
+ = Error Classes
49
+ CPU::Error < StandardError
50
+ Raised is response to internal function errors, usually relating to an
51
+ invalid cpu number.
52
+
53
+ = Known Bugs
54
+ No bugs known. Please log any bugs at
55
+ http://www.rubyforge.org/projects/sysutils
56
+
57
+ = Future Plans
58
+ Add cpu model and type
59
+
60
+ = Copyright
61
+ (C) 2003-2007 Daniel J. Berger
62
+ All Rights Reserved
63
+
64
+ = Warranty
65
+ This package is provided "as is" and without any express or
66
+ implied warranties, including, without limitation, the implied
67
+ warranties of merchantability and fitness for a particular purpose.
68
+
69
+ = License
70
+ Ruby's
71
+
72
+ = Author
73
+ Daniel J. Berger
74
+ djberg96 at nospam at gmail dot com
75
+ imperator on IRC (Freenode)
data/doc/linux.txt ADDED
@@ -0,0 +1,41 @@
1
+ == Description
2
+ Sys::CPU - An interface for various cpu statistics
3
+
4
+ == Synopsis
5
+ require "sys/cpu"
6
+ include Sys
7
+
8
+ CPU.processors{ |cs|
9
+ cs.members.each{ |m|
10
+ puts "#{m}: " + cs[m].to_s
11
+ }
12
+ }
13
+
14
+ CPU.bogomips(1) # -> returns bogomips for cpu #2
15
+
16
+ == Notes
17
+ Portions of this documentation built dynamically
18
+
19
+ == Constants
20
+ VERSION
21
+ Returns the current version number for this package as a String.
22
+
23
+ == Class Methods
24
+ CPU.load_avg
25
+ Returns an array of three floats indicating the 1, 5 and 15 minute load
26
+ average.
27
+
28
+ CPU.cpu_stats
29
+ Returns a hash, with the cpu number as the key and an array as the value.
30
+ The array contains the number of seconds that the system spent in
31
+ user mode, user mode with low priority (nice), system mode, and the
32
+ idle task, respectively, for that cpu.
33
+
34
+ CPU.processors{ |cpu struct| block }
35
+ Calls the block for each processor on your system, passing a CPUStruct as the
36
+ parameter.
37
+
38
+ The exact members of the CPUStruct are the same as the class method names, except
39
+ for CPU.processors (although you may optionally omit the "?" when referring to a
40
+ struct member). These were determined when you installed this package because they
41
+ vary from one chip architecture to another.
data/doc/sunos.txt ADDED
@@ -0,0 +1,78 @@
1
+ = Description
2
+ Sys::CPU - An interface for various cpu statistics
3
+
4
+ = Synopsis
5
+ require "sys/cpu"
6
+ include Sys
7
+
8
+ # Solaris
9
+ puts "Mhz: " + CPU.cpu_freq(0).to_s
10
+ puts "State: " + CPU.state(0)
11
+ puts "Number of cpu's on this system: " + CPU.num_cpu.to_s
12
+ puts "CPU type: " + CPU.type
13
+ puts "FPU type: " + CPU.fpu_type
14
+ puts "CPU model: " + CPU.model
15
+ puts "Load averages: " + CPU.load_avg.join(", ")
16
+
17
+ = Constants
18
+ VERSION
19
+ Returns the current version number for this package.
20
+
21
+ = Class Methods
22
+ CPU.freq(cpu_num=0)
23
+ Returns an integer indicating the speed (i.e. frequency in Mhz) of
24
+ 'cpu_num', or CPU 0 if no number is provided.
25
+
26
+ CPU.type
27
+ Returns a string indicating the type of processor. This is the
28
+ architecture (e.g. sparcv9), not the exact model (e.g. Ultra-IIe).
29
+ Returns nil if not found.
30
+
31
+ CPU.fpu_type
32
+ Returns a string indicating the type of floating point unit, or nil if
33
+ not found.
34
+
35
+ CPU.load_avg
36
+ Returns an array of three floats indicating the 1, 5 and 15 minute load
37
+ average.
38
+
39
+ CPU.model
40
+ Returns a string indicating the cpu model. For now, this is the
41
+ architecture type, rather than the exact model. However, see the
42
+ 'Future Plans' section below.
43
+
44
+ CPU.num_cpu
45
+ Returns an integer indicating the number of cpu's on the system.
46
+
47
+ CPU.state(cpu_num)
48
+ Returns a string indicating the cpu state of 'cpu_num'.
49
+
50
+ = Error Classes
51
+ CPU::Error < StandardError
52
+ Raised is response to internal function errors, usually relating to an
53
+ invalid cpu number.
54
+
55
+ = Known Bugs
56
+ None known. Please post bug reports to the SourceForge home page at
57
+ http://www.rubyforge.org/projects/sysutils
58
+
59
+ = Future Plans
60
+ Add more information, such as what prtdiag shows.
61
+ Get the model() method to display more specific information.
62
+
63
+ = Copyright
64
+ (C) 2003-2007 Daniel J. Berger
65
+ All Rights Reserved
66
+
67
+ = Warranty
68
+ This package is provided "as is" and without any express or
69
+ implied warranties, including, without limitation, the implied
70
+ warranties of merchantability and fitness for a particular purpose.
71
+
72
+ = License
73
+ Ruby's
74
+
75
+ = Author
76
+ Daniel J. Berger
77
+ djberg96 at nospam at gmail dot com
78
+ imperator on IRC (Freenode)
data/doc/windows.txt ADDED
@@ -0,0 +1,152 @@
1
+ = Description
2
+ Sys::CPU - An interface for various cpu statistics
3
+
4
+ = Synopsis
5
+ require "sys/cpu"
6
+ include Sys
7
+
8
+ CPU.processors{ |cs|
9
+ cs.members.each{ |m|
10
+ puts "#{m}: " + cs[m].to_s
11
+ }
12
+ }
13
+
14
+ puts "CPU Speed (Frequency): " + CPU.freq(0).to_s
15
+ puts "Load avg: " + CPU.load_avg.to_s
16
+ puts "Num CPU: " + CPU.num_cpu.to_s
17
+ puts "Type: " + CPU.type
18
+ puts "Model: " + CPU.model
19
+ puts "Architecture: " + CPU.architecture
20
+
21
+ = Constants
22
+ VERSION
23
+ Returns the current version number for this package.
24
+
25
+ = Class Methods
26
+ CPU.architecture(host=localhost)
27
+ Returns the architecture of the cpu, e.g. x86 Family 15 Model 2
28
+
29
+ CPU.freq(cpu_num=0, host=localhost)
30
+ Returns an integer indicating the speed (i.e. frequency in Mhz) of
31
+ 'cpu_num'. If cpu_num+1 is greater than the number of cpu's on
32
+ your system, or this call fails for any other reason, a CPUError
33
+ is raised.
34
+
35
+ CPU.load_avg(host=localhost)
36
+ Returns the load capacity of each processor, averaged to the last second.
37
+ Processor loading refers to the total computing burden for each
38
+ processor at one time.
39
+
40
+ Note that this attribute is actually the LoadPercentage. I may use
41
+ one of the Win32_Perf* classes in the future.
42
+
43
+ CPU.model(host=localhost)
44
+ Returns a string indicating the cpu model, e.g. Intel Pentium 4
45
+
46
+ CPU.num_cpu(host=localhost)
47
+ Returns an integer indicating the number of cpu's on the system.
48
+
49
+ CPU.processors(host=localhost){ |cpu| ... }
50
+ Returns a CPUStruct for each CPU on the system containing the following
51
+ members:
52
+
53
+ * address_width
54
+ * architecture
55
+ * availability
56
+ * caption
57
+ * config_manager_error_code
58
+ * config_manager_user_config
59
+ * cpu_status
60
+ * creation_class_name
61
+ * freq
62
+ * voltage
63
+ * data_width
64
+ * description
65
+ * device_id
66
+ * error_cleared?
67
+ * error_description
68
+ * ext_clock
69
+ * family
70
+ * install_date
71
+ * l2_cache_size
72
+ * l2_cache_speed
73
+ * last_error_code
74
+ * level
75
+ * load_avg
76
+ * manufacturer
77
+ * max_clock_speed
78
+ * name
79
+ * other_family_description
80
+ * pnp_device_id
81
+ * power_management_supported?
82
+ * power_management_capabilities
83
+ * processor_id
84
+ * processor_type
85
+ * revision
86
+ * role
87
+ * socket_designation
88
+ * status
89
+ * status_info
90
+ * stepping
91
+ * system_creation_class_name
92
+ * system_name
93
+ * unique_id
94
+ * upgrade_method
95
+ * version
96
+ * voltage_caps
97
+
98
+ Note that not all of these members will necessarily be defined. See the
99
+ NOTES section below.
100
+
101
+ CPU.type(host=localhost)
102
+ Returns a string indicating the type of processor, e.g. GenuineIntel.
103
+
104
+ = Exception Classes
105
+ CPU::Error < StandardError
106
+ Raised is response to internal function errors, most likely to be raised
107
+ in the event that in invalid cpu number is provided for the 'freq'
108
+ method.
109
+
110
+ = Notes
111
+ Some of the CPUStruct members may be nil. As far as I can tell, this
112
+ means that Windows is unable to determine the value for the attribute due
113
+ to your BIOS and/or BIOS settings. There is nothing clear in the
114
+ documentation I could find for this, however.
115
+
116
+ The 'family' attribute may contain the trademark symbol.
117
+
118
+ The 'status_info' attribute was not converted to a string because the
119
+ 'status' attribute already is a string. I'm not even sure why MS has both
120
+ versions.
121
+
122
+ The 'system_name' attribute appears to be the hostname. I have no idea
123
+ why this is included as part of the CPU information, but there you go.
124
+
125
+ See http://tinyurl.com/2mros (and click on 'Win32_Processor' in the left
126
+ frame) for a list of attributes and their meaning. Link courtesy of
127
+ tinyurl.com.
128
+
129
+ = Known Bugs
130
+ No bugs known. Please log any bugs at
131
+ http://www.rubyforge.org/projects/sysutils
132
+
133
+ = Future Plans
134
+ Add more detailed CPU usage information via the
135
+ Win32_PerfFormattedData_PerfOS_Processor class.
136
+
137
+ = Copyright
138
+ (C) 2003-2007 Daniel J. Berger
139
+ All Rights Reserved
140
+
141
+ = Warranty
142
+ This package is provided "as is" and without any express or
143
+ implied warranties, including, without limitation, the implied
144
+ warranties of merchantability and fitness for a particular purpose.
145
+
146
+ = License
147
+ Ruby's
148
+
149
+ = Author
150
+ Daniel J. Berger
151
+ djberg96 at nospam at gmail dot com
152
+ imperator/rubyhacker1 on IRC (Freenode)
data/lib/sys/cpu.rb ADDED
@@ -0,0 +1,105 @@
1
+ ##########################################################
2
+ # linux.rb (sys-cpu) - pure Ruby version for Linux
3
+ ##########################################################
4
+ module Sys
5
+ cpu_file = "/proc/cpuinfo"
6
+ cpu_hash = {}
7
+ $cpu_array = []
8
+
9
+ # Parse the info out of the /proc/cpuinfo file
10
+ IO.foreach(cpu_file){ |line|
11
+ line.strip!
12
+ next if line.empty?
13
+
14
+ key, val = line.split(":")
15
+ key.strip!
16
+ key.gsub!(/\s+/,"_")
17
+ key.downcase!
18
+ val.strip! if val
19
+
20
+ if cpu_hash.has_key?(key)
21
+ $cpu_array.push(cpu_hash.dup)
22
+ cpu_hash.clear
23
+ end
24
+
25
+ # Turn yes/no attributes into booleans
26
+ if val == 'yes'
27
+ val = true
28
+ elsif val == 'no'
29
+ val = false
30
+ end
31
+ cpu_hash[key] = val
32
+ }
33
+
34
+ $cpu_array.push(cpu_hash)
35
+
36
+ class CPU
37
+
38
+ VERSION = '0.6.1'
39
+ CPUStruct = Struct.new("CPUStruct", *$cpu_array.first.keys)
40
+
41
+ # In block form, yields a CPUStruct for each CPU on the system. In
42
+ # non-block form, returns an Array of CPUStruct's.
43
+ #
44
+ # The exact members of the struct vary on Linux systems.
45
+ #
46
+ def self.processors
47
+ array = []
48
+ $cpu_array.each{ |hash|
49
+ struct = CPUStruct.new
50
+ struct.members.each{ |m| struct.send("#{m}=", hash[m]) }
51
+ if block_given?
52
+ yield struct
53
+ else
54
+ array << struct
55
+ end
56
+ }
57
+ array unless block_given?
58
+ end
59
+
60
+ #--
61
+ # Create singleton methods for each of the attributes
62
+ #
63
+ def self.method_missing(id,arg=0)
64
+ rv = $cpu_array[arg][id.to_s]
65
+ if rv.nil?
66
+ id = id.to_s + "?"
67
+ rv = $cpu_array[arg][id]
68
+ end
69
+ rv
70
+ end
71
+
72
+ # Returns a 3 element Array corresponding to the 1, 5 and 15 minute
73
+ # load average for the system.
74
+ #
75
+ def self.load_avg
76
+ load_avg_file = "/proc/loadavg"
77
+ IO.readlines(load_avg_file).first.split[0..2].map{|e| e.to_f}
78
+ end
79
+
80
+ # Returns a hash of arrays that contain the number of seconds that the
81
+ # system spent in user mode, user mode with low priority (nice), system
82
+ # mode, and the idle task, respectively.
83
+ #
84
+ def self.cpu_stats
85
+ cpu_stat_file = "/proc/stat"
86
+ hash = {} # Hash needed for multi-cpu systems
87
+
88
+ lines = IO.readlines(cpu_stat_file)
89
+ lines.each_with_index{ |line, i|
90
+ array = line.split
91
+ break unless array[0] =~ /cpu/ # 'cpu' entries always on top
92
+
93
+ # Some machines list a 'cpu' and a 'cpu0'. In this case, only
94
+ # return values for the numbered cpu entry.
95
+ if lines[i].split[0] == "cpu" && lines[i+1].split[0] =~ /cpu\d/
96
+ next
97
+ end
98
+
99
+ vals = array[1..-1].map{ |e| e = e.to_i / 100 } # 100 jiffies/sec.
100
+ hash[array[0]] = vals
101
+ }
102
+ hash
103
+ end
104
+ end
105
+ end
data/test/tc_bsd.rb ADDED
@@ -0,0 +1,56 @@
1
+ #############################################################
2
+ # tc_bsd.rb
3
+ #
4
+ # The test case for sys-cpu on BSD flavors, including OS X.
5
+ #############################################################
6
+ require "sys/cpu"
7
+ require "test/unit"
8
+ require "tc_version"
9
+ include Sys
10
+
11
+ class TC_BSD < Test::Unit::TestCase
12
+ def test_architecture
13
+ assert_respond_to(CPU, :architecture)
14
+ assert_nothing_raised{ CPU.architecture }
15
+ assert_kind_of(String, CPU.architecture)
16
+ assert_raises(ArgumentError){ CPU.architecture(0) }
17
+ end
18
+
19
+ unless RUBY_PLATFORM.match('darwin')
20
+ def test_cpu_freq
21
+ assert_respond_to(CPU, :freq)
22
+ assert_nothing_raised{ CPU.freq }
23
+ assert_kind_of(Integer, CPU.freq)
24
+ assert_raises(ArgumentError){ CPU.freq(0) }
25
+ end
26
+ end
27
+
28
+ def test_load_avg
29
+ assert_respond_to(CPU, :load_avg)
30
+ assert_nothing_raised{ CPU.load_avg }
31
+ assert_kind_of(Array, CPU.load_avg)
32
+ assert_equal(3,CPU.load_avg.length)
33
+ assert_raises(ArgumentError){ CPU.load_avg(0) }
34
+ end
35
+
36
+ def test_machine
37
+ assert_respond_to(CPU, :machine)
38
+ assert_nothing_raised{ CPU.machine }
39
+ assert_kind_of(String, CPU.machine)
40
+ assert_raises(ArgumentError){ CPU.machine(0) }
41
+ end
42
+
43
+ def test_model
44
+ assert_respond_to(CPU, :model)
45
+ assert_nothing_raised{ CPU.model }
46
+ assert_kind_of(String, CPU.model)
47
+ assert_raises(ArgumentError){ CPU.model(0) }
48
+ end
49
+
50
+ def test_num_cpu
51
+ assert_respond_to(CPU, :num_cpu)
52
+ assert_nothing_raised{ CPU.num_cpu }
53
+ assert_kind_of(Integer, CPU.num_cpu)
54
+ assert_raises(ArgumentError){ CPU.num_cpu(0) }
55
+ end
56
+ end
data/test/tc_cpu.rb ADDED
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
2
+ require 'tc_version'
3
+
4
+ case RUBY_PLATFORM
5
+ when /bsd|darwin|mach|osx/i
6
+ require 'tc_bsd'
7
+ when /hpux/i
8
+ require 'tc_hpux'
9
+ when /linux/i
10
+ require 'tc_linux'
11
+ when /sunos|solaris/i
12
+ require 'tc_sunos'
13
+ when /mswin|win32|dos|mingw|cygwin/i
14
+ require 'tc_windows'
15
+ else
16
+ raise "Platform not supported"
17
+ end
data/test/tc_hpux.rb ADDED
@@ -0,0 +1,49 @@
1
+ #####################################################################
2
+ # tc_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 "tc_version"
10
+ include Sys
11
+
12
+ class TC_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/tc_linux.rb ADDED
@@ -0,0 +1,34 @@
1
+ ###########################################################
2
+ # tc_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 "tc_version"
10
+ include Sys
11
+
12
+ class TC_Linux < Test::Unit::TestCase
13
+ def test_all_dynamic_methods
14
+ assert_nothing_raised{
15
+ CPU.processors{ |cs|
16
+ cs.members.each{ |m|
17
+ puts "#{m}: " + cs[m].to_s
18
+ }
19
+ }
20
+ }
21
+ end
22
+
23
+ def test_load_avg
24
+ assert_nothing_raised{ CPU.load_avg }
25
+ assert_equal(3, CPU.load_avg.length)
26
+ end
27
+
28
+ def test_cpu_stats
29
+ assert_nothing_raised{ CPU.cpu_stats }
30
+ assert_kind_of(Hash, CPU.cpu_stats)
31
+ assert_equal(true, CPU.cpu_stats["cpu0"].length >= 4)
32
+ end
33
+ end
34
+
data/test/tc_sunos.rb ADDED
@@ -0,0 +1,65 @@
1
+ ###########################################################
2
+ # tc_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
+ require "tc_version"
10
+ include Sys
11
+
12
+ class TC_SunOS < 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(0))
18
+ end
19
+
20
+ def test_cpu_type
21
+ assert_respond_to(CPU, :cpu_type)
22
+ assert_nothing_raised{ CPU.cpu_type }
23
+ assert_kind_of(String, CPU.cpu_type)
24
+ end
25
+
26
+ def test_fpu_type
27
+ assert_respond_to(CPU, :fpu_type)
28
+ assert_nothing_raised{ CPU.fpu_type }
29
+ assert_kind_of(String, CPU.fpu_type)
30
+ end
31
+
32
+ def test_load_avg
33
+ assert_respond_to(CPU, :load_avg)
34
+ assert_nothing_raised{ CPU.load_avg }
35
+ assert_kind_of(Array, CPU.load_avg)
36
+ assert_equal(3, CPU.load_avg.length)
37
+ assert_kind_of(Float, CPU.load_avg.first)
38
+ end
39
+
40
+ def test_cpu_model
41
+ assert_respond_to(CPU, :model)
42
+ assert_nothing_raised{ CPU.model }
43
+ assert_kind_of(String, CPU.model)
44
+ end
45
+
46
+ def test_num_cpu
47
+ assert_respond_to(CPU, :num_cpu)
48
+ assert_nothing_raised{ CPU.num_cpu }
49
+ assert_kind_of(Integer, CPU.num_cpu)
50
+ end
51
+
52
+ def test_state
53
+ assert_respond_to(CPU, :state)
54
+ assert_nothing_raised{ CPU.state }
55
+ assert_nothing_raised{ CPU.state(0) }
56
+ assert_kind_of(String, CPU.state(0))
57
+ end
58
+
59
+ def test_exceptions
60
+ assert_raises(Sys::CPU::Error){ CPU.state(55) }
61
+ assert_raises(TypeError){ CPU.state("yo") }
62
+ assert_raises(Sys::CPU::Error){ CPU.freq(999) }
63
+ assert_raises(TypeError){ CPU.freq("yo") }
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ #######################################################################
2
+ # tc_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
+ def test_version
13
+ assert_equal('0.6.1', Sys::CPU::VERSION)
14
+ end
15
+ end
@@ -0,0 +1,69 @@
1
+ ######################################################################
2
+ # tc_windows.rb
3
+ #
4
+ # Test suite for MS Windows systems. This should be run via the
5
+ # 'rake test' task.
6
+ ######################################################################
7
+ require "test/unit"
8
+ require "sys/cpu"
9
+ require "tc_version"
10
+ require "socket"
11
+ include Sys
12
+
13
+ class TC_Windows_CPU < Test::Unit::TestCase
14
+ def setup
15
+ @host = Socket.gethostname
16
+ end
17
+
18
+ def test_architecture
19
+ assert_respond_to(CPU, :architecture)
20
+ assert_nothing_raised{ CPU.architecture }
21
+ assert_nothing_raised{ CPU.architecture(@host) }
22
+ assert_kind_of(String, CPU.architecture, "Invalid Type")
23
+ end
24
+
25
+ def test_freq
26
+ assert_respond_to(CPU, :freq)
27
+ assert_nothing_raised{ CPU.freq }
28
+ assert_nothing_raised{ CPU.freq(0) }
29
+ assert_nothing_raised{ CPU.freq(0, @host) }
30
+ assert_kind_of(Integer, CPU.freq, "Invalid Type")
31
+ end
32
+
33
+ def test_model
34
+ assert_respond_to(CPU, :model)
35
+ assert_nothing_raised{ CPU.model }
36
+ assert_nothing_raised{ CPU.model(@host) }
37
+ assert_kind_of(String, CPU.model, "Invalid Type")
38
+ end
39
+
40
+ def test_num_cpu
41
+ assert_respond_to(CPU, :num_cpu)
42
+ assert_nothing_raised{ CPU.num_cpu }
43
+ assert_nothing_raised{ CPU.num_cpu(@host) }
44
+ assert_kind_of(Integer, CPU.num_cpu, "Invalid Type")
45
+ end
46
+
47
+ def test_type
48
+ assert_respond_to(CPU, :type)
49
+ assert_nothing_raised{ CPU.type }
50
+ assert_nothing_raised{ CPU.type(@host) }
51
+ assert_kind_of(String, CPU.type, "Invalid Type")
52
+ end
53
+
54
+ def test_load_avg
55
+ assert_respond_to(CPU, :load_avg)
56
+ assert_nothing_raised{ CPU.load_avg }
57
+ assert_nothing_raised{ CPU.load_avg(0, @host) }
58
+ assert_kind_of(Integer, CPU.load_avg, "Invalid Type")
59
+ end
60
+
61
+ def test_processors
62
+ assert_respond_to(CPU, :processors)
63
+ assert_nothing_raised{ CPU.processors{} }
64
+ end
65
+
66
+ def teardown
67
+ @host = nil
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys-cpu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: x86-linux
6
+ authors:
7
+ - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A Ruby interface for providing CPU information
17
+ email: djberg96 at nospam at gmail dot com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGES
24
+ - README
25
+ - MANIFEST
26
+ - lib/sys/cpu.rb
27
+ files:
28
+ - doc/bsd.txt
29
+ - doc/windows.txt
30
+ - doc/sunos.txt
31
+ - doc/linux.txt
32
+ - doc/hpux.txt
33
+ - test/tc_cpu.rb
34
+ - test/tc_linux.rb
35
+ - test/tc_hpux.rb
36
+ - test/tc_sunos.rb
37
+ - test/tc_bsd.rb
38
+ - test/tc_version.rb
39
+ - test/tc_windows.rb
40
+ - CHANGES
41
+ - README
42
+ - MANIFEST
43
+ - lib/sys/cpu.rb
44
+ has_rdoc: true
45
+ homepage: http://www.rubyforge.org/projects/sysutils
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.2
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: sysutils
66
+ rubygems_version: 1.3.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: A Ruby interface for providing CPU information
70
+ test_files:
71
+ - test/tc_linux.rb