sys-proctable 0.8.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +260 -0
- data/MANIFEST +38 -0
- data/README +137 -0
- data/doc/top.txt +50 -0
- data/doc/windows.txt +106 -0
- data/lib/sys/proctable.rb +209 -0
- data/lib/sys/top.rb +35 -0
- data/test/test_sys_proctable_all.rb +80 -0
- data/test/test_sys_proctable_windows.rb +320 -0
- metadata +74 -0
data/CHANGES
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
== 0.8.0 - 26-Jan-2009
|
2
|
+
* The Linux and Solaris versions of this library are now pure Ruby. Be warned,
|
3
|
+
however, that only Solaris 8 and later are now supported. This may change
|
4
|
+
in a future release if there's demand to support 2.6 and 2.7.
|
5
|
+
* Some Struct::ProcTableStruct members have changed. As a general rule they
|
6
|
+
now more closely match the C struct member name. See individual platforms
|
7
|
+
for more details.
|
8
|
+
* Bug fix for the cmd_args struct member on Solaris.
|
9
|
+
* Bug fixes for OS X. Added a VERSION constant, fixed struct name, and changed
|
10
|
+
pct_cpu to pctcpu.
|
11
|
+
* The .new method is now explicitly illegal.
|
12
|
+
* The Struct::ProcTableStruct instances are now frozen. This is read-only data.
|
13
|
+
* Added the peak_page_file_usage and status members on MS Windows. The status
|
14
|
+
member is always nil, but was added for completeness.
|
15
|
+
* Fixed the quota_peak_paged_pool_usage member on MS Windows.
|
16
|
+
* ProcTableError is now ProcTable::Error.
|
17
|
+
* Minor test case fix for kvm/bsd based versions.
|
18
|
+
* Added the 'time' library as a require for Windows (to parse MS date/time
|
19
|
+
format strings).
|
20
|
+
* The kvm (bsd.c) implementation now works for FreeBSD 7.
|
21
|
+
* Added many more tests.
|
22
|
+
* Added some benchmarking code in the 'benchmarks' directory.
|
23
|
+
* Added a 'bench' Rake task.
|
24
|
+
* Renamed the test_ps.rb file to example_ps.rb in order to avoid any possible
|
25
|
+
confusion with actual test files.
|
26
|
+
* Added an 'example' rake task to run the example file.
|
27
|
+
|
28
|
+
== 0.7.6 - 11-Jul-2007
|
29
|
+
* Fixed the starttime for Linux. Thanks go to Yaroslav Dmitriev for the spot.
|
30
|
+
* Fixed a bug in the MS Windows version within a private method that parsed
|
31
|
+
an MS specific date format. This was caused by a backwards incompatible
|
32
|
+
change in the Time.parse method in Ruby 1.8.6. See ruby-core: 11245 ff.
|
33
|
+
* Fixed the gemspec (I hope). Please let me know if you have problems.
|
34
|
+
* Added a Rakefile. Building, testing and installing should now be handled via
|
35
|
+
Rake tasks. The install.rb file has been removed - that code is now
|
36
|
+
integrated in the Rakefile.
|
37
|
+
* Minor directory layout changes and cleanup (mostly for the extconf.rb file).
|
38
|
+
* Side note - it seems that the code for OS X *does* work, at least on 10.4.10.
|
39
|
+
I can only conclude that previous reports about it failing were related to
|
40
|
+
bugs in OS X or were really just build issues. Apologies (and thanks, again)
|
41
|
+
to David Felstead for the code. However, see the README for more information
|
42
|
+
specific to OS X, as there are shortcomings.
|
43
|
+
|
44
|
+
== 0.7.5 - 23-Nov-2006
|
45
|
+
* Fixed int/long issues for Linux. Thanks go to Matt Lightner for the spot.
|
46
|
+
* Minor documentation fixes and changes to the extconf.rb file.
|
47
|
+
|
48
|
+
== 0.7.4 - 20-Nov-2006
|
49
|
+
* Added a patch that deals with the large file compilation issue on Solaris.
|
50
|
+
You no longer need to build Ruby with --disable-largefile, or build a
|
51
|
+
64 bit Ruby, in order for this package to work. Thanks go to Steven Jenkins
|
52
|
+
for the information that led to the patch.
|
53
|
+
* Added inline rdoc to the source code.
|
54
|
+
* Added a gemspec.
|
55
|
+
* Fixed some potential 64 bit issues (struct declarations).
|
56
|
+
* Added preliminary support for Darwin (OS X). The code was provided by
|
57
|
+
David Felstead, but does not appear to compile successfully. Help wanted.
|
58
|
+
|
59
|
+
== 0.7.3 - 27-Oct-2005
|
60
|
+
* Fix for 1.8.3 and later (rb_pid_t). This should have only affected
|
61
|
+
Solaris.
|
62
|
+
|
63
|
+
== 0.7.2 - 15-May-2005
|
64
|
+
* Bug fix for the FreeBSD version that reads from /proc.
|
65
|
+
* Eliminated the test bug on Linux (inexplicably caused by File.copy). The
|
66
|
+
test suite should now run without segfaulting.
|
67
|
+
* Include bsd.c in tarball (oops).
|
68
|
+
* Minor test updates for FreeBSD.
|
69
|
+
* The 'pct_cpu' member for the BSD/kvm version has been changed to 'pctcpu'
|
70
|
+
for consistency with other platforms.
|
71
|
+
|
72
|
+
== 0.7.1 - 8-May-2005
|
73
|
+
* Bug fixed for the cmdline info on Linux. Thanks go to Arash Abedinzadeh
|
74
|
+
for the spot.
|
75
|
+
* Added an example program.
|
76
|
+
* Minor setup fix for Win32 in tc_all.rb.
|
77
|
+
|
78
|
+
== 0.7.0 - 25-Apr-2005
|
79
|
+
* Scrapped the C implementation for Windows in favor of an OLE + WMI pure Ruby
|
80
|
+
approach. See documentation for details.
|
81
|
+
* Added an optional lkvm implementation for BSD users. This is automatically
|
82
|
+
used if the /proc filesystem isn't found.
|
83
|
+
* Added prusage info for the Solaris version.
|
84
|
+
* Added name, eid, euid, gid and guid information for Linux. Thanks go to
|
85
|
+
James Hranicky for the patch.
|
86
|
+
* Fixed some potential bugs in the Linux version. Thanks go to James
|
87
|
+
Hranicky for the spot.
|
88
|
+
* Added the 'sys/top' package.
|
89
|
+
* ProcTable.fields no longer supports a block form.
|
90
|
+
* The BTIME (boot time) information has been removed from the Linux version.
|
91
|
+
If you want that information, use sys-uptime instead.
|
92
|
+
* The .html and .rd files have been removed. You can generate html on your
|
93
|
+
own with rdoc if you like.
|
94
|
+
* Some code cleanup on the C side of the house.
|
95
|
+
* Most documents made rdoc friendly.
|
96
|
+
* Renamed 'install_pure_ruby.rb' to just 'install.rb'.
|
97
|
+
* Removed the 'INSTALL' file. Installation instructions are in the README.
|
98
|
+
* Some test suite cleanup and reorganization.
|
99
|
+
* Moved project to RubyForge.
|
100
|
+
|
101
|
+
== 0.6.4 - 31-Mar-2004
|
102
|
+
* Fixed a bug in the pure Ruby version for Win32. Thanks go to Mark Hudson
|
103
|
+
for the spot.
|
104
|
+
* Fixed a bug in the C implementation for Win32 where the cmdline and path
|
105
|
+
values were sometimes wrong for running processes. Thanks go to Park Heesob
|
106
|
+
for the fix.
|
107
|
+
* Updated the VERSION constant and removed the VERSION class method in the
|
108
|
+
pure Ruby version for Win32.
|
109
|
+
* Updated install_pure_ruby.rb and test.rb scripts.
|
110
|
+
* Updated warranty information.
|
111
|
+
* The extconf.rb script has been revamped. See the INSTALL and README files
|
112
|
+
for important changes since the last release.
|
113
|
+
* The start ProcInfo struct member on Solaris, HP-UX and FreeBSD is now a
|
114
|
+
Time object, not a Fixnum/Bignum.
|
115
|
+
* Modified linux.c yet again to make gcc happy when it comes to multi-line
|
116
|
+
string literals.
|
117
|
+
* Minor change to way process state is handled on HP-UX.
|
118
|
+
* Documentation additions and updates, including warranty information.
|
119
|
+
|
120
|
+
== 0.6.3 - 24-Feb-2004
|
121
|
+
* Fixed a bug in the Solaris version where the cmd_args array did not
|
122
|
+
necessarily contain data on 2.7 and later. The current patch still
|
123
|
+
does not quite fix the problem for 2.6 and earlier but can be easily
|
124
|
+
derived manually by parsing the cmdline string.
|
125
|
+
|
126
|
+
== 0.6.2 - 20-Jan-2004
|
127
|
+
* Fixed a small memory leak in the solaris version.
|
128
|
+
|
129
|
+
== 0.6.1 - 31-Dec-2003
|
130
|
+
* Fixed a minor bug in the cmdline field on Linux where a blank character
|
131
|
+
was being appended to the end of the field.
|
132
|
+
* Fixed a minor annoyance where the windows.rb file was being copied into
|
133
|
+
the Ruby lib directory on install.
|
134
|
+
* Added a test_memleak.rb file. Currently only supported on Linux and
|
135
|
+
only does a file descriptor count check. I plan to expand this to
|
136
|
+
other platforms in the future.
|
137
|
+
* Minor test suite changes
|
138
|
+
* MANIFEST correction and update.
|
139
|
+
|
140
|
+
== 0.6.0 - 22-Oct-2003
|
141
|
+
* Significant API change (and thus, a version jump) - only a
|
142
|
+
single argument is now accepted to the ps() method, and only a PID
|
143
|
+
(Fixnum) is regarded as a valid argument.
|
144
|
+
* Calling ps() with a pid returns a single ProcTable struct (or nil
|
145
|
+
if the pid is not found), instead of a one element array.
|
146
|
+
* Argument to ps() now works properly on HP-UX and Win32.
|
147
|
+
* Removed the '#include <sys/types32.h>' in sunos.h. It wasn't needed
|
148
|
+
and you're not supposed to include it directly.
|
149
|
+
* Fixed 2.6 compatibility issue with regards to cmdline on Solaris.
|
150
|
+
* Removed the ProcStatException completely on Linux. There was no reason
|
151
|
+
to fail on a directory read for /proc/xxx/stat. If the read fails
|
152
|
+
(meaning the process died in the middle of collecting info for it), it
|
153
|
+
is simply ignored.
|
154
|
+
* The ttynum bug on HPUX has been fixed. In addition, the return value for
|
155
|
+
this field is now a string rather than an int and the field name has
|
156
|
+
been changed to "ttydev".
|
157
|
+
* The ttynum field has been changed to ttydev on Solaris and HPUX. On
|
158
|
+
Solaris, the ttydev is now reported as -1 if there is no associated tty.
|
159
|
+
In a future release, Solaris and the other *nix platforms will be changed
|
160
|
+
so that ttydev is always a device name (i.e String).
|
161
|
+
* Added plain text documentation for all platforms.
|
162
|
+
* Some test suite cleanup.
|
163
|
+
* Changed .rd2 extension to just '.rd'.
|
164
|
+
|
165
|
+
== 0.5.2 - 18-Jul-2003
|
166
|
+
* Modified cmdline to extend past the traditional 80 character limit on
|
167
|
+
Solaris, where possible (Solaris 2.6+ only).
|
168
|
+
* Added the cmdline_args and num_args fields on Solaris, which returns
|
169
|
+
an array of cmdline arguments and the number of cmdline arguments,
|
170
|
+
respectively.
|
171
|
+
* Minor modification to fields() method, in addition to warning cleanup
|
172
|
+
for Solaris.
|
173
|
+
* Changed "defunct" state string to "zombie" for Solaris.
|
174
|
+
* Should cleanly compile with -Wall -W now (gcc) on Solaris.
|
175
|
+
* Added solaris.txt to doc directory.
|
176
|
+
* MANIFEST corrections.
|
177
|
+
|
178
|
+
== 0.5.1 - 16-Jul-2003
|
179
|
+
* Fixed a nasty file descriptor bug in the Linux code, where file descriptors
|
180
|
+
were continuously being used up.
|
181
|
+
* Added the BTIME (boot time) constant for Linux.
|
182
|
+
* Fixed up the test/test.rb file a bit.
|
183
|
+
* Added BTIME tests to tc_linux.rb.
|
184
|
+
|
185
|
+
== 0.5.0 - 11-Jul-200
|
186
|
+
* Added HP-UX support!
|
187
|
+
* Note that passing PID's or strings as arguments to ps() is not supported
|
188
|
+
in the HP-UX version. This functionality will be stripped out of the
|
189
|
+
other versions in a future release. See the README file for more details.
|
190
|
+
* Removed the VERSION() class method. Use the constant instead.
|
191
|
+
* Separated the rd docs from their respective source files. Now in the doc
|
192
|
+
directory.
|
193
|
+
* Got rid of the interactive html generation in extconf.rb.
|
194
|
+
* Changed License to Artistic.
|
195
|
+
|
196
|
+
== 0.4.3 - 30-May-2003
|
197
|
+
* Added a version.h file to store the version number. Modified all of the
|
198
|
+
C source files to use that instead of hard coding the version everywhere.
|
199
|
+
* Added a generic test.rb script for those without TestUnit installed, or
|
200
|
+
just futzing in general. Modified the extconf.rb script to copy this
|
201
|
+
instead of writing an inline HERE document.
|
202
|
+
* Modified extconf.rb so that it builds with mingw or cygwin. Thanks go to
|
203
|
+
Peter Fischer for the spot and patch.
|
204
|
+
* Modified test suite to work with TestUnit 0.1.6 or 0.1.8.
|
205
|
+
|
206
|
+
== 0.4.2 - 14-Apr-2003
|
207
|
+
* Added pure Ruby version for Win32 - thanks Park Heesob.
|
208
|
+
* Modified extconf.rb file to handle pure Ruby versions.
|
209
|
+
* Added install_pure_ruby.rb file, an alternate installation
|
210
|
+
script for pure Ruby versions.
|
211
|
+
|
212
|
+
== 0.4.1 - 31-Mar-2003
|
213
|
+
* Added support for Solaris 2.5.x.
|
214
|
+
* All exceptions are now a direct subclass of StandardError.
|
215
|
+
* Value returned for wchan now more meaningful (2.5.x only for now).
|
216
|
+
* Fixed the start, utime and ctime for FreeBSD.
|
217
|
+
* Minor fix to FreeBSD test suite.
|
218
|
+
* Some changes to extconf.rb.
|
219
|
+
* Minor doc changes.
|
220
|
+
* Added License and Copyright info.
|
221
|
+
|
222
|
+
== 0.4.0 - 10-Mar-2003
|
223
|
+
* Added MS Windows support (non-cygwin).
|
224
|
+
* Added environment information for Linux version.
|
225
|
+
* Added real exceptions (type depends on platform).
|
226
|
+
* Added a test suite (for those with testunit installed).
|
227
|
+
* Removed the sys-uname requirement.
|
228
|
+
* Heavily modified the extconf.rb script.
|
229
|
+
* Changed "Changelog" to "CHANGES" and "Manifest" to "MANIFEST".
|
230
|
+
* Added a VERSION constant and class method.
|
231
|
+
* Minor internal directory layout change (put 'os' under 'lib').
|
232
|
+
* Changed package name to lower case.
|
233
|
+
* Doc changes, including license information.
|
234
|
+
|
235
|
+
== 0.3.1 - 16-Aug-2002
|
236
|
+
* Added a "comm" field to the sunos version. I am going to try to make this a
|
237
|
+
common field for all platforms to help reduce RUBY_PLATFORM checking.
|
238
|
+
* Fixed the release date for 0.3.0 (was accidentally marked *July*).
|
239
|
+
* Added an INSTALL file.
|
240
|
+
* Minor documentation change to the sunos.c source file.
|
241
|
+
|
242
|
+
== 0.3.0 - 11-Aug-2002
|
243
|
+
* Added FreeBSD support!
|
244
|
+
* Struct name changed to just "ProcTableStruct" to be compliant with future
|
245
|
+
versions of Ruby.
|
246
|
+
* The ps() function now returns an array of ProcTableStruct's in lvalue context.
|
247
|
+
* Fixed the ability to search by process name in Linux.
|
248
|
+
* Modified Linux "comm" field to strip parenthesis.
|
249
|
+
* Some doc changes/additions.
|
250
|
+
* Added Sean Chittenden to the "Acknowledgements" section. Sean provided me
|
251
|
+
with access to a FreeBSD box, which is how I was able to provide FreeBSD
|
252
|
+
support. Thanks Sean!
|
253
|
+
|
254
|
+
== 0.2.0 - 19-Jul-2002
|
255
|
+
* Added the ability to search by process name.
|
256
|
+
* test.rb modified to be cross-platform.
|
257
|
+
* Solaris - fixed bug with fname (was accidentally called "name").
|
258
|
+
|
259
|
+
== 0.1.0 - 2-Jul-2002
|
260
|
+
- Initial release.
|
data/MANIFEST
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
CHANGES
|
2
|
+
INSTALL
|
3
|
+
MANIFEST
|
4
|
+
Rakefile
|
5
|
+
sys-proctable.gemspec
|
6
|
+
|
7
|
+
doc/freebsd.txt
|
8
|
+
doc/hpux.txt
|
9
|
+
doc/linux.txt
|
10
|
+
doc/solaris.txt
|
11
|
+
doc/top.txt
|
12
|
+
doc/windows.txt
|
13
|
+
|
14
|
+
example/example_ps.rb
|
15
|
+
|
16
|
+
ext/extconf.rb
|
17
|
+
ext/bsd/bsd.c
|
18
|
+
ext/darwin/darwin.c
|
19
|
+
ext/freebsd/freebsd.c
|
20
|
+
ext/freebsd/freebsd.h
|
21
|
+
ext/hpux/hpux.c
|
22
|
+
ext/hpux/hpux.h
|
23
|
+
ext/version.h
|
24
|
+
|
25
|
+
lib/sys/top.rb
|
26
|
+
lib/sys/linux.rb
|
27
|
+
lib/sys/sunos.rb
|
28
|
+
lib/sys/windows.rb
|
29
|
+
|
30
|
+
test/test_sys_proctable_all.rb
|
31
|
+
test/test_sys_proctable_darwin.rb
|
32
|
+
test/test_sys_proctable_freebsd.rb
|
33
|
+
test/test_sys_proctable_hpux.rb
|
34
|
+
test/test_sys_proctable_kvm.rb
|
35
|
+
test/test_sys_proctable_linux.rb
|
36
|
+
test/test_sys_proctable_sunos.rb
|
37
|
+
test/test_sys_proctable_windows.rb
|
38
|
+
test/test_sys_top.rb
|
data/README
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
= Description
|
2
|
+
A Ruby interface for gathering process information.
|
3
|
+
|
4
|
+
= Prerequisites
|
5
|
+
* Ruby 1.8.2 or later
|
6
|
+
* Test::Unit 2.x
|
7
|
+
|
8
|
+
= Supported Platforms
|
9
|
+
* Windows NT family (NT, 2000, XP, etc)
|
10
|
+
* Linux
|
11
|
+
* FreeBSD
|
12
|
+
* Solaris 2.8+
|
13
|
+
* HP-UX
|
14
|
+
* OS X
|
15
|
+
|
16
|
+
= Installation
|
17
|
+
* rake test (optional)
|
18
|
+
* rake install
|
19
|
+
|
20
|
+
= Synopsis
|
21
|
+
require 'sys/proctable'
|
22
|
+
include Sys
|
23
|
+
|
24
|
+
# Everything
|
25
|
+
ProcTable.ps{ |p|
|
26
|
+
puts p.pid.to_s
|
27
|
+
puts p.comm
|
28
|
+
...
|
29
|
+
}
|
30
|
+
|
31
|
+
or
|
32
|
+
|
33
|
+
# Just one process
|
34
|
+
s = ProcTable.ps(2123)
|
35
|
+
puts s.pid.to_s
|
36
|
+
puts s.comm
|
37
|
+
...
|
38
|
+
|
39
|
+
# Return the results as an array of ProcTableStructs
|
40
|
+
a = ProcTable.ps
|
41
|
+
a.each do |p|
|
42
|
+
puts a.pid
|
43
|
+
...
|
44
|
+
end
|
45
|
+
|
46
|
+
= Notes
|
47
|
+
Windows users may pass a host name as a second argument to get process
|
48
|
+
information from a different host. This relies on the WMI service running.
|
49
|
+
|
50
|
+
If you're building C source code, the ts_all.rb file is autogenerated for
|
51
|
+
you.
|
52
|
+
|
53
|
+
= Known Issues
|
54
|
+
=== FreeBSD
|
55
|
+
If you're building on FreeBSD, a standard /proc filesystem read approach is
|
56
|
+
used if mounted. Otherwise, a kvm interface is used. There are more fields
|
57
|
+
available with the kvm interface, but keep in mind that you need to be a
|
58
|
+
member of the kvm group (or root) to use this. You can tweak the extconf.rb
|
59
|
+
file manually if you want to force the issue.
|
60
|
+
|
61
|
+
=== OpenBSD, NetBSD
|
62
|
+
This library will attempt to use the kvm interface. It is untested,
|
63
|
+
however.
|
64
|
+
|
65
|
+
=== Solaris
|
66
|
+
The cmdline member on Solaris is limited to 80 characters unless you (or
|
67
|
+
your program) own the process. This is a Solaris design flaw/feature.
|
68
|
+
|
69
|
+
=== OS X
|
70
|
+
At the moment you do not get the full command line string. The code required
|
71
|
+
to get this information is obnoxious and I don't have any compelling desire
|
72
|
+
to add it. However, if you're willing to submit a patch I'll accept it.
|
73
|
+
|
74
|
+
You can find a good starting point with the OS X code found in Dan Urist's
|
75
|
+
Proc::ProcessTable module. You can find that module on CPAN. Point your
|
76
|
+
browser at http://search.cpan.org.
|
77
|
+
|
78
|
+
=== Misc
|
79
|
+
If you build your library as a C extension (which is what will happen if
|
80
|
+
you run the 'build', 'test', or 'install' Rake tasks), then the .rb files
|
81
|
+
file under 'lib/sys/' are renamed to '.orig', except top.rb. This is
|
82
|
+
necessary to prevent mkmf from installing them during a 'make install'.
|
83
|
+
|
84
|
+
The 'clean' Rake task will rename them back to '.rb'.
|
85
|
+
|
86
|
+
=== Thread Safety
|
87
|
+
I am not currently using a thread-safe version of readdir(). I am not
|
88
|
+
especially concerned about it either. If you are trying to read information
|
89
|
+
out of /proc from different threads at the same time there is something
|
90
|
+
seriously wrong with your code logic. Using readdir_r() still won't solve
|
91
|
+
all potential thread safety issues anyway.
|
92
|
+
|
93
|
+
= Future Plans
|
94
|
+
Research has indicated that the kvm approach is less favored than a sysctl
|
95
|
+
approach on BSD variants. I will try to add this interface in a future
|
96
|
+
release.
|
97
|
+
|
98
|
+
= Acknowledgements
|
99
|
+
This library is largely based on the Perl module Proc::ProcessTable by
|
100
|
+
Dan Urist. Many ideas, as well as large chunks of code, were taken
|
101
|
+
from his work. So, a big THANK YOU goes out to Dan Urist.
|
102
|
+
|
103
|
+
A big thanks also goes out to Mike Hall who was very helpful with ideas,
|
104
|
+
logic and testing.
|
105
|
+
|
106
|
+
Thanks also go to Sean Chittenden for providing an account on one of his
|
107
|
+
FreeBSD machines. This is how the FreeBSD support was (initially) added.
|
108
|
+
|
109
|
+
Thanks go to James Hranicky for providing a patch that grabs name, eid,
|
110
|
+
euid, gid and guid info in the Linux version, along with some general
|
111
|
+
debugging help.
|
112
|
+
|
113
|
+
Finally I'd like to thank all the folks who have submitted bug reports
|
114
|
+
and/or patches.
|
115
|
+
|
116
|
+
= Help Wanted
|
117
|
+
I do not have access to all platforms. There are a few other major platforms
|
118
|
+
out there, namely AIX, OpenBSD, and IRIX, among others, that I would
|
119
|
+
like to see ports for. There are two ways you can help - either submit code
|
120
|
+
for your particular platform or give me an account on your platform so I can
|
121
|
+
develop on it.
|
122
|
+
|
123
|
+
= More documentation
|
124
|
+
See the documentation under the 'doc' directory for more information,
|
125
|
+
including platform specific notes and issues.
|
126
|
+
|
127
|
+
= License
|
128
|
+
Ruby's
|
129
|
+
|
130
|
+
= Copyright
|
131
|
+
(C) 2003-2009 Daniel J. Berger
|
132
|
+
All Rights Reserved.
|
133
|
+
|
134
|
+
= Author
|
135
|
+
Daniel J. Berger
|
136
|
+
djberg96 at nospam at gmail dot com
|
137
|
+
imperator on IRC (Freenode)
|
data/doc/top.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= Description
|
2
|
+
A simple 'top' interface for Ruby
|
3
|
+
|
4
|
+
= Prerequisites
|
5
|
+
Requires the "sys/proctable" package (which should be installed along
|
6
|
+
with this package).
|
7
|
+
|
8
|
+
= Synopsis
|
9
|
+
require "sys/top"
|
10
|
+
include Sys
|
11
|
+
|
12
|
+
Top.top(5).each{ |ps|
|
13
|
+
p ps
|
14
|
+
}
|
15
|
+
|
16
|
+
= Constants
|
17
|
+
VERSION
|
18
|
+
Returns the version number of this package as a String.
|
19
|
+
|
20
|
+
= Class Methods
|
21
|
+
Top.top(number=10, field="pctcpu")
|
22
|
+
Returns an array of ProcTableStruct's. The size of the array (i.e. the
|
23
|
+
number of processes) that it returns is based on +number+, and sorted by
|
24
|
+
+pctcpu+. By default, the size and field values are 10 and "pctcpu",
|
25
|
+
respectively.
|
26
|
+
|
27
|
+
= Notes
|
28
|
+
Not all fields are available on all platforms. Please check your
|
29
|
+
platform specific documentation for which fields are available.
|
30
|
+
|
31
|
+
= Bugs
|
32
|
+
None that I'm aware of. Please log bug reports on the project page at
|
33
|
+
http://www.rubyforge.org/projects/sysutils
|
34
|
+
|
35
|
+
= License
|
36
|
+
Ruby's
|
37
|
+
|
38
|
+
= Copyright
|
39
|
+
(C) 2004-2009 Daniel J. Berger
|
40
|
+
All Rights Reserved.
|
41
|
+
|
42
|
+
= Warranty
|
43
|
+
This package is provided "as is" and without any express or
|
44
|
+
implied warranties, including, without limitation, the implied
|
45
|
+
warranties of merchantability and fitness for a particular purpose.
|
46
|
+
|
47
|
+
= Author
|
48
|
+
Daniel J. Berger
|
49
|
+
djberg96 at nospam at gmail dot com
|
50
|
+
imperator on IRC (Freenode)
|
data/doc/windows.txt
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
= Description
|
2
|
+
A Ruby interface for gathering process information. For MS Windows,
|
3
|
+
the process information is gathered via OLE + WMI, using pure Ruby.
|
4
|
+
|
5
|
+
= Synopsis
|
6
|
+
require 'sys/proctable'
|
7
|
+
include Sys
|
8
|
+
|
9
|
+
# Everything
|
10
|
+
ProcTable.ps{ |p|
|
11
|
+
puts p.pid.to_s
|
12
|
+
puts p.comm
|
13
|
+
...
|
14
|
+
}
|
15
|
+
|
16
|
+
or
|
17
|
+
|
18
|
+
# A single pid
|
19
|
+
p = ProcTable.ps(1234)
|
20
|
+
puts p.pid.to_s
|
21
|
+
puts p.comm
|
22
|
+
...
|
23
|
+
|
24
|
+
or
|
25
|
+
|
26
|
+
# Return the results as an array of ProcTableStructs
|
27
|
+
a = ProcTable.ps
|
28
|
+
a.each do |p|
|
29
|
+
puts a.pid
|
30
|
+
...
|
31
|
+
end
|
32
|
+
|
33
|
+
= Constants
|
34
|
+
VERSION
|
35
|
+
Returns the current version number for this library (as a string).
|
36
|
+
|
37
|
+
= Class Methods
|
38
|
+
ProcTable.fields
|
39
|
+
Returns an Array of fields available on the current OS in the
|
40
|
+
ProcTableStruct.
|
41
|
+
|
42
|
+
ProcTable.ps(pid=nil, host='localhost')
|
43
|
+
ProcTable.ps{ |s| ... }
|
44
|
+
Returns a struct of type ProcTableStruct for every process in the proc
|
45
|
+
table in block form. Otherwise it returns an array of ProcTableStruct's.
|
46
|
+
|
47
|
+
If 'pid' is provided, then only a struct for that pid is returned, or
|
48
|
+
nil if it is not found.
|
49
|
+
|
50
|
+
If 'host' is provided, then processes from that host are gathered. By
|
51
|
+
default, process information is gathered on the local host.
|
52
|
+
|
53
|
+
= Supported fields
|
54
|
+
You can also view the supported fields with the Sys::ProcTable.fields
|
55
|
+
method.
|
56
|
+
|
57
|
+
= Notes
|
58
|
+
For the sake of attempting to provide a somewhat common API, the 'comm'
|
59
|
+
and 'cmdline' fields have been included as part of the structure. The
|
60
|
+
'comm' member corresponds to the Name attribute of Win32_Process. The
|
61
|
+
'cmdline' attribute corresponds to either the Executable_Path attribute
|
62
|
+
(on Windows 2000 or earlier) or the CommandLine attribute (on Windows XP
|
63
|
+
and later).
|
64
|
+
|
65
|
+
Also note that the ProcessId and ParentProcessId attributes have been
|
66
|
+
abbreviated as 'pid' and 'ppid' in the struct members, again to keep the
|
67
|
+
members more consistent between platforms.
|
68
|
+
|
69
|
+
The "Mem Usage" and "VM Size" that you may be used to seeing in your Task
|
70
|
+
Manager window (probably) correspond to the 'working_set_size' and
|
71
|
+
'page_file_usage' struct members, respectively, keeping in mind that
|
72
|
+
those values are in bytes, not kilobytes. I say 'probably' because
|
73
|
+
comments that I've read online indicate that it may not always line up
|
74
|
+
with what you see in the Task Manager, based on the current version (or
|
75
|
+
even Service Pack) of Windows that you are using.
|
76
|
+
|
77
|
+
= Future Plans
|
78
|
+
Possibly use the Win32_PerfFormattedData_PerfProc_Process class to get
|
79
|
+
additional process information.
|
80
|
+
|
81
|
+
= Known Bugs
|
82
|
+
Versions of Ruby earlier than 1.8.2 resulted in segfaults when trying to
|
83
|
+
run this code. You will likely encounter the same behavior.
|
84
|
+
|
85
|
+
Please log any additional bug reports on the project page at
|
86
|
+
http://www.rubyforge.org/projects/sysutils
|
87
|
+
|
88
|
+
= License
|
89
|
+
Ruby's
|
90
|
+
|
91
|
+
= Copyright
|
92
|
+
(C) 2003-2009 Daniel J. Berger
|
93
|
+
All Rights Reserved
|
94
|
+
|
95
|
+
= Warranty
|
96
|
+
This package is provided "as is" and without any express or
|
97
|
+
implied warranties, including, without limitation, the implied
|
98
|
+
warranties of merchantability and fitness for a particular purpose.
|
99
|
+
|
100
|
+
= Author
|
101
|
+
Daniel J. Berger
|
102
|
+
djberg96 at nospam at gmail dot com
|
103
|
+
imperator on IRC (freenode)
|
104
|
+
|
105
|
+
= See Also
|
106
|
+
OLE + WMI
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'win32ole'
|
2
|
+
require 'socket'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
# The Sys module serves as a namespace only
|
6
|
+
module Sys
|
7
|
+
|
8
|
+
# The ProcTable class encapsulates process table information
|
9
|
+
class ProcTable
|
10
|
+
|
11
|
+
# There is no constructor
|
12
|
+
private_class_method :new
|
13
|
+
|
14
|
+
# Error typically raised if one of the Sys::ProcTable methods fails
|
15
|
+
class Error < StandardError; end
|
16
|
+
|
17
|
+
# The version of the sys-proctable library
|
18
|
+
VERSION = '0.8.0'
|
19
|
+
|
20
|
+
# The comm field corresponds to the 'name' field. The 'cmdline' field
|
21
|
+
# is the CommandLine attribute on Windows XP or later, or the
|
22
|
+
# 'executable_path' field on Windows 2000 or earlier.
|
23
|
+
#
|
24
|
+
@fields = %w/
|
25
|
+
caption
|
26
|
+
cmdline
|
27
|
+
comm
|
28
|
+
creation_class_name
|
29
|
+
creation_date
|
30
|
+
cs_creation_class_name
|
31
|
+
cs_name
|
32
|
+
description
|
33
|
+
executable_path
|
34
|
+
execution_state
|
35
|
+
handle
|
36
|
+
handle_count
|
37
|
+
install_date
|
38
|
+
kernel_mode_time
|
39
|
+
maximum_working_set_size
|
40
|
+
minimum_working_set_size
|
41
|
+
name
|
42
|
+
os_creation_class_name
|
43
|
+
os_name
|
44
|
+
other_operation_count
|
45
|
+
other_transfer_count
|
46
|
+
page_faults
|
47
|
+
page_file_usage
|
48
|
+
ppid
|
49
|
+
peak_page_file_usage
|
50
|
+
peak_virtual_size
|
51
|
+
peak_working_set_size
|
52
|
+
priority
|
53
|
+
private_page_count
|
54
|
+
pid
|
55
|
+
quota_non_paged_pool_usage
|
56
|
+
quota_paged_pool_usage
|
57
|
+
quota_peak_non_paged_pool_usage
|
58
|
+
quota_peak_paged_pool_usage
|
59
|
+
read_operation_count
|
60
|
+
read_transfer_count
|
61
|
+
session_id
|
62
|
+
status
|
63
|
+
termination_date
|
64
|
+
thread_count
|
65
|
+
user_mode_time
|
66
|
+
virtual_size
|
67
|
+
windows_version
|
68
|
+
working_set_size
|
69
|
+
write_operation_count
|
70
|
+
write_transfer_count
|
71
|
+
/
|
72
|
+
|
73
|
+
ProcTableStruct = Struct.new("ProcTableStruct", *@fields)
|
74
|
+
|
75
|
+
# call-seq:
|
76
|
+
# ProcTable.fields
|
77
|
+
#
|
78
|
+
# Returns an array of fields that each ProcTableStruct will contain. This
|
79
|
+
# may be useful if you want to know in advance what fields are available
|
80
|
+
# without having to perform at least one read of the /proc table.
|
81
|
+
#
|
82
|
+
def self.fields
|
83
|
+
@fields
|
84
|
+
end
|
85
|
+
|
86
|
+
# call-seq:
|
87
|
+
# ProcTable.ps(pid=nil)
|
88
|
+
# ProcTable.ps(pid=nil){ |ps| ... }
|
89
|
+
#
|
90
|
+
# In block form, yields a ProcTableStruct for each process entry that you
|
91
|
+
# have rights to. This method returns an array of ProcTableStruct's in
|
92
|
+
# non-block form.
|
93
|
+
#
|
94
|
+
# If a +pid+ is provided, then only a single ProcTableStruct is yielded or
|
95
|
+
# returned, or nil if no process information is found for that +pid+.
|
96
|
+
#
|
97
|
+
def self.ps(pid=nil, host=Socket.gethostname)
|
98
|
+
if pid
|
99
|
+
raise TypeError unless pid.kind_of?(Fixnum)
|
100
|
+
end
|
101
|
+
|
102
|
+
array = block_given? ? nil : []
|
103
|
+
struct = nil
|
104
|
+
|
105
|
+
begin
|
106
|
+
wmi = WIN32OLE.connect("winmgmts://#{host}/root/cimv2")
|
107
|
+
rescue WIN32OLERuntimeError => e
|
108
|
+
raise Error, e # Re-raise as ProcTable::Error
|
109
|
+
else
|
110
|
+
wmi.InstancesOf("Win32_Process").each{ |wproc|
|
111
|
+
if pid
|
112
|
+
next unless wproc.ProcessId == pid
|
113
|
+
end
|
114
|
+
|
115
|
+
# Some fields are added later, and so are nil initially
|
116
|
+
struct = ProcTableStruct.new(
|
117
|
+
wproc.Caption,
|
118
|
+
nil, # Added later, based on OS version
|
119
|
+
wproc.Name,
|
120
|
+
wproc.CreationClassName,
|
121
|
+
self.parse_ms_date(wproc.CreationDate),
|
122
|
+
wproc.CSCreationClassName,
|
123
|
+
wproc.CSName,
|
124
|
+
wproc.Description,
|
125
|
+
wproc.ExecutablePath,
|
126
|
+
wproc.ExecutionState,
|
127
|
+
wproc.Handle,
|
128
|
+
wproc.HandleCount,
|
129
|
+
self.parse_ms_date(wproc.InstallDate),
|
130
|
+
self.convert(wproc.KernelModeTime),
|
131
|
+
wproc.MaximumWorkingSetSize,
|
132
|
+
wproc.MinimumWorkingSetSize,
|
133
|
+
wproc.Name,
|
134
|
+
wproc.OSCreationClassName,
|
135
|
+
wproc.OSName,
|
136
|
+
self.convert(wproc.OtherOperationCount),
|
137
|
+
self.convert(wproc.OtherTransferCount),
|
138
|
+
wproc.PageFaults,
|
139
|
+
wproc.PageFileUsage,
|
140
|
+
wproc.ParentProcessId,
|
141
|
+
self.convert(wproc.PeakPageFileUsage),
|
142
|
+
self.convert(wproc.PeakVirtualSize),
|
143
|
+
self.convert(wproc.PeakWorkingSetSize),
|
144
|
+
wproc.Priority,
|
145
|
+
self.convert(wproc.PrivatePageCount),
|
146
|
+
wproc.ProcessId,
|
147
|
+
wproc.QuotaNonPagedPoolUsage,
|
148
|
+
wproc.QuotaPagedPoolUsage,
|
149
|
+
wproc.QuotaPeakNonPagedPoolUsage,
|
150
|
+
wproc.QuotaPeakPagedPoolUsage,
|
151
|
+
self.convert(wproc.ReadOperationCount),
|
152
|
+
self.convert(wproc.ReadTransferCount),
|
153
|
+
wproc.SessionId,
|
154
|
+
wproc.Status,
|
155
|
+
self.parse_ms_date(wproc.TerminationDate),
|
156
|
+
wproc.ThreadCount,
|
157
|
+
self.convert(wproc.UserModeTime),
|
158
|
+
self.convert(wproc.VirtualSize),
|
159
|
+
wproc.WindowsVersion,
|
160
|
+
self.convert(wproc.WorkingSetSize),
|
161
|
+
self.convert(wproc.WriteOperationCount),
|
162
|
+
self.convert(wproc.WriteTransferCount)
|
163
|
+
)
|
164
|
+
|
165
|
+
###############################################################
|
166
|
+
# On Windows XP or later, set the cmdline to the CommandLine
|
167
|
+
# attribute. Otherwise, set it to the ExecutablePath
|
168
|
+
# attribute.
|
169
|
+
###############################################################
|
170
|
+
if wproc.WindowsVersion.to_f < 5.1
|
171
|
+
struct.cmdline = wproc.ExecutablePath
|
172
|
+
else
|
173
|
+
struct.cmdline = wproc.CommandLine
|
174
|
+
end
|
175
|
+
|
176
|
+
struct.freeze # This is read-only data
|
177
|
+
|
178
|
+
if block_given?
|
179
|
+
yield struct
|
180
|
+
else
|
181
|
+
array << struct
|
182
|
+
end
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
pid ? struct : array
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
#######################################################################
|
192
|
+
# Converts a string in the format '20040703074625.015625-360' into a
|
193
|
+
# Ruby Time object.
|
194
|
+
#######################################################################
|
195
|
+
def self.parse_ms_date(str)
|
196
|
+
return if str.nil?
|
197
|
+
return Date.parse(str.split('.').first)
|
198
|
+
end
|
199
|
+
|
200
|
+
#####################################################################
|
201
|
+
# There is a bug in win32ole where uint64 types are returned as a
|
202
|
+
# String instead of a Fixnum. This method deals with that for now.
|
203
|
+
#####################################################################
|
204
|
+
def self.convert(str)
|
205
|
+
return nil if str.nil? # Return nil, not 0
|
206
|
+
return str.to_i
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
data/lib/sys/top.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sys/proctable'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
# The Sys module serves as a namespace only
|
5
|
+
module Sys
|
6
|
+
|
7
|
+
# The Top class serves as a toplevel name for the 'top' method.
|
8
|
+
class Top
|
9
|
+
|
10
|
+
# The version of the sys-top library
|
11
|
+
VERSION = '1.0.2'
|
12
|
+
|
13
|
+
# Returns an array of Struct::ProcTableStruct elements containing up
|
14
|
+
# to +num+ elements, sorted by +field+. The default number of elements
|
15
|
+
# is 10, while the default field is 'pctcpu'.
|
16
|
+
#
|
17
|
+
# Exception: the default sort field is 'pid' on Linux and Windows.
|
18
|
+
#
|
19
|
+
def self.top(num=10, field='pctcpu')
|
20
|
+
field = field.to_s if field.is_a?(Symbol)
|
21
|
+
|
22
|
+
# Sort by pid on Windows by default
|
23
|
+
if Config::CONFIG['host_os'].match('mswin') && field == 'pctcpu'
|
24
|
+
field = 'pid'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Linux does not have a pctcpu field yet
|
28
|
+
if Config::CONFIG['host_os'].match('linux') && field == 'pctcpu'
|
29
|
+
field = 'pid'
|
30
|
+
end
|
31
|
+
|
32
|
+
Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# test_sys_proctable_all.rb
|
3
|
+
#
|
4
|
+
# Test suite for methods common to all platforms. Generally speaking
|
5
|
+
# you should run this test case using the 'rake test' task.
|
6
|
+
#######################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'sys/proctable'
|
12
|
+
require 'rbconfig'
|
13
|
+
require 'test/test_sys_top'
|
14
|
+
include Sys
|
15
|
+
|
16
|
+
class TC_ProcTable_All < Test::Unit::TestCase
|
17
|
+
def self.startup
|
18
|
+
@@windows = Config::CONFIG['host_os'].match('mswin')
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@pid = @@windows ? 0 : 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_version
|
26
|
+
assert_equal('0.8.0', ProcTable::VERSION)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_fields
|
30
|
+
assert_respond_to(ProcTable, :fields)
|
31
|
+
assert_nothing_raised{ ProcTable.fields }
|
32
|
+
assert_kind_of(Array, ProcTable.fields)
|
33
|
+
assert_kind_of(String, ProcTable.fields.first)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_ps
|
37
|
+
assert_respond_to(ProcTable, :ps)
|
38
|
+
assert_nothing_raised{ ProcTable.ps }
|
39
|
+
assert_nothing_raised{ ProcTable.ps{} }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ps_with_pid
|
43
|
+
assert_nothing_raised{ ProcTable.ps(0) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_ps_with_explicit_nil
|
47
|
+
assert_nothing_raised{ ProcTable.ps(nil) }
|
48
|
+
assert_kind_of(Array, ProcTable.ps(nil))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_ps_return_value
|
52
|
+
assert_kind_of(Array, ProcTable.ps)
|
53
|
+
assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
|
54
|
+
assert_equal(nil, ProcTable.ps(999999999))
|
55
|
+
assert_equal(nil, ProcTable.ps(999999999){})
|
56
|
+
assert_equal(nil, ProcTable.ps{})
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_ps_returned_struct_is_frozen
|
60
|
+
assert_true(ProcTable.ps.first.frozen?)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_ps_expected_errors
|
64
|
+
assert_raises(TypeError){ ProcTable.ps('vim') }
|
65
|
+
omit_if(@@windows, 'ArgumentError check skipped on MS Windows')
|
66
|
+
assert_raises(ArgumentError){ ProcTable.ps(0, 'localhost') }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_new_not_allowed
|
70
|
+
assert_raise(NoMethodError){ Sys::ProcTable.new }
|
71
|
+
end
|
72
|
+
|
73
|
+
def teardown
|
74
|
+
@pid = nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.teardown
|
78
|
+
@@windows = nil
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
############################################################################
|
2
|
+
# test_sys_proctable_windows.rb
|
3
|
+
#
|
4
|
+
# Test suite for the sys-proctable library for MS Windows. This should be
|
5
|
+
# run via the 'rake test' task.
|
6
|
+
############################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'sys/proctable'
|
11
|
+
require 'socket'
|
12
|
+
require 'test/unit'
|
13
|
+
require 'test/test_sys_proctable_all'
|
14
|
+
|
15
|
+
class TC_ProcTable_MSWindows < Test::Unit::TestCase
|
16
|
+
def self.startup
|
17
|
+
@@hostname = Socket.gethostname
|
18
|
+
|
19
|
+
@@fields = %w/
|
20
|
+
caption
|
21
|
+
cmdline
|
22
|
+
comm
|
23
|
+
creation_class_name
|
24
|
+
creation_date
|
25
|
+
cs_creation_class_name
|
26
|
+
cs_name description
|
27
|
+
executable_path
|
28
|
+
execution_state
|
29
|
+
handle
|
30
|
+
handle_count
|
31
|
+
install_date
|
32
|
+
kernel_mode_time
|
33
|
+
maximum_working_set_size
|
34
|
+
minimum_working_set_size name
|
35
|
+
os_creation_class_name
|
36
|
+
os_name
|
37
|
+
other_operation_count
|
38
|
+
other_transfer_count
|
39
|
+
page_faults
|
40
|
+
page_file_usage
|
41
|
+
ppid
|
42
|
+
peak_page_file_usage
|
43
|
+
peak_virtual_size
|
44
|
+
peak_working_set_size
|
45
|
+
priority
|
46
|
+
private_page_count
|
47
|
+
pid
|
48
|
+
quota_non_paged_pool_usage
|
49
|
+
quota_paged_pool_usage
|
50
|
+
quota_peak_non_paged_pool_usage
|
51
|
+
quota_peak_paged_pool_usage
|
52
|
+
read_operation_count
|
53
|
+
read_transfer_count
|
54
|
+
session_id
|
55
|
+
status
|
56
|
+
termination_date
|
57
|
+
thread_count
|
58
|
+
user_mode_time
|
59
|
+
virtual_size
|
60
|
+
windows_version
|
61
|
+
working_set_size
|
62
|
+
write_operation_count
|
63
|
+
write_transfer_count
|
64
|
+
/
|
65
|
+
|
66
|
+
@@ptable = ProcTable.ps.first
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_write_transfer_count
|
70
|
+
assert_respond_to(@@ptable, :write_transfer_count)
|
71
|
+
assert_kind_of(Integer, @@ptable.write_transfer_count)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_write_operation_count
|
75
|
+
assert_respond_to(@@ptable, :write_operation_count)
|
76
|
+
assert_kind_of(Integer, @@ptable.write_operation_count)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_working_set_size
|
80
|
+
assert_respond_to(@@ptable, :working_set_size)
|
81
|
+
assert_kind_of(Integer, @@ptable.working_set_size)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_windows_version
|
85
|
+
assert_respond_to(@@ptable, :windows_version)
|
86
|
+
assert_kind_of(String, @@ptable.windows_version)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_virtual_size
|
90
|
+
assert_respond_to(@@ptable, :virtual_size)
|
91
|
+
assert_kind_of(Integer, @@ptable.virtual_size)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_user_mode_time
|
95
|
+
assert_respond_to(@@ptable, :user_mode_time)
|
96
|
+
assert_kind_of(Integer, @@ptable.user_mode_time)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_thread_count
|
100
|
+
assert_respond_to(@@ptable, :thread_count)
|
101
|
+
assert_kind_of(Integer, @@ptable.thread_count)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_termination_date
|
105
|
+
assert_respond_to(@@ptable, :termination_date)
|
106
|
+
assert_true([NilClass, Date].include?(@@ptable.termination_date.class))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_status
|
110
|
+
assert_respond_to(@@ptable, :status)
|
111
|
+
assert_nil(@@ptable.status) # Always null according to MSDN
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_session_id
|
115
|
+
assert_respond_to(@@ptable, :session_id)
|
116
|
+
assert_kind_of(Integer, @@ptable.session_id)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_read_transfer_count
|
120
|
+
assert_respond_to(@@ptable, :read_transfer_count)
|
121
|
+
assert_kind_of(Integer, @@ptable.read_transfer_count)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_read_operation_count
|
125
|
+
assert_respond_to(@@ptable, :read_operation_count)
|
126
|
+
assert_kind_of(Integer, @@ptable.read_operation_count)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_quota_peak_paged_pool_usage
|
130
|
+
assert_respond_to(@@ptable, :quota_peak_paged_pool_usage)
|
131
|
+
assert_kind_of(Integer, @@ptable.quota_peak_paged_pool_usage)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_quota_peak_non_paged_pool_usage
|
135
|
+
assert_respond_to(@@ptable, :quota_peak_non_paged_pool_usage)
|
136
|
+
assert_kind_of(Integer, @@ptable.quota_peak_non_paged_pool_usage)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_quota_paged_pool_usage
|
140
|
+
assert_respond_to(@@ptable, :quota_paged_pool_usage)
|
141
|
+
assert_kind_of(Integer, @@ptable.quota_paged_pool_usage)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_quota_non_paged_pool_usage
|
145
|
+
assert_respond_to(@@ptable, :quota_non_paged_pool_usage)
|
146
|
+
assert_kind_of(Integer, @@ptable.quota_non_paged_pool_usage)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_pid
|
150
|
+
assert_respond_to(@@ptable, :pid)
|
151
|
+
assert_kind_of(Integer, @@ptable.pid)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_private_page_count
|
155
|
+
assert_respond_to(@@ptable, :private_page_count)
|
156
|
+
assert_kind_of(Integer, @@ptable.private_page_count)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_priority
|
160
|
+
assert_respond_to(@@ptable, :priority)
|
161
|
+
assert_kind_of(Integer, @@ptable.priority)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_peak_working_set_size
|
165
|
+
assert_respond_to(@@ptable, :peak_working_set_size)
|
166
|
+
assert_kind_of(Integer, @@ptable.peak_working_set_size)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_peak_virtual_size
|
170
|
+
assert_respond_to(@@ptable, :peak_virtual_size)
|
171
|
+
assert_kind_of(Integer, @@ptable.peak_virtual_size)
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_peak_page_file_usage
|
175
|
+
assert_respond_to(@@ptable, :peak_page_file_usage)
|
176
|
+
assert_kind_of(Integer, @@ptable.peak_page_file_usage)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_ppid
|
180
|
+
assert_respond_to(@@ptable, :ppid)
|
181
|
+
assert_kind_of(Integer, @@ptable.ppid)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_page_file_usage
|
185
|
+
assert_respond_to(@@ptable, :page_file_usage)
|
186
|
+
assert_kind_of(Integer, @@ptable.page_file_usage)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_page_faults
|
190
|
+
assert_respond_to(@@ptable, :page_faults)
|
191
|
+
assert_kind_of(Integer, @@ptable.page_faults)
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_other_transfer_count
|
195
|
+
assert_respond_to(@@ptable, :other_transfer_count)
|
196
|
+
assert_kind_of(Integer, @@ptable.other_transfer_count)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_other_operation_count
|
200
|
+
assert_respond_to(@@ptable, :other_operation_count)
|
201
|
+
assert_kind_of(Integer, @@ptable.other_operation_count)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_os_name
|
205
|
+
assert_respond_to(@@ptable, :os_name)
|
206
|
+
assert_kind_of(String, @@ptable.os_name)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_os_creation_class_name
|
210
|
+
assert_respond_to(@@ptable, :os_creation_class_name)
|
211
|
+
assert_kind_of(String, @@ptable.os_creation_class_name)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_name
|
215
|
+
assert_respond_to(@@ptable, :name)
|
216
|
+
assert_kind_of(String, @@ptable.name)
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_minimum_working_set_size
|
220
|
+
assert_respond_to(@@ptable, :minimum_working_set_size)
|
221
|
+
assert_true([NilClass, Integer].include?(@@ptable.minimum_working_set_size.class))
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_maximum_working_set_size
|
225
|
+
assert_respond_to(@@ptable, :maximum_working_set_size)
|
226
|
+
assert_true([NilClass, Integer].include?(@@ptable.maximum_working_set_size.class))
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_kernel_mode_time
|
230
|
+
assert_respond_to(@@ptable, :kernel_mode_time)
|
231
|
+
assert_kind_of(Integer, @@ptable.kernel_mode_time)
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_install_date
|
235
|
+
assert_respond_to(@@ptable, :install_date)
|
236
|
+
assert_true([NilClass, Date].include?(@@ptable.install_date.class))
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_handle_count
|
240
|
+
assert_respond_to(@@ptable, :handle_count)
|
241
|
+
assert_kind_of(Integer, @@ptable.handle_count)
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_handle
|
245
|
+
assert_respond_to(@@ptable, :handle)
|
246
|
+
assert_kind_of(String, @@ptable.handle) # MSDN says it's a String
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_execution_state
|
250
|
+
assert_respond_to(@@ptable, :execution_state)
|
251
|
+
assert_nil(@@ptable.execution_state) # Always NULL according to MSDN
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_executable_path
|
255
|
+
assert_respond_to(@@ptable, :executable_path)
|
256
|
+
assert_true([NilClass, String].include?(@@ptable.executable_path.class))
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_description
|
260
|
+
assert_respond_to(@@ptable, :description)
|
261
|
+
assert_kind_of(String, @@ptable.description)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_cs_name
|
265
|
+
assert_respond_to(@@ptable, :cs_name)
|
266
|
+
assert_kind_of(String, @@ptable.cs_name)
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_cs_creation_class_name
|
270
|
+
assert_respond_to(@@ptable, :cs_creation_class_name)
|
271
|
+
assert_kind_of(String, @@ptable.cs_creation_class_name)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_creation_date
|
275
|
+
assert_respond_to(@@ptable, :creation_date)
|
276
|
+
assert_true([NilClass, Date].include?(@@ptable.creation_date.class))
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_creation_class_name
|
280
|
+
assert_respond_to(@@ptable, :creation_class_name)
|
281
|
+
assert_kind_of(String, @@ptable.creation_class_name)
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_comm
|
285
|
+
assert_respond_to(@@ptable, :comm)
|
286
|
+
assert_kind_of(String, @@ptable.comm)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_cmdline
|
290
|
+
assert_respond_to(@@ptable, :cmdline)
|
291
|
+
assert_true([NilClass, String].include?(@@ptable.cmdline.class))
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_caption
|
295
|
+
assert_respond_to(@@ptable, :caption)
|
296
|
+
assert_kind_of(String, @@ptable.caption)
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_field_members
|
300
|
+
assert_equal(@@fields.length, @@ptable.length)
|
301
|
+
assert_equal(@@fields, ProcTable.fields)
|
302
|
+
assert_equal(@@fields, @@ptable.members)
|
303
|
+
end
|
304
|
+
|
305
|
+
# Only Windows supports a hostname as a second argument
|
306
|
+
def test_ps_with_pid_and_host
|
307
|
+
assert_nothing_raised{ ProcTable.ps(0, @@hostname) }
|
308
|
+
assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(0, @@hostname))
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_ps_expected_errors
|
312
|
+
assert_raise(ArgumentError){ ProcTable.ps(0, @@hostname, 0) }
|
313
|
+
end
|
314
|
+
|
315
|
+
def self.shutdown
|
316
|
+
@@ptable = nil
|
317
|
+
@@hostname = nil
|
318
|
+
@@fields = nil
|
319
|
+
end
|
320
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sys-proctable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: x86-mswin32-60
|
6
|
+
authors:
|
7
|
+
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-26 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: test-unit
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.0.2
|
24
|
+
version:
|
25
|
+
description: An interface for providing process table information
|
26
|
+
email: djberg96@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- CHANGES
|
33
|
+
- README
|
34
|
+
- MANIFEST
|
35
|
+
- doc/top.txt
|
36
|
+
- doc/windows.txt
|
37
|
+
files:
|
38
|
+
- lib/sys/top.rb
|
39
|
+
- test/test_sys_proctable_all.rb
|
40
|
+
- CHANGES
|
41
|
+
- README
|
42
|
+
- MANIFEST
|
43
|
+
- doc/top.txt
|
44
|
+
- lib/sys/proctable.rb
|
45
|
+
- doc/windows.txt
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.8.2
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: sysutils
|
68
|
+
rubygems_version: 1.3.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: An interface for providing process table information
|
72
|
+
test_files:
|
73
|
+
- test/test_sys_proctable_all.rb
|
74
|
+
- test/test_sys_proctable_windows.rb
|