sys-proctable 0.9.9-universal-hpux

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require 'sys/proctable'
@@ -0,0 +1,6 @@
1
+ module Sys
2
+ class ProcTable
3
+ # The version of the sys-proctable library
4
+ VERSION = '0.9.9'
5
+ end
6
+ end
data/lib/sys/top.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'sys/proctable'
2
+
3
+ # The Sys module serves as a namespace only
4
+ module Sys
5
+
6
+ # The Top class serves as a toplevel name for the 'top' method.
7
+ class Top
8
+
9
+ # The version of the sys-top library
10
+ VERSION = '1.0.4'
11
+
12
+ # Returns an array of Struct::ProcTableStruct elements containing up
13
+ # to +num+ elements, sorted by +field+. The default number of elements
14
+ # is 10, while the default field is 'pctcpu'.
15
+ #
16
+ # Exception: the default sort field is 'pid' on AIX and Windows.
17
+ #
18
+ def self.top(num=10, field='pctcpu')
19
+ field = field.to_s if field.is_a?(Symbol)
20
+
21
+ aix = RbConfig::CONFIG['host_os'] =~ /aix/i
22
+
23
+ # Sort by pid on Windows and AIX by default
24
+ if (File::ALT_SEPARATOR || aix) && field == 'pctcpu'
25
+ field = 'pid'
26
+ end
27
+
28
+ Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'sys-proctable'
5
+ spec.version = '0.9.9'
6
+ spec.author = 'Daniel J. Berger'
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://github.com/djberg96/sys-proctable'
10
+ spec.platform = Gem::Platform::CURRENT # Probably altered by Rake task
11
+ spec.summary = 'An interface for providing process table information'
12
+ spec.test_files = ['test/test_sys_proctable_all.rb']
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
+
15
+ # Additional files for your platform are added by the 'rake gem' task.
16
+ spec.files = [
17
+ 'benchmarks/bench_ps.rb',
18
+ 'examples/example_ps.rb',
19
+ 'lib/sys/proctable/version.rb',
20
+ 'lib/sys/top.rb',
21
+ 'CHANGES',
22
+ 'MANIFEST',
23
+ 'Rakefile',
24
+ 'README',
25
+ 'sys-proctable.gemspec'
26
+ ]
27
+
28
+ spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
29
+
30
+ spec.add_development_dependency('test-unit')
31
+ spec.add_development_dependency('rake')
32
+
33
+ spec.description = <<-EOF
34
+ The sys-proctable library provides an interface for gathering information
35
+ about processes on your system, i.e. the process table. Most major
36
+ platforms are supported and, while different platforms may return
37
+ different information, the external interface is identical across
38
+ platforms.
39
+ EOF
40
+ end
@@ -0,0 +1,87 @@
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 'test-unit'
8
+ require 'sys/proctable'
9
+ require 'test/test_sys_top'
10
+ include Sys
11
+
12
+ class TC_ProcTable_All < Test::Unit::TestCase
13
+ def self.startup
14
+ @@windows = File::ALT_SEPARATOR
15
+ end
16
+
17
+ def setup
18
+ @pid = @@windows ? 0 : 1
19
+ end
20
+
21
+ def test_version
22
+ assert_equal('0.9.9', ProcTable::VERSION)
23
+ end
24
+
25
+ def test_fields
26
+ assert_respond_to(ProcTable, :fields)
27
+ assert_nothing_raised{ ProcTable.fields }
28
+ assert_kind_of(Array, ProcTable.fields)
29
+ assert_kind_of(String, ProcTable.fields.first)
30
+ end
31
+
32
+ def test_ps
33
+ assert_respond_to(ProcTable, :ps)
34
+ assert_nothing_raised{ ProcTable.ps }
35
+ assert_nothing_raised{ ProcTable.ps{} }
36
+ end
37
+
38
+ def test_ps_with_pid
39
+ assert_nothing_raised{ ProcTable.ps(0) }
40
+ end
41
+
42
+ def test_ps_with_explicit_nil
43
+ assert_nothing_raised{ ProcTable.ps(nil) }
44
+ assert_kind_of(Array, ProcTable.ps(nil))
45
+ end
46
+
47
+ def test_ps_return_value
48
+ assert_kind_of(Array, ProcTable.ps)
49
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
50
+ assert_equal(nil, ProcTable.ps(999999999))
51
+ assert_equal(nil, ProcTable.ps(999999999){})
52
+ assert_equal(nil, ProcTable.ps{})
53
+ end
54
+
55
+ def test_ps_returned_struct_is_frozen
56
+ assert_true(ProcTable.ps.first.frozen?)
57
+ end
58
+
59
+ def test_ps_expected_errors
60
+ assert_raises(TypeError){ ProcTable.ps('vim') }
61
+ omit_if(@@windows, 'ArgumentError check skipped on MS Windows')
62
+ assert_raises(ArgumentError){ ProcTable.ps(0, 'localhost') }
63
+ end
64
+
65
+ def test_new_not_allowed
66
+ assert_raise(NoMethodError){ Sys::ProcTable.new }
67
+ end
68
+
69
+ def test_error_class_defined
70
+ assert_not_nil(Sys::ProcTable::Error)
71
+ assert_kind_of(StandardError, Sys::ProcTable::Error.new)
72
+ end
73
+
74
+ def test_from_thread
75
+ Thread.new do
76
+ Sys::ProcTable.ps
77
+ end.value
78
+ end
79
+
80
+ def teardown
81
+ @pid = nil
82
+ end
83
+
84
+ def self.teardown
85
+ @@windows = nil
86
+ end
87
+ end
@@ -0,0 +1,313 @@
1
+ #######################################################################
2
+ # test_sys_proctable_hpux.rb
3
+ #
4
+ # Test case for the HP-UX version of the sys-proctable library. You
5
+ # should run this test suite via the 'rake test' task.
6
+ #######################################################################
7
+ require 'rubygems'
8
+ gem 'test/unit'
9
+
10
+ require 'sys/proctable'
11
+ require 'test/test_sys_proctable_all'
12
+ include Sys
13
+
14
+ class TC_ProcTable_HPUX < Test::Unit::TestCase
15
+ def self.startup
16
+ @@fields = %w/
17
+ comm uid pid ppid dsize tsize ssize nice ttydev pgrp pri addr
18
+ cpu utime stime start flag stat wchan procnum cmd cmdline time
19
+ cpticks cptickstotal fss pctcpu rssize suid shmsize mmsize usize
20
+ iosize vtsize vdsize vssize vshmsize vmmsize vusize viosize
21
+ minorfaults majorfaults nswap nsignals msgrcv msgsnd maxrss
22
+ sid schedpolicy ticksleft euid egid gid sgid
23
+ /
24
+ end
25
+
26
+ def setup
27
+ @ptable = ProcTable.ps.last
28
+ end
29
+
30
+ def test_expected_fields
31
+ assert_respond_to(ProcTable, :fields)
32
+ assert_kind_of(Array, ProcTable.fields)
33
+ assert_equal(@@fields, ProcTable.fields)
34
+ end
35
+
36
+ def test_comm
37
+ assert_respond_to(@ptable, :comm)
38
+ assert_kind_of(String, @ptable.comm)
39
+ end
40
+
41
+ def test_uid
42
+ assert_respond_to(@ptable, :uid)
43
+ assert_kind_of(Fixnum, @ptable.uid)
44
+ end
45
+
46
+ def test_pid
47
+ assert_respond_to(@ptable, :pid)
48
+ assert_kind_of(Fixnum, @ptable.pid)
49
+ end
50
+
51
+ def test_ppid
52
+ assert_respond_to(@ptable, :ppid)
53
+ assert_kind_of(Fixnum, @ptable.ppid)
54
+ end
55
+
56
+ def test_dsize
57
+ assert_respond_to(@ptable, :dsize)
58
+ assert_kind_of(Fixnum, @ptable.dsize)
59
+ end
60
+
61
+ def test_tsize
62
+ assert_respond_to(@ptable, :tsize)
63
+ assert_kind_of(Fixnum, @ptable.tsize)
64
+ end
65
+
66
+ def test_ssize
67
+ assert_respond_to(@ptable, :ssize)
68
+ assert_kind_of(Fixnum, @ptable.ssize)
69
+ end
70
+
71
+ def test_nice
72
+ assert_respond_to(@ptable, :nice)
73
+ assert_kind_of(Fixnum, @ptable.nice)
74
+ end
75
+
76
+ def test_ttydev
77
+ assert_respond_to(@ptable, :ttydev)
78
+ assert_kind_of(String, @ptable.ttydev)
79
+ end
80
+
81
+ def test_pgrp
82
+ assert_respond_to(@ptable, :pgrp)
83
+ assert_kind_of(Fixnum, @ptable.pgrp)
84
+ end
85
+
86
+ def test_pri
87
+ assert_respond_to(@ptable, :pri)
88
+ assert_kind_of(Fixnum, @ptable.pri)
89
+ end
90
+
91
+ def test_addr
92
+ assert_respond_to(@ptable, :addr)
93
+ assert_kind_of(Fixnum, @ptable.addr)
94
+ end
95
+
96
+ def test_cpu
97
+ assert_respond_to(@ptable, :cpu)
98
+ assert_kind_of(Fixnum, @ptable.cpu)
99
+ end
100
+
101
+ def test_utime
102
+ assert_respond_to(@ptable, :utime)
103
+ assert_kind_of(Fixnum, @ptable.utime)
104
+ end
105
+
106
+ def test_stime
107
+ assert_respond_to(@ptable, :stime)
108
+ assert_kind_of(Fixnum, @ptable.stime)
109
+ end
110
+
111
+ def test_start
112
+ assert_respond_to(@ptable, :start)
113
+ assert_kind_of(Time, @ptable.start)
114
+ end
115
+
116
+ def test_flag
117
+ assert_respond_to(@ptable, :flag)
118
+ assert_kind_of(Fixnum, @ptable.flag)
119
+ end
120
+
121
+ def test_state
122
+ assert_respond_to(@ptable, :state)
123
+ assert_kind_of(String, @ptable.state)
124
+ end
125
+
126
+ def test_wchan
127
+ assert_respond_to(@ptable, :wchan)
128
+ assert_kind_of(Fixnum, @ptable.wchan)
129
+ end
130
+
131
+ def test_procnum
132
+ assert_respond_to(@ptable, :procnum)
133
+ assert_kind_of(Fixnum, @ptable.procnum)
134
+ end
135
+
136
+ def test_cmd
137
+ assert_respond_to(@ptable, :cmd)
138
+ assert_kind_of(String, @ptable.cmd)
139
+ end
140
+
141
+ def test_cmdline
142
+ assert_respond_to(@ptable, :cmdline)
143
+ assert_kind_of(String, @ptable.cmdline)
144
+ end
145
+
146
+ def test_time
147
+ assert_respond_to(@ptable, :time)
148
+ assert_kind_of(Fixnum, @ptable.time)
149
+ end
150
+
151
+ def test_cpticks
152
+ assert_respond_to(@ptable, :cpticks)
153
+ assert_kind_of(Fixnum, @ptable.cpticks)
154
+ end
155
+
156
+ def test_cptickstotal
157
+ assert_respond_to(@ptable, :cptickstotal)
158
+ assert_kind_of(Fixnum, @ptable.cptickstotal)
159
+ end
160
+
161
+ def test_fss
162
+ assert_respond_to(@ptable, :fss)
163
+ assert_kind_of(Fixnum, @ptable.fss)
164
+ end
165
+
166
+ def test_pctcpu
167
+ assert_respond_to(@ptable, :pctcpu)
168
+ assert_kind_of(Float, @ptable.pctcpu)
169
+ end
170
+
171
+ def test_rssize
172
+ assert_respond_to(@ptable, :rssize)
173
+ assert_kind_of(Fixnum, @ptable.rssize)
174
+ end
175
+
176
+ def test_suid
177
+ assert_respond_to(@ptable, :suid)
178
+ assert_kind_of(Fixnum, @ptable.suid)
179
+ end
180
+
181
+ def test_shmsize
182
+ assert_respond_to(@ptable, :shmsize)
183
+ assert_kind_of(Fixnum, @ptable.shmsize)
184
+ end
185
+
186
+ def test_mmsize
187
+ assert_respond_to(@ptable, :mmsize)
188
+ assert_kind_of(Fixnum, @ptable.mmsize)
189
+ end
190
+
191
+ def test_usize
192
+ assert_respond_to(@ptable, :usize)
193
+ assert_kind_of(Fixnum, @ptable.usize)
194
+ end
195
+
196
+ def test_iosize
197
+ assert_respond_to(@ptable, :iosize)
198
+ assert_kind_of(Fixnum, @ptable.iosize)
199
+ end
200
+
201
+ def test_vtsize
202
+ assert_respond_to(@ptable, :vtsize)
203
+ assert_kind_of(Fixnum, @ptable.vtsize)
204
+ end
205
+
206
+ def test_vdsize
207
+ assert_respond_to(@ptable, :vdsize)
208
+ assert_kind_of(Fixnum, @ptable.vdsize)
209
+ end
210
+
211
+ def test_vssize
212
+ assert_respond_to(@ptable, :vssize)
213
+ assert_kind_of(Fixnum, @ptable.vssize)
214
+ end
215
+
216
+ def test_vshmsize
217
+ assert_respond_to(@ptable, :vshmsize)
218
+ assert_kind_of(Fixnum, @ptable.vshmsize)
219
+ end
220
+
221
+ def test_vmmsize
222
+ assert_respond_to(@ptable, :vmmsize)
223
+ assert_kind_of(Fixnum, @ptable.vmmsize)
224
+ end
225
+
226
+ def test_vusize
227
+ assert_respond_to(@ptable, :vusize)
228
+ assert_kind_of(Fixnum, @ptable.vusize)
229
+ end
230
+
231
+ def test_viosize
232
+ assert_respond_to(@ptable, :viosize)
233
+ assert_kind_of(Fixnum, @ptable.viosize)
234
+ end
235
+
236
+ def test_minorfaults
237
+ assert_respond_to(@ptable, :minorfaults)
238
+ assert_kind_of(Integer, @ptable.minorfaults)
239
+ end
240
+
241
+ def test_majorfaults
242
+ assert_respond_to(@ptable, :majorfaults)
243
+ assert_kind_of(Integer, @ptable.majorfaults)
244
+ end
245
+
246
+ def test_nswap
247
+ assert_respond_to(@ptable, :nswap)
248
+ assert_kind_of(Integer, @ptable.nswap)
249
+ end
250
+
251
+ def test_nsignals
252
+ assert_respond_to(@ptable, :nsignals)
253
+ assert_kind_of(Integer, @ptable.nsignals)
254
+ end
255
+
256
+ def test_msgrcv
257
+ assert_respond_to(@ptable, :msgrcv)
258
+ assert_kind_of(Integer, @ptable.msgrcv)
259
+ end
260
+
261
+ def test_msgsnd
262
+ assert_respond_to(@ptable, :msgsnd)
263
+ assert_kind_of(Integer, @ptable.msgsnd)
264
+ end
265
+
266
+ def test_maxrss
267
+ assert_respond_to(@ptable, :maxrss)
268
+ assert_kind_of(Fixnum, @ptable.maxrss)
269
+ end
270
+
271
+ def test_sid
272
+ assert_respond_to(@ptable, :sid)
273
+ assert_kind_of(Fixnum, @ptable.sid)
274
+ end
275
+
276
+ def test_schedpolicy
277
+ assert_respond_to(@ptable, :schedpolicy)
278
+ assert_kind_of(Fixnum, @ptable.schedpolicy)
279
+ end
280
+
281
+ def test_ticksleft
282
+ assert_respond_to(@ptable, :ticksleft)
283
+ assert_kind_of(Fixnum, @ptable.ticksleft)
284
+ end
285
+
286
+ def test_euid
287
+ assert_respond_to(@ptable, :euid)
288
+ assert_kind_of(Fixnum, @ptable.euid)
289
+ end
290
+
291
+ def test_egid
292
+ assert_respond_to(@ptable, :egid)
293
+ assert_kind_of(Fixnum, @ptable.egid)
294
+ end
295
+
296
+ def test_gid
297
+ assert_respond_to(@ptable, :gid)
298
+ assert_kind_of(Fixnum, @ptable.gid)
299
+ end
300
+
301
+ def test_sgid
302
+ assert_respond_to(@ptable, :sgid)
303
+ assert_kind_of(Fixnum, @ptable.sgid)
304
+ end
305
+
306
+ def teardown
307
+ @ptable = nil
308
+ end
309
+
310
+ def self.shutdown
311
+ @@fields = nil
312
+ end
313
+ end