sys-proctable 0.7.6-i586-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/version.h ADDED
@@ -0,0 +1,2 @@
1
+ /* version.h - stores the version number for all platforms (that use C) */
2
+ #define SYS_PROCTABLE_VERSION "0.7.6"
data/lib/sys/top.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "sys/proctable"
2
+ module Sys
3
+ class Top
4
+ VERSION = "1.0.1"
5
+ WINDOWS = PLATFORM.match("mswin")
6
+
7
+ def self.top(num=10, field="pctcpu")
8
+ # Sort by pid on Windows by default
9
+ if WINDOWS && field == "pctcpu"
10
+ field = "pid"
11
+ end
12
+
13
+ # Linux does not have a pctcpu field yet
14
+ if RUBY_PLATFORM =~ /linux/ && field == "pctcpu"
15
+ field = "pid"
16
+ end
17
+
18
+ Sys::ProcTable.ps.sort{ |a,b|
19
+ b.send(field) <=> a.send(field)
20
+ }[0..num-1]
21
+ end
22
+ end
23
+ end
data/test/tc_all.rb ADDED
@@ -0,0 +1,59 @@
1
+ #######################################################################
2
+ # tc_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 'socket'
8
+ require 'test/unit'
9
+ require 'sys/proctable'
10
+ include Sys
11
+
12
+ class TC_ProcTable_All < Test::Unit::TestCase
13
+ def setup
14
+ @host = Socket.gethostname
15
+ @pid = RUBY_PLATFORM.match('mswin') ? 0 : 1
16
+ end
17
+
18
+ def test_version
19
+ assert_equal('0.7.6', ProcTable::VERSION)
20
+ end
21
+
22
+ def test_fields
23
+ assert_respond_to(ProcTable, :fields)
24
+ assert_nothing_raised{ ProcTable.fields }
25
+ assert_kind_of(Array, ProcTable.fields)
26
+ assert_kind_of(String, ProcTable.fields.first)
27
+ end
28
+
29
+ def test_ps
30
+ assert_respond_to(ProcTable, :ps)
31
+ assert_nothing_raised{ ProcTable.ps }
32
+ assert_nothing_raised{ ProcTable.ps{} }
33
+ end
34
+
35
+ def test_ps_with_args
36
+ assert_nothing_raised{ ProcTable.ps(0) }
37
+ assert_nothing_raised{ ProcTable.ps(nil) }
38
+ assert_raises(TypeError){ ProcTable.ps('vim') }
39
+
40
+ if RUBY_PLATFORM.match('mswin')
41
+ assert_nothing_raised{ ProcTable.ps(0, @host) }
42
+ assert_raises(ArgumentError){ ProcTable.ps(0, @host, 1) }
43
+ else
44
+ assert_raises(ArgumentError){ ProcTable.ps(0, @host) }
45
+ end
46
+ end
47
+
48
+ def test_ps_return_values
49
+ assert_kind_of(Array, ProcTable.ps)
50
+ assert_kind_of(Struct::ProcTableStruct, ProcTable.ps(@pid))
51
+ assert_equal(nil, ProcTable.ps(999999999))
52
+ assert_equal(nil, ProcTable.ps{})
53
+ end
54
+
55
+ def teardown
56
+ @host = nil
57
+ @pid = nil
58
+ end
59
+ end
@@ -0,0 +1,45 @@
1
+ ############################################
2
+ # tc_freebsd.rb
3
+ #
4
+ # Test suite for sys-proctable for FreeBSD.
5
+ ############################################
6
+ require "sys/proctable"
7
+ require "test/unit"
8
+ require "test/tc_all"
9
+ include Sys
10
+
11
+ class TC_ProcTable_FreeBSD < Test::Unit::TestCase
12
+ def setup
13
+ @fields = %w/
14
+ comm pid ppid pgid sid tdev_maj tdev_min flags start
15
+ utime stime wchan euid ruid rgid egid groups cmdline
16
+ /
17
+ @pt = ProcTable.ps.first
18
+ end
19
+
20
+ def test_field_members
21
+ msg = "Struct members don't match expected fields"
22
+ assert_equal(@fields.length, @pt.length, "Bad length")
23
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
24
+ assert_equal(@fields, @pt.members, msg)
25
+ end
26
+
27
+ def test_struct_member_types
28
+ @fields.each{ |f|
29
+ if %w/comm cmdline groups wchan flags/.include?(f)
30
+ assert_kind_of(String, @pt.send(f), "Bad #{f} type")
31
+ elsif %w/utime stime/.include?(f)
32
+ assert_kind_of(Float, @pt.send(f), "Bad #{f} type")
33
+ elsif %w/start/.include?(f)
34
+ assert_kind_of(Time, @pt.send(f), "Bad #{f} type")
35
+ else
36
+ assert_kind_of(Fixnum, @pt.send(f), "Bad #{f} type")
37
+ end
38
+ }
39
+ end
40
+
41
+ def teardown
42
+ @fields = nil
43
+ @pt = nil
44
+ end
45
+ end
data/test/tc_hpux.rb ADDED
@@ -0,0 +1,49 @@
1
+ ##################################################
2
+ # tc_hpux.rb
3
+ #
4
+ # Test case for sys-proctable for HP-UX.
5
+ ##################################################
6
+ require "sys/proctable"
7
+ require "test/unit"
8
+ require "test/tc_all"
9
+ include Sys
10
+
11
+ class TC_ProcTable_HPUX < Test::Unit::TestCase
12
+ def setup
13
+ @fields = %w/
14
+ comm uid pid ppid dsize tsize ssize nice ttydev pgrp pri addr
15
+ cpu utime stime start flag stat wchan procnum cmd cmdline time
16
+ cpticks cptickstotal fss pctcpu rssize suid shmsize mmsize usize
17
+ iosize vtsize vdsize vssize vshmsize vmmsize vusize viosize
18
+ minorfaults majorfaults nswap nsignals msgrcv msgsnd maxrss
19
+ sid schedpolicy ticksleft euid egid gid sgid
20
+ /
21
+ @pt = ProcTable.ps.first
22
+ end
23
+
24
+ def test_expected_fields
25
+ msg = "Struct members don't match expected fields"
26
+ assert_equal(@fields.length, @pt.length,"Bad length")
27
+ assert_equal(@fields, ProcTable.fields,"Bad fields")
28
+ assert_equal(@fields, @pt.members,msg)
29
+ end
30
+
31
+ def test_struct_member_types
32
+ @fields.each{ |f|
33
+ if %w/comm stat cmd cmdline ttydev/.include?(f)
34
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
35
+ elsif %w/pctcpu/.include?(f)
36
+ assert_kind_of(Float,@pt.send(f),"Bad #{f} type")
37
+ elsif %w/start/.include(f)
38
+ assert_kind_of(Time,@pt.send(f),"Bad #{f} type")
39
+ else
40
+ assert_kind_of(Fixnum,@pt.send(f),"Bad #{f} type")
41
+ end
42
+ }
43
+ end
44
+
45
+ def teardown
46
+ @fields = nil
47
+ @pt = nil
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ ################################################################
2
+ # tc_kvm_bsd.rb
3
+ #
4
+ # Test suite for the BSD specific version of the kvm interface.
5
+ ################################################################
6
+ require "test/unit"
7
+ require "sys/proctable"
8
+ include Sys
9
+
10
+ class TC_KVM_BSD < Test::Unit::TestCase
11
+ def setup
12
+ @fields = %w/
13
+ pid ppid pgid ruid rgid comm state pct_cpu cpu_num tty_num
14
+ tty_dev wchan time priority usr_priority nice cmdline start_time
15
+ max_rss ix_rss id_rss is_rss minflt maxflt nswap inblock oublock
16
+ msgsnd msgrcv nsignals nvcsw nivcsw user_time system_time
17
+ /
18
+ @pt = ProcTable.ps.first
19
+ end
20
+
21
+ def test_field_members
22
+ msg = "Struct members don't match expected fields"
23
+ assert_equal(@fields.length, @pt.length, "Bad number of fields")
24
+ assert_equal(@fields, ProcTable.fields, "Bad field members")
25
+ assert_equal(@fields, @pt.members, msg)
26
+ end
27
+
28
+ def teardown
29
+ @fields = nil
30
+ end
31
+ end
data/test/tc_linux.rb ADDED
@@ -0,0 +1,45 @@
1
+ ##########################################
2
+ # tc_linux.rb
3
+ #
4
+ # Test suite for sys-proctable for Linux.
5
+ ##########################################
6
+ require "sys/proctable"
7
+ require "test/unit"
8
+ require "test/tc_all"
9
+
10
+ class TC_ProcTable_Linux < Test::Unit::TestCase
11
+
12
+ def setup
13
+ @fields = %w/
14
+ cmdline cwd exe pid name uid euid gid egid comm state ppid pgrp
15
+ session tty_num tpgid flags minflt cminflt majflt cmajflt utime
16
+ stime cutime cstime priority nice itrealvalue starttime vsize
17
+ rss rlim startcode endcode startstack kstkesp kstkeip signal blocked
18
+ sigignore sigcatch wchan nswap cnswap exit_signal processor environ
19
+ /
20
+ @pt = ProcTable.ps.first
21
+ end
22
+
23
+ def test_field_members
24
+ msg = "Struct members don't match expected fields"
25
+ assert_equal(@fields.length, @pt.length, "Bad length")
26
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
27
+ assert_equal(@fields, @pt.members,msg)
28
+ end
29
+
30
+ def test_struct_member_types
31
+ @fields.each{ |f|
32
+ if %w/cmdline cwd exe name comm state/.include?(f)
33
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
34
+ elsif f == "environ"
35
+ assert_kind_of(Hash,@pt.environ,"Bad environ type")
36
+ else
37
+ assert_kind_of(Integer,@pt.send(f),"Bad #{f} type")
38
+ end
39
+ }
40
+ end
41
+
42
+ def teardown
43
+ @pt = nil
44
+ end
45
+ end
data/test/tc_sunos.rb ADDED
@@ -0,0 +1,52 @@
1
+ ##################################################
2
+ # tc_sunos.rb
3
+ #
4
+ # Test suite for sys-proctable for SunOS/Solaris.
5
+ ##################################################
6
+ require "sys/proctable"
7
+ require "test/unit"
8
+ require "test/tc_all"
9
+ include Sys
10
+
11
+ class TC_ProcTable_SunOS < Test::Unit::TestCase
12
+ def setup
13
+ @fields = %w/
14
+ flag nlwp pid ppid pgid sid uid euid gid egid priority
15
+ nice ttydev time ctime size rss wchan pctcpu pctmem
16
+ state fname cmdline start processor comm num_args
17
+ cmd_args lwpid count tstamp create term rtime utime
18
+ stime ttime tftime dftime kftime ltime slptime wtime
19
+ stoptime minf majf nswap inblk oublk msnd mrcv sigs
20
+ vctx ictx sysc ioch
21
+ /
22
+ @pt = ProcTable.ps.first
23
+ end
24
+
25
+ def test_field_members
26
+ msg = "Struct members don't match expected fields"
27
+ assert_equal(@fields.length, @pt.length, "Bad number of fields")
28
+ assert_equal(@fields, ProcTable.fields, "Bad field members")
29
+ assert_equal(@fields, @pt.members, msg)
30
+ end
31
+
32
+ def test_struct_member_types
33
+ @fields.each{ |f|
34
+ if %w/comm state fname cmdline/.include?(f)
35
+ assert_kind_of(String,@pt.send(f),"Bad #{f} type")
36
+ elsif %w/pctcpu pctmem/.include?(f)
37
+ assert_kind_of(Float,@pt.send(f),"Bad #{f} type")
38
+ elsif %w/cmd_args/.include?(f)
39
+ assert_kind_of(Array,@pt.send(f),"Bad #{f} type")
40
+ elsif %w/start/.include?(f)
41
+ assert_kind_of(Time,@pt.send(f),"Bad #{f} type")
42
+ else
43
+ assert_kind_of(Fixnum,@pt.send(f),"Bad #{f} type")
44
+ end
45
+ }
46
+ end
47
+
48
+ def teardown
49
+ @pt = nil
50
+ @fields = nil
51
+ end
52
+ end
data/test/tc_top.rb ADDED
@@ -0,0 +1,26 @@
1
+ ##############################################################################
2
+ # tc_top.rb
3
+ #
4
+ # Test suite for the sys-top package that is included with this distribution.
5
+ ##############################################################################
6
+ require 'test/unit'
7
+ require 'sys/top'
8
+ include Sys
9
+
10
+ class TC_Top < Test::Unit::TestCase
11
+ def test_version
12
+ assert_equal('1.0.1', Top::VERSION)
13
+ end
14
+
15
+ def test_top
16
+ assert_respond_to(Top,:top)
17
+ assert_nothing_raised{ Top.top }
18
+ assert_nothing_raised{ Top.top(5) }
19
+ assert_nothing_raised{ Top.top(5, 'cmdline') }
20
+ assert_raises(ArgumentError){ Top.top(1,'foo',2) }
21
+ assert_kind_of(Array, Top.top)
22
+ assert_equal(10, Top.top.length)
23
+ assert_equal(5, Top.top(5).length)
24
+ assert_kind_of(Struct::ProcTableStruct, Top.top.first)
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ ##################################################
2
+ # tc_windows.rb
3
+ #
4
+ # Test suite for sys-proctable for MS Windows
5
+ ##################################################
6
+ require 'sys/proctable'
7
+ require 'test/unit'
8
+ require 'test/tc_all'
9
+
10
+ class TC_ProcTable_MSWindows < Test::Unit::TestCase
11
+ def setup
12
+ @fields = %w/
13
+ caption cmdline comm creation_class_name creation_date
14
+ cs_creation_class_name cs_name description executable_path
15
+ execution_state handle handle_count install_date kernel_mode_time
16
+ maximum_working_set_size minimum_working_set_size name
17
+ os_creation_class_name os_name other_operation_count
18
+ other_transfer_count page_faults page_file_usage
19
+ peak_virtual_size ppid peak_working_set_size priority
20
+ private_page_count pid quota_non_paged_pool_usage
21
+ quota_paged_pool_usage quota_peak_non_paged_pool_usage
22
+ quota_non_paged_pool_usage read_operation_count read_transfer_count
23
+ session_id termination_date thread_count user_mode_time virtual_size
24
+ windows_version working_set_size write_operation_count write_transfer_count
25
+ /
26
+ @pt = ProcTable.ps.first
27
+ end
28
+
29
+ def test_field_members
30
+ msg = "Struct members don't match expected fields"
31
+ assert_equal(@fields.length, @pt.length, "Bad length")
32
+ assert_equal(@fields, ProcTable.fields, "Bad fields")
33
+ assert_equal(@fields, @pt.members, msg)
34
+ end
35
+
36
+ def teardown
37
+ @pt = nil
38
+ @fields = nil
39
+ end
40
+ end
@@ -0,0 +1,54 @@
1
+ ##########################################################
2
+ # test_memleak.rb
3
+ #
4
+ # Test script to check for memory leaks. For now, it is
5
+ # only supported on Linux.
6
+ ##########################################################
7
+ unless PLATFORM =~ /linux/i
8
+ puts "This program is currently only supported on Linux"
9
+ puts "Exiting program"
10
+ exit!
11
+ end
12
+
13
+ base = File.basename(Dir.pwd)
14
+ if base == "test" || base =~ /^sys-proctable.*/
15
+ require "fileutils"
16
+ Dir.chdir("..") if base == "test"
17
+ $LOAD_PATH.unshift(Dir.pwd)
18
+ File.delete("sys/proctable.so") rescue nil
19
+ Dir.mkdir("sys") rescue nil
20
+ FileUtils.cp("ext/proctable.so", "sys")
21
+ end
22
+
23
+
24
+ require "sys/proctable"
25
+ include Sys
26
+
27
+ pid = Process.pid
28
+ fd_file = "/proc/#{pid}/fd/*"
29
+
30
+ initial_fd = 0 # initial number of file descriptors
31
+ found = false
32
+
33
+ puts "ProcTable VERSION: " + ProcTable::VERSION
34
+
35
+ 0.upto(50){ |n|
36
+ ProcTable.ps
37
+ if 0 == n
38
+ initial_fd = Dir[fd_file].length + 1 # one fd margin of error
39
+ puts "Initial file descriptors in use: #{initial_fd - 1}"
40
+ else
41
+ current_fd = Dir[fd_file].length
42
+ if current_fd > initial_fd
43
+ puts "Possible memory leak. FD count now up to #{current_fd}"
44
+ found = true
45
+ end
46
+ end
47
+ }
48
+
49
+ if found
50
+ puts "You appear to have a file descriptor issue"
51
+ puts "After 50 iterations you had #{n} file descriptors open"
52
+ else
53
+ puts "No apparent fd leaks"
54
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: sys-proctable
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.7.6
7
+ date: 2007-07-11 00:00:00 -06:00
8
+ summary: An interface for providing process table information
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/sysutils
13
+ rubyforge_project: sysutils
14
+ description: An interface for providing process table information
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.0
24
+ version:
25
+ platform: i586-linux
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Daniel J. Berger
31
+ files:
32
+ - doc/freebsd.txt
33
+ - doc/top.txt
34
+ - doc/solaris.txt
35
+ - doc/windows.txt
36
+ - doc/hpux.txt
37
+ - doc/linux.txt
38
+ - test/tc_linux.rb
39
+ - test/tc_sunos.rb
40
+ - test/tc_kvm_bsd.rb
41
+ - test/tc_hpux.rb
42
+ - test/tc_windows.rb
43
+ - test/test_memleak.rb
44
+ - test/tc_all.rb
45
+ - test/tc_freebsd.rb
46
+ - test/tc_top.rb
47
+ - lib/sys/top.rb
48
+ - CHANGES
49
+ - README
50
+ - MANIFEST
51
+ - ext/linux/linux.c
52
+ - ext/extconf.rb
53
+ - ext/version.h
54
+ - ext/linux/linux.h
55
+ test_files:
56
+ - test/tc_linux.rb
57
+ rdoc_options: []
58
+
59
+ extra_rdoc_files:
60
+ - CHANGES
61
+ - README
62
+ - MANIFEST
63
+ - doc/top.txt
64
+ - doc/linux.txt
65
+ - ext/linux/linux.c
66
+ executables: []
67
+
68
+ extensions:
69
+ - ext/extconf.rb
70
+ requirements: []
71
+
72
+ dependencies: []
73
+