sys-proctable 0.9.1-universal-freebsd
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 +120 -0
- data/Rakefile +176 -0
- data/benchmarks/bench_ps.rb +21 -0
- data/doc/top.txt +47 -0
- data/examples/example_ps.rb +20 -0
- data/ext/bsd/extconf.rb +14 -0
- data/ext/bsd/sys/proctable.c +301 -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_bsd.rb +212 -0
- metadata +97 -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,212 @@
|
|
1
|
+
################################################################
|
2
|
+
# test_sys_proctable_bsd.rb
|
3
|
+
#
|
4
|
+
# Test suite for various BSD flavors for the sys-proctable
|
5
|
+
# library. You should run these tests via 'rake test'.
|
6
|
+
################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'sys/proctable'
|
12
|
+
require 'test/test_sys_proctable_all'
|
13
|
+
include Sys
|
14
|
+
|
15
|
+
class TC_Sys_ProcTable_BSD < Test::Unit::TestCase
|
16
|
+
def self.startup
|
17
|
+
@@fields = %w/
|
18
|
+
pid ppid pgid ruid rgid comm state pctcpu oncpu ttynum ttydev
|
19
|
+
wmesg time priority usrpri nice cmdline start
|
20
|
+
maxrss ixrss idrss isrss minflt majflt nswap inblock oublock
|
21
|
+
msgsnd msgrcv nsignals nvcsw nivcsw utime stime
|
22
|
+
/
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@ptable = ProcTable.ps.last
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_fields
|
30
|
+
assert_respond_to(ProcTable, :fields)
|
31
|
+
assert_kind_of(Array, ProcTable.fields)
|
32
|
+
assert_equal(@@fields, ProcTable.fields)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_pid
|
36
|
+
assert_respond_to(@ptable, :pid)
|
37
|
+
assert_kind_of(Fixnum, @ptable.pid)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_ppid
|
41
|
+
assert_respond_to(@ptable, :ppid)
|
42
|
+
assert_kind_of(Fixnum, @ptable.ppid)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_pgid
|
46
|
+
assert_respond_to(@ptable, :pgid)
|
47
|
+
assert_kind_of(Fixnum, @ptable.pgid)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_ruid
|
51
|
+
assert_respond_to(@ptable, :ruid)
|
52
|
+
assert_kind_of(Fixnum, @ptable.ruid)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_rgid
|
56
|
+
assert_respond_to(@ptable, :rgid)
|
57
|
+
assert_kind_of(Fixnum, @ptable.rgid)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_comm
|
61
|
+
assert_respond_to(@ptable, :comm)
|
62
|
+
assert_kind_of(String, @ptable.comm)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_state
|
66
|
+
assert_respond_to(@ptable, :state)
|
67
|
+
assert_kind_of(String, @ptable.state)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_pctcpu
|
71
|
+
assert_respond_to(@ptable, :pctcpu)
|
72
|
+
assert_kind_of(Float, @ptable.pctcpu)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_oncpu
|
76
|
+
assert_respond_to(@ptable, :oncpu)
|
77
|
+
assert_kind_of(Fixnum, @ptable.oncpu)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_ttynum
|
81
|
+
assert_respond_to(@ptable, :ttynum)
|
82
|
+
assert_kind_of(Fixnum, @ptable.ttynum)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_ttydev
|
86
|
+
assert_respond_to(@ptable, :ttydev)
|
87
|
+
assert_kind_of(String, @ptable.ttydev)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_wmesg
|
91
|
+
assert_respond_to(@ptable, :wmesg)
|
92
|
+
assert_kind_of(String, @ptable.wmesg)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_time
|
96
|
+
assert_respond_to(@ptable, :time)
|
97
|
+
assert_kind_of(Fixnum, @ptable.time)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_priority
|
101
|
+
assert_respond_to(@ptable, :priority)
|
102
|
+
assert_kind_of(Fixnum, @ptable.priority)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_usrpri
|
106
|
+
assert_respond_to(@ptable, :usrpri)
|
107
|
+
assert_kind_of(Fixnum, @ptable.usrpri)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_nice
|
111
|
+
assert_respond_to(@ptable, :nice)
|
112
|
+
assert_kind_of(Fixnum, @ptable.nice)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_cmdline
|
116
|
+
assert_respond_to(@ptable, :cmdline)
|
117
|
+
assert_kind_of(String, @ptable.cmdline)
|
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_maxrss
|
126
|
+
assert_respond_to(@ptable, :maxrss)
|
127
|
+
assert_true(@ptable.maxrss.kind_of?(Fixnum) || @ptable.maxrss.nil?)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_ixrss
|
131
|
+
assert_respond_to(@ptable, :ixrss)
|
132
|
+
assert_true(@ptable.ixrss.kind_of?(Fixnum) || @ptable.ixrss.nil?)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_idrss
|
136
|
+
assert_respond_to(@ptable, :idrss)
|
137
|
+
assert_true(@ptable.idrss.kind_of?(Fixnum) || @ptable.idrss.nil?)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_isrss
|
141
|
+
assert_respond_to(@ptable, :isrss)
|
142
|
+
assert_true(@ptable.isrss.kind_of?(Fixnum) || @ptable.isrss.nil?)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_minflt
|
146
|
+
assert_respond_to(@ptable, :minflt)
|
147
|
+
assert_true(@ptable.minflt.kind_of?(Fixnum) || @ptable.minflt.nil?)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_majflt
|
151
|
+
assert_respond_to(@ptable, :majflt)
|
152
|
+
assert_true(@ptable.majflt.kind_of?(Fixnum) || @ptable.majflt.nil?)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_nswap
|
156
|
+
assert_respond_to(@ptable, :nswap)
|
157
|
+
assert_true(@ptable.nswap.kind_of?(Fixnum) || @ptable.nswap.nil?)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_inblock
|
161
|
+
assert_respond_to(@ptable, :inblock)
|
162
|
+
assert_true(@ptable.inblock.kind_of?(Fixnum) || @ptable.inblock.nil?)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_oublock
|
166
|
+
assert_respond_to(@ptable, :oublock)
|
167
|
+
assert_true(@ptable.oublock.kind_of?(Fixnum) || @ptable.oublock.nil?)
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_msgsnd
|
171
|
+
assert_respond_to(@ptable, :msgsnd)
|
172
|
+
assert_true(@ptable.msgsnd.kind_of?(Fixnum) || @ptable.msgsnd.nil?)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_msgrcv
|
176
|
+
assert_respond_to(@ptable, :msgrcv)
|
177
|
+
assert_true(@ptable.msgrcv.kind_of?(Fixnum) || @ptable.msgrcv.nil?)
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_nsignals
|
181
|
+
assert_respond_to(@ptable, :nsignals)
|
182
|
+
assert_true(@ptable.nsignals.kind_of?(Fixnum) || @ptable.nsignals.nil?)
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_nvcsw
|
186
|
+
assert_respond_to(@ptable, :nvcsw)
|
187
|
+
assert_true(@ptable.nvcsw.kind_of?(Fixnum) || @ptable.nvcsw.nil?)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_nivcsw
|
191
|
+
assert_respond_to(@ptable, :nivcsw)
|
192
|
+
assert_true(@ptable.nivcsw.kind_of?(Fixnum) || @ptable.nivcsw.nil?)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_utime
|
196
|
+
assert_respond_to(@ptable, :utime)
|
197
|
+
assert_true(@ptable.utime.kind_of?(Fixnum) || @ptable.utime.nil?)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_stime
|
201
|
+
assert_respond_to(@ptable, :stime)
|
202
|
+
assert_true(@ptable.stime.kind_of?(Fixnum) || @ptable.stime.nil?)
|
203
|
+
end
|
204
|
+
|
205
|
+
def teardown
|
206
|
+
@ptable = nil
|
207
|
+
end
|
208
|
+
|
209
|
+
def self.shutdown
|
210
|
+
@@fields = nil
|
211
|
+
end
|
212
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sys-proctable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 57
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
|
+
platform: universal-freebsd
|
12
|
+
authors:
|
13
|
+
- Daniel J. Berger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: test-unit
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
version: 2.1.2
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
description: " The sys-proctable library provides an interface for gathering information\n about processes on your system, i.e. the process table. Most major\n platforms are supported and, while different platforms may return\n different information, the external interface is identical across\n platforms.\n"
|
37
|
+
email: djberg96@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions:
|
41
|
+
- ext/bsd/extconf.rb
|
42
|
+
extra_rdoc_files:
|
43
|
+
- CHANGES
|
44
|
+
- README
|
45
|
+
- MANIFEST
|
46
|
+
- doc/top.txt
|
47
|
+
- ext/bsd/sys/proctable.c
|
48
|
+
files:
|
49
|
+
- benchmarks/bench_ps.rb
|
50
|
+
- examples/example_ps.rb
|
51
|
+
- lib/sys/top.rb
|
52
|
+
- CHANGES
|
53
|
+
- MANIFEST
|
54
|
+
- Rakefile
|
55
|
+
- README
|
56
|
+
- sys-proctable.gemspec
|
57
|
+
- test/test_sys_proctable_all.rb
|
58
|
+
- doc/top.txt
|
59
|
+
- ext/bsd/sys/proctable.c
|
60
|
+
- test/test_sys_proctable_bsd.rb
|
61
|
+
- ext/bsd/extconf.rb
|
62
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
63
|
+
licenses:
|
64
|
+
- Artistic 2.0
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project: sysutils
|
91
|
+
rubygems_version: 1.8.10
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: An interface for providing process table information
|
95
|
+
test_files:
|
96
|
+
- test/test_sys_proctable_all.rb
|
97
|
+
- test/test_sys_proctable_bsd.rb
|