sys-proctable 0.7.6-powerpc-darwin
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/CHANGES +233 -0
- data/MANIFEST +41 -0
- data/README +140 -0
- data/doc/freebsd.txt +90 -0
- data/doc/hpux.txt +77 -0
- data/doc/linux.txt +85 -0
- data/doc/solaris.txt +99 -0
- data/doc/top.txt +53 -0
- data/doc/windows.txt +122 -0
- data/ext/darwin/darwin.c +240 -0
- data/ext/extconf.rb +98 -0
- data/ext/version.h +2 -0
- data/lib/sys/top.rb +23 -0
- data/test/tc_all.rb +59 -0
- data/test/tc_freebsd.rb +45 -0
- data/test/tc_hpux.rb +49 -0
- data/test/tc_kvm_bsd.rb +31 -0
- data/test/tc_linux.rb +45 -0
- data/test/tc_sunos.rb +52 -0
- data/test/tc_top.rb +26 -0
- data/test/tc_windows.rb +40 -0
- data/test/test_memleak.rb +54 -0
- metadata +71 -0
data/ext/extconf.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Installation script for sys-proctable.
|
3
|
+
#
|
4
|
+
# By running this file, it is assumed that you want a C extension, and not
|
5
|
+
# a pure Ruby version. If you want a pure Ruby version (and you're on a
|
6
|
+
# platform for which it's supported), run install.rb instead.
|
7
|
+
#############################################################################
|
8
|
+
require 'mkmf'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
c_file = nil
|
12
|
+
h_file = nil
|
13
|
+
tc_file = nil
|
14
|
+
|
15
|
+
########################################################################
|
16
|
+
# Ruby 1.8.3 and later mandates the use of rb_pid_t over pid_t because
|
17
|
+
# some libraries define their own pid_t. So, we check for that.
|
18
|
+
########################################################################
|
19
|
+
have_type('rb_pid_t', 'ruby.h')
|
20
|
+
|
21
|
+
##########################################################################
|
22
|
+
# Determine appropriate source files based on platform. Also, check for
|
23
|
+
# certain header files and/or libraries on some platforms.
|
24
|
+
#
|
25
|
+
# On FreeBSD a different source file is used if the /proc filesystem is
|
26
|
+
# not found (kvm is used instead). For OpenBSD or NetBSD, the kvm
|
27
|
+
# interface is always used for now.
|
28
|
+
##########################################################################
|
29
|
+
case RUBY_PLATFORM
|
30
|
+
when /hpux/i
|
31
|
+
c_file = 'hpux/hpux.c'
|
32
|
+
h_file = 'hpux/hpux.h'
|
33
|
+
tc_file = 'tc_hpux'
|
34
|
+
when /freebsd/i
|
35
|
+
if File.exists?('/proc') && Dir['/proc/*'].length > 0
|
36
|
+
c_file = 'freebsd/freebsd.c'
|
37
|
+
h_file = 'freebsd/freebsd.h'
|
38
|
+
tc_file = 'tc_freebsd'
|
39
|
+
else
|
40
|
+
have_library('kvm')
|
41
|
+
have_struct_member('struct kinfo_proc', 'kp_proc', 'sys/user.h')
|
42
|
+
have_struct_member('struct kinfo_proc', 'kp_eproc', 'sys/user.h')
|
43
|
+
c_file = 'bsd/bsd.c'
|
44
|
+
tc_file = 'tc_kvm_bsd.rb'
|
45
|
+
end
|
46
|
+
when /openbsd|netbsd/
|
47
|
+
have_library('kvm')
|
48
|
+
c_file = 'bsd/bsd.c'
|
49
|
+
tc_file = 'tc_kvm_bsd.rb'
|
50
|
+
when /solaris|sunos/i
|
51
|
+
c_file = 'sunos/sunos.c'
|
52
|
+
h_file = 'sunos/sunos.h'
|
53
|
+
tc_file = 'tc_sunos'
|
54
|
+
have_header('procfs.h') # false means Solaris 2.5.x
|
55
|
+
when /linux/i
|
56
|
+
c_file = 'linux/linux.c'
|
57
|
+
h_file = 'linux/linux.h'
|
58
|
+
tc_file = 'tc_linux'
|
59
|
+
when /darwin/i
|
60
|
+
c_file = 'darwin/darwin.c'
|
61
|
+
tc_file = 'tc_darwin'
|
62
|
+
when /windows|win32|cygwin|mingw|dos/i
|
63
|
+
msg = 'Use the install_pure_ruby.rb script to install on MS Windows'
|
64
|
+
STDERR.puts msg
|
65
|
+
exit
|
66
|
+
else
|
67
|
+
puts 'This platform not currently supported. Exiting...'
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
|
71
|
+
#####################################################################
|
72
|
+
# Move the 'windows.rb' file under 'lib/sys/' to '.orig' to prevent
|
73
|
+
# mkmf from installing it during the 'make install' phase.
|
74
|
+
#####################################################################
|
75
|
+
if File.exists?('../lib/sys/windows.rb')
|
76
|
+
File.rename('../lib/sys/windows.rb', '../lib/sys/windows.orig')
|
77
|
+
end
|
78
|
+
|
79
|
+
###################
|
80
|
+
# build ts_all.rb
|
81
|
+
###################
|
82
|
+
test_file = '../test/ts_all.rb'
|
83
|
+
File.open(test_file, 'w'){ |fh|
|
84
|
+
fh.puts "require 'tc_all'"
|
85
|
+
fh.puts "require '#{tc_file}'"
|
86
|
+
fh.puts "require 'tc_top'"
|
87
|
+
}
|
88
|
+
|
89
|
+
########################################################################
|
90
|
+
# Copy or link files to current directory for create_makefile to work.
|
91
|
+
########################################################################
|
92
|
+
File.delete('proctable.c') rescue nil
|
93
|
+
File.delete(File.basename(h_file)) rescue nil
|
94
|
+
|
95
|
+
FileUtils.cp(c_file, 'proctable.c')
|
96
|
+
FileUtils.cp(h_file, File.basename(h_file)) if h_file
|
97
|
+
|
98
|
+
create_makefile('sys/proctable')
|
data/ext/version.h
ADDED
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
|
data/test/tc_freebsd.rb
ADDED
@@ -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
|
data/test/tc_kvm_bsd.rb
ADDED
@@ -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 pctcpu 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
|