sys-proctable 0.9.1-universal-solaris
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +302 -0
- data/MANIFEST +30 -0
- data/README +119 -0
- data/Rakefile +175 -0
- data/benchmarks/bench_ps.rb +21 -0
- data/doc/top.txt +47 -0
- data/examples/example_ps.rb +20 -0
- data/lib/sunos/sys/proctable.rb +462 -0
- data/lib/sys/top.rb +32 -0
- data/sys-proctable.gemspec +39 -0
- data/test/test_sys_proctable_all.rb +85 -0
- data/test/test_sys_proctable_sunos.rb +308 -0
- metadata +96 -0
data/lib/sys/top.rb
ADDED
@@ -0,0 +1,32 @@
|
|
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.3'
|
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
|
+
windows = /mswin|win32|windows|dos|cygwin|mingw/i
|
23
|
+
|
24
|
+
# Sort by pid on Windows by default
|
25
|
+
if Config::CONFIG['host_os'].match(windows) && field == 'pctcpu'
|
26
|
+
field = 'pid'
|
27
|
+
end
|
28
|
+
|
29
|
+
Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbconfig'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'sys-proctable'
|
6
|
+
spec.version = '0.9.1'
|
7
|
+
spec.author = 'Daniel J. Berger'
|
8
|
+
spec.license = 'Artistic 2.0'
|
9
|
+
spec.email = 'djberg96@gmail.com'
|
10
|
+
spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
11
|
+
spec.platform = Gem::Platform::CURRENT # Probably altered by Rake task
|
12
|
+
spec.summary = 'An interface for providing process table information'
|
13
|
+
spec.test_files = ['test/test_sys_proctable_all.rb']
|
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/top.rb',
|
20
|
+
'CHANGES',
|
21
|
+
'MANIFEST',
|
22
|
+
'Rakefile',
|
23
|
+
'README',
|
24
|
+
'sys-proctable.gemspec'
|
25
|
+
]
|
26
|
+
|
27
|
+
spec.rubyforge_project = 'sysutils'
|
28
|
+
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
|
29
|
+
|
30
|
+
spec.add_development_dependency('test-unit', '>= 2.1.2')
|
31
|
+
|
32
|
+
spec.description = <<-EOF
|
33
|
+
The sys-proctable library provides an interface for gathering information
|
34
|
+
about processes on your system, i.e. the process table. Most major
|
35
|
+
platforms are supported and, while different platforms may return
|
36
|
+
different information, the external interface is identical across
|
37
|
+
platforms.
|
38
|
+
EOF
|
39
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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'] =~ /windows|win32|msdos|mswin32|mingw|cygwin/i
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup
|
22
|
+
@pid = @@windows ? 0 : 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_version
|
26
|
+
assert_equal('0.9.1', 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 test_error_class_defined
|
74
|
+
assert_not_nil(Sys::ProcTable::Error)
|
75
|
+
assert_kind_of(StandardError, Sys::ProcTable::Error.new)
|
76
|
+
end
|
77
|
+
|
78
|
+
def teardown
|
79
|
+
@pid = nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.teardown
|
83
|
+
@@windows = nil
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
#######################################################################
|
2
|
+
# tc_sunos.rb
|
3
|
+
#
|
4
|
+
# Test suite for sys-proctable for SunOS/Solaris. This should be run
|
5
|
+
# run 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_SunOS < Test::Unit::TestCase
|
15
|
+
def self.startup
|
16
|
+
@@fields = %w//
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@ptable = ProcTable.ps.first
|
21
|
+
end
|
22
|
+
|
23
|
+
# PSINFO
|
24
|
+
|
25
|
+
def test_flag
|
26
|
+
assert_respond_to(@ptable, :flag)
|
27
|
+
assert_kind_of(Integer, @ptable.flag)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_nlwp
|
31
|
+
assert_respond_to(@ptable, :nlwp)
|
32
|
+
assert_kind_of(Integer, @ptable.nlwp)
|
33
|
+
assert_true(@ptable.nlwp >= 0)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_pid
|
37
|
+
assert_respond_to(@ptable, :pid)
|
38
|
+
assert_kind_of(Integer, @ptable.pid)
|
39
|
+
assert_true(@ptable.pid >= 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ppid
|
43
|
+
assert_respond_to(@ptable, :ppid)
|
44
|
+
assert_kind_of(Integer, @ptable.ppid)
|
45
|
+
assert_true(@ptable.ppid >= 0)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_pgid
|
49
|
+
assert_respond_to(@ptable, :pgid)
|
50
|
+
assert_kind_of(Integer, @ptable.pgid)
|
51
|
+
assert_true(@ptable.pgid >= 0)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_sid
|
55
|
+
assert_respond_to(@ptable, :sid)
|
56
|
+
assert_kind_of(Integer, @ptable.sid)
|
57
|
+
assert_true(@ptable.sid >= 0)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_uid
|
61
|
+
assert_respond_to(@ptable, :uid)
|
62
|
+
assert_kind_of(Integer, @ptable.uid)
|
63
|
+
assert_true(@ptable.uid >= 0)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_euid
|
67
|
+
assert_respond_to(@ptable, :euid)
|
68
|
+
assert_kind_of(Integer, @ptable.euid)
|
69
|
+
assert_true(@ptable.euid >= 0)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_gid
|
73
|
+
assert_respond_to(@ptable, :gid)
|
74
|
+
assert_kind_of(Integer, @ptable.gid)
|
75
|
+
assert_true(@ptable.gid >= 0)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_egid
|
79
|
+
assert_respond_to(@ptable, :egid)
|
80
|
+
assert_kind_of(Integer, @ptable.egid)
|
81
|
+
assert_true(@ptable.egid >= 0)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_addr
|
85
|
+
assert_respond_to(@ptable, :addr)
|
86
|
+
assert_kind_of(Integer, @ptable.addr)
|
87
|
+
assert_true(@ptable.addr >= 0)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_size
|
91
|
+
assert_respond_to(@ptable, :size)
|
92
|
+
assert_kind_of(Integer, @ptable.size)
|
93
|
+
assert_true(@ptable.size >= 0)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_rssize
|
97
|
+
assert_respond_to(@ptable, :rssize)
|
98
|
+
assert_kind_of(Integer, @ptable.rssize)
|
99
|
+
assert_true(@ptable.rssize >= 0)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_ttydev
|
103
|
+
assert_respond_to(@ptable, :ttydev)
|
104
|
+
assert_kind_of(Integer, @ptable.ttydev)
|
105
|
+
assert_true(@ptable.ttydev >= 0 || @ptable.ttydev == -1)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_pctcpu
|
109
|
+
assert_respond_to(@ptable, :pctcpu)
|
110
|
+
assert_kind_of(Float, @ptable.pctcpu)
|
111
|
+
assert_true(@ptable.pctcpu >= 0)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_pctmem
|
115
|
+
assert_respond_to(@ptable, :pctmem)
|
116
|
+
assert_kind_of(Float, @ptable.pctmem)
|
117
|
+
assert_true(@ptable.pctmem >= 0)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_start
|
121
|
+
assert_respond_to(@ptable, :start)
|
122
|
+
assert_kind_of(Time, @ptable.start)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_time
|
126
|
+
assert_respond_to(@ptable, :time)
|
127
|
+
assert_kind_of(Integer, @ptable.time)
|
128
|
+
assert_true(@ptable.time >= 0)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_ctime
|
132
|
+
assert_respond_to(@ptable, :ctime)
|
133
|
+
assert_kind_of(Integer, @ptable.ctime)
|
134
|
+
assert_true(@ptable.ctime >= 0)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_fname
|
138
|
+
assert_respond_to(@ptable, :fname)
|
139
|
+
assert_kind_of(String, @ptable.fname)
|
140
|
+
assert_true(@ptable.fname.size > 0)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_comm_alias
|
144
|
+
assert_respond_to(@ptable, :comm)
|
145
|
+
assert_kind_of(String, @ptable.comm)
|
146
|
+
assert_true(@ptable.comm.size > 0)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_psargs
|
150
|
+
assert_respond_to(@ptable, :psargs)
|
151
|
+
assert_kind_of(String, @ptable.psargs)
|
152
|
+
assert_true(@ptable.psargs.size > 0)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_wstat
|
156
|
+
assert_respond_to(@ptable, :wstat)
|
157
|
+
assert_kind_of(Integer, @ptable.wstat)
|
158
|
+
assert_true(@ptable.wstat >= 0)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_argc
|
162
|
+
assert_respond_to(@ptable, :argc)
|
163
|
+
assert_kind_of(Integer, @ptable.argc)
|
164
|
+
assert_true(@ptable.argc >= 0)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_argv
|
168
|
+
assert_respond_to(@ptable, :argv)
|
169
|
+
assert_kind_of(Integer, @ptable.argv)
|
170
|
+
assert_true(@ptable.argv >= 0)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_envp
|
174
|
+
assert_respond_to(@ptable, :envp)
|
175
|
+
assert_kind_of(Integer, @ptable.envp)
|
176
|
+
assert_true(@ptable.envp >= 0)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_dmodel
|
180
|
+
assert_respond_to(@ptable, :dmodel)
|
181
|
+
assert_kind_of(Integer, @ptable.dmodel)
|
182
|
+
assert_true(@ptable.dmodel >= 0)
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_taskid
|
186
|
+
assert_respond_to(@ptable, :taskid)
|
187
|
+
assert_kind_of(Integer, @ptable.taskid)
|
188
|
+
assert_true(@ptable.taskid >= 0)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_projid
|
192
|
+
assert_respond_to(@ptable, :projid)
|
193
|
+
assert_kind_of(Integer, @ptable.projid)
|
194
|
+
assert_true(@ptable.projid >= 0)
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_nzomb
|
198
|
+
assert_respond_to(@ptable, :nzomb)
|
199
|
+
assert_kind_of(Integer, @ptable.nzomb)
|
200
|
+
assert_true(@ptable.nzomb >= 0)
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_poolid
|
204
|
+
assert_respond_to(@ptable, :poolid)
|
205
|
+
assert_kind_of(Integer, @ptable.poolid)
|
206
|
+
assert_true(@ptable.poolid >= 0)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_zoneid
|
210
|
+
assert_respond_to(@ptable, :zoneid)
|
211
|
+
assert_kind_of(Integer, @ptable.zoneid)
|
212
|
+
assert_true(@ptable.zoneid >= 0)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_contract
|
216
|
+
assert_respond_to(@ptable, :contract)
|
217
|
+
assert_kind_of(Integer, @ptable.contract)
|
218
|
+
assert_true(@ptable.contract >= 0 || @ptable.contract == -1)
|
219
|
+
end
|
220
|
+
|
221
|
+
# LWPSINFO
|
222
|
+
|
223
|
+
def test_lwpid
|
224
|
+
assert_respond_to(@ptable, :lwpid)
|
225
|
+
assert_kind_of(Integer, @ptable.lwpid)
|
226
|
+
assert_true(@ptable.lwpid >= 0)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_wchan
|
230
|
+
assert_respond_to(@ptable, :wchan)
|
231
|
+
assert_kind_of(Integer, @ptable.wchan)
|
232
|
+
assert_true(@ptable.wchan >= 0)
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_stype
|
236
|
+
assert_respond_to(@ptable, :stype)
|
237
|
+
assert_kind_of(Fixnum, @ptable.stype)
|
238
|
+
assert_true(@ptable.stype >= 0)
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_state
|
242
|
+
assert_respond_to(@ptable, :state)
|
243
|
+
assert_kind_of(Fixnum, @ptable.state)
|
244
|
+
assert_true(@ptable.state >= 0)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_sname
|
248
|
+
assert_respond_to(@ptable, :sname)
|
249
|
+
assert_kind_of(String, @ptable.sname)
|
250
|
+
assert_true(['S', 'R', 'Z', 'T', 'I', 'O'].include?(@ptable.sname))
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_nice
|
254
|
+
assert_respond_to(@ptable, :nice)
|
255
|
+
assert_kind_of(Fixnum, @ptable.nice)
|
256
|
+
assert_true(@ptable.nice >= 0)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_syscall
|
260
|
+
assert_respond_to(@ptable, :syscall)
|
261
|
+
assert_kind_of(Fixnum, @ptable.syscall)
|
262
|
+
assert_true(@ptable.syscall >= 0)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_pri
|
266
|
+
assert_respond_to(@ptable, :pri)
|
267
|
+
assert_kind_of(Fixnum, @ptable.pri)
|
268
|
+
assert_true(@ptable.pri >= 0)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_clname
|
272
|
+
assert_respond_to(@ptable, :clname)
|
273
|
+
assert_kind_of(String, @ptable.clname)
|
274
|
+
assert_true(@ptable.clname.length >= 0 && @ptable.clname.length <= 8)
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_name
|
278
|
+
assert_respond_to(@ptable, :name)
|
279
|
+
assert_kind_of(String, @ptable.name)
|
280
|
+
assert_true(@ptable.name.length >= 0 && @ptable.name.length <= 16)
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_onpro
|
284
|
+
assert_respond_to(@ptable, :onpro)
|
285
|
+
assert_kind_of(Fixnum, @ptable.onpro)
|
286
|
+
assert_true(@ptable.onpro >= 0)
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_bindpro
|
290
|
+
assert_respond_to(@ptable, :bindpro)
|
291
|
+
assert_kind_of(Fixnum, @ptable.bindpro)
|
292
|
+
assert_true(@ptable.bindpro >= 0 || @ptable.bindpro == -1)
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_bindpset
|
296
|
+
assert_respond_to(@ptable, :bindpset)
|
297
|
+
assert_kind_of(Fixnum, @ptable.bindpset)
|
298
|
+
assert_true(@ptable.bindpset >= 0 || @ptable.bindpset == -1)
|
299
|
+
end
|
300
|
+
|
301
|
+
def teardown
|
302
|
+
@ptable = nil
|
303
|
+
end
|
304
|
+
|
305
|
+
def self.shutdown
|
306
|
+
@@fields = nil
|
307
|
+
end
|
308
|
+
end
|