sys-proctable 0.9.1-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
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,213 @@
1
+ ########################################################################
2
+ # test_sys_proctable_darwin.rb
3
+ #
4
+ # Test suite for the Darwin version of the sys-proctable library. You
5
+ # should run these tests 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_Darwin < Test::Unit::TestCase
15
+ def self.startup
16
+ @@fields = %w/
17
+ pid ppid pgid ruid rgid comm state pctcpu oncpu tnum
18
+ tdev wmesg rtime priority usrpri nice cmdline starttime
19
+ maxrss ixrss idrss isrss minflt majflt nswap inblock oublock
20
+ msgsnd msgrcv nsignals nvcsw nivcsw utime stime
21
+ /
22
+ end
23
+
24
+ def setup
25
+ @ptable = ProcTable.ps.last
26
+ end
27
+
28
+ def test_fields
29
+ assert_respond_to(ProcTable, :fields)
30
+ assert_kind_of(Array, ProcTable.fields)
31
+ assert_equal(@@fields, ProcTable.fields)
32
+ end
33
+
34
+ def test_pid
35
+ assert_respond_to(@ptable, :pid)
36
+ assert_kind_of(Fixnum, @ptable.pid)
37
+ end
38
+
39
+ def test_ppid
40
+ assert_respond_to(@ptable, :ppid)
41
+ assert_kind_of(Fixnum, @ptable.ppid)
42
+ end
43
+
44
+ def test_pgid
45
+ assert_respond_to(@ptable, :pgid)
46
+ assert_kind_of(Fixnum, @ptable.pgid)
47
+ end
48
+
49
+ def test_ruid
50
+ assert_respond_to(@ptable, :ruid)
51
+ assert_kind_of(Fixnum, @ptable.ruid)
52
+ end
53
+
54
+ def test_rgid
55
+ assert_respond_to(@ptable, :rgid)
56
+ assert_kind_of(Fixnum, @ptable.rgid)
57
+ end
58
+
59
+ def test_comm
60
+ assert_respond_to(@ptable, :comm)
61
+ assert_kind_of(String, @ptable.comm)
62
+ assert_true(@ptable.comm.length > 0)
63
+ end
64
+
65
+ def test_state
66
+ assert_respond_to(@ptable, :state)
67
+ assert_kind_of(String, @ptable.state)
68
+ assert_true(%w/idle run sleep stop zombie unknown/.include?(@ptable.state))
69
+ end
70
+
71
+ def test_pctcpu
72
+ assert_respond_to(@ptable, :pctcpu)
73
+ assert_kind_of(Float, @ptable.pctcpu)
74
+ end
75
+
76
+ def test_oncpu
77
+ assert_respond_to(@ptable, :oncpu)
78
+ omit("oncpu always nil for now")
79
+ end
80
+
81
+ def test_tnum
82
+ assert_respond_to(@ptable, :tnum)
83
+ #assert_kind_of(Fixnum, @ptable.tnum)
84
+ end
85
+
86
+ def test_tdev
87
+ assert_respond_to(@ptable, :tdev)
88
+ #assert_kind_of(String, @ptable.tdev)
89
+ end
90
+
91
+ def test_wmesg
92
+ assert_respond_to(@ptable, :wmesg)
93
+ assert_kind_of(String, @ptable.wmesg)
94
+ end
95
+
96
+ def test_rtime
97
+ assert_respond_to(@ptable, :rtime)
98
+ assert_kind_of(Fixnum, @ptable.rtime)
99
+ end
100
+
101
+ def test_priority
102
+ assert_respond_to(@ptable, :priority)
103
+ assert_kind_of(Fixnum, @ptable.priority)
104
+ end
105
+
106
+ def test_usrpri
107
+ assert_respond_to(@ptable, :usrpri)
108
+ assert_kind_of(Fixnum, @ptable.usrpri)
109
+ end
110
+
111
+ def test_nice
112
+ assert_respond_to(@ptable, :nice)
113
+ assert_kind_of(Fixnum, @ptable.nice)
114
+ end
115
+
116
+ def test_cmdline
117
+ assert_respond_to(@ptable, :cmdline)
118
+ assert_kind_of(String, @ptable.cmdline)
119
+ end
120
+
121
+ def test_starttime
122
+ assert_respond_to(@ptable, :starttime)
123
+ assert_kind_of(Time, @ptable.starttime)
124
+ end
125
+
126
+ def test_maxrss
127
+ assert_respond_to(@ptable, :maxrss)
128
+ assert_true([NilClass, Fixnum].include?(@ptable.maxrss.class))
129
+ end
130
+
131
+ def test_ixrss
132
+ assert_respond_to(@ptable, :ixrss)
133
+ assert_true([NilClass, Fixnum].include?(@ptable.ixrss.class))
134
+ end
135
+
136
+ def test_idrss
137
+ assert_respond_to(@ptable, :idrss)
138
+ assert_true([NilClass, Fixnum].include?(@ptable.idrss.class))
139
+ end
140
+
141
+ def test_isrss
142
+ assert_respond_to(@ptable, :isrss)
143
+ assert_true([NilClass, Fixnum].include?(@ptable.isrss.class))
144
+ end
145
+
146
+ def test_minflt
147
+ assert_respond_to(@ptable, :minflt)
148
+ assert_true([NilClass, Fixnum].include?(@ptable.minflt.class))
149
+ end
150
+
151
+ def test_majflt
152
+ assert_respond_to(@ptable, :majflt)
153
+ assert_true([NilClass, Fixnum].include?(@ptable.majflt.class))
154
+ end
155
+
156
+ def test_nswap
157
+ assert_respond_to(@ptable, :nswap)
158
+ assert_true([NilClass, Fixnum].include?(@ptable.nswap.class))
159
+ end
160
+
161
+ def test_inblock
162
+ assert_respond_to(@ptable, :inblock)
163
+ assert_true([NilClass, Fixnum].include?(@ptable.inblock.class))
164
+ end
165
+
166
+ def test_oublock
167
+ assert_respond_to(@ptable, :oublock)
168
+ assert_true([NilClass, Fixnum].include?(@ptable.oublock.class))
169
+ end
170
+
171
+ def test_msgsnd
172
+ assert_respond_to(@ptable, :msgsnd)
173
+ assert_true([NilClass, Fixnum].include?(@ptable.msgsnd.class))
174
+ end
175
+
176
+ def test_msgrcv
177
+ assert_respond_to(@ptable, :msgrcv)
178
+ assert_true([NilClass, Fixnum].include?(@ptable.msgrcv.class))
179
+ end
180
+
181
+ def test_nsignals
182
+ assert_respond_to(@ptable, :nsignals)
183
+ assert_true([NilClass, Fixnum].include?(@ptable.nsignals.class))
184
+ end
185
+
186
+ def test_nvcsw
187
+ assert_respond_to(@ptable, :nvcsw)
188
+ assert_true([NilClass, Fixnum].include?(@ptable.nvcsw.class))
189
+ end
190
+
191
+ def test_nivcsw
192
+ assert_respond_to(@ptable, :nivcsw)
193
+ assert_true([NilClass, Fixnum].include?(@ptable.nivcsw.class))
194
+ end
195
+
196
+ def test_utime
197
+ assert_respond_to(@ptable, :utime)
198
+ assert_true([NilClass, Fixnum].include?(@ptable.utime.class))
199
+ end
200
+
201
+ def test_stime
202
+ assert_respond_to(@ptable, :stime)
203
+ assert_true([NilClass, Fixnum].include?(@ptable.stime.class))
204
+ end
205
+
206
+ def teardown
207
+ @ptable = nil
208
+ end
209
+
210
+ def self.shutdown
211
+ @@fields = nil
212
+ end
213
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sys-proctable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 1
9
+ version: 0.9.1
10
+ platform: universal-darwin
11
+ authors:
12
+ - Daniel J. Berger
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-20 00:00:00 -06:00
18
+ default_executable:
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
+ segments:
29
+ - 2
30
+ - 1
31
+ - 2
32
+ version: 2.1.2
33
+ type: :development
34
+ version_requirements: *id001
35
+ 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"
36
+ email: djberg96@gmail.com
37
+ executables: []
38
+
39
+ extensions:
40
+ - ext/darwin/extconf.rb
41
+ extra_rdoc_files:
42
+ - CHANGES
43
+ - README
44
+ - MANIFEST
45
+ - doc/top.txt
46
+ - ext/darwin/sys/proctable.c
47
+ files:
48
+ - benchmarks/bench_ps.rb
49
+ - examples/example_ps.rb
50
+ - lib/sys/top.rb
51
+ - CHANGES
52
+ - MANIFEST
53
+ - Rakefile
54
+ - README
55
+ - sys-proctable.gemspec
56
+ - test/test_sys_proctable_all.rb
57
+ - doc/top.txt
58
+ - ext/darwin/sys/proctable.c
59
+ - test/test_sys_proctable_darwin.rb
60
+ - ext/darwin/extconf.rb
61
+ has_rdoc: true
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
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project: sysutils
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: An interface for providing process table information
93
+ test_files:
94
+ - test/test_sys_proctable_all.rb
95
+ - test/test_sys_proctable_darwin.rb