sys-proctable 0.7.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/CHANGES +165 -0
  5. data/MANIFEST +33 -41
  6. data/README +115 -135
  7. data/Rakefile +94 -0
  8. data/benchmarks/bench_ps.rb +21 -0
  9. data/doc/top.txt +5 -11
  10. data/examples/example_ps.rb +20 -0
  11. data/lib/aix/sys/proctable.rb +458 -0
  12. data/lib/darwin/sys/proctable.rb +363 -0
  13. data/lib/freebsd/sys/proctable.rb +363 -0
  14. data/lib/linux/sys/proctable.rb +314 -0
  15. data/lib/linux/sys/proctable/cgroup_entry.rb +50 -0
  16. data/lib/linux/sys/proctable/smaps.rb +118 -0
  17. data/lib/sunos/sys/proctable.rb +456 -0
  18. data/lib/sys-proctable.rb +1 -0
  19. data/lib/sys-top.rb +1 -0
  20. data/lib/sys/proctable.rb +18 -0
  21. data/lib/sys/proctable/version.rb +6 -0
  22. data/lib/sys/top.rb +28 -19
  23. data/lib/windows/sys/proctable.rb +208 -0
  24. data/spec/sys_proctable_aix_spec.rb +328 -0
  25. data/spec/sys_proctable_all_spec.rb +89 -0
  26. data/spec/sys_proctable_darwin_spec.rb +120 -0
  27. data/spec/sys_proctable_freebsd_spec.rb +210 -0
  28. data/spec/sys_proctable_linux_spec.rb +310 -0
  29. data/spec/sys_proctable_sunos_spec.rb +316 -0
  30. data/spec/sys_proctable_windows_spec.rb +317 -0
  31. data/spec/sys_top_spec.rb +51 -0
  32. data/sys-proctable.gemspec +38 -0
  33. metadata +140 -64
  34. metadata.gz.sig +0 -0
  35. data/doc/freebsd.txt +0 -90
  36. data/doc/hpux.txt +0 -77
  37. data/doc/linux.txt +0 -85
  38. data/doc/solaris.txt +0 -99
  39. data/doc/windows.txt +0 -122
  40. data/ext/extconf.rb +0 -98
  41. data/ext/sunos/sunos.c +0 -374
  42. data/ext/sunos/sunos.h +0 -177
  43. data/ext/version.h +0 -2
  44. data/test/tc_all.rb +0 -59
  45. data/test/tc_freebsd.rb +0 -45
  46. data/test/tc_hpux.rb +0 -49
  47. data/test/tc_kvm_bsd.rb +0 -31
  48. data/test/tc_linux.rb +0 -45
  49. data/test/tc_sunos.rb +0 -52
  50. data/test/tc_top.rb +0 -26
  51. data/test/tc_windows.rb +0 -40
  52. data/test/test_memleak.rb +0 -54
@@ -1,177 +0,0 @@
1
- /*****************************************************************************
2
- * solaris.h
3
- *
4
- * Solaris specific header file. Some things copy/pasted straight out
5
- * of Dan Urist's Proc::ProcessTable Perl module.
6
- *****************************************************************************/
7
- #include <stdio.h>
8
- #include <stdlib.h>
9
- #include <dirent.h>
10
- #include <sys/param.h>
11
- #include <sys/types.h>
12
- #include <sys/proc.h>
13
- #include <fcntl.h>
14
- #include <string.h>
15
- #include <unistd.h>
16
- #include <utmpx.h>
17
-
18
- /* This bit of magic was taken from a post by Stefan Teleman on the KDE
19
- * mailing list. It allows us to build without having to disable largefile
20
- * support or explicitly build a 64 bit Ruby.
21
- */
22
- #if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
23
- #define PROCFS_FILE_OFFSET_BITS_HACK 1
24
- #undef _FILE_OFFSET_BITS
25
- #else
26
- #define PROCFS_FILE_OFFSET_BITS_HACK 0
27
- #endif
28
-
29
- #if defined(HAVE_PROCFS_H)
30
- #include <procfs.h>
31
- #else
32
- #include <sys/procfs.h>
33
- #endif
34
-
35
- #if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
36
- #define _FILE_OFFSET_BITS 64
37
- #endif
38
-
39
- #ifndef CLK_TCK
40
- #define CLK_TCK sysconf(_SC_CLK_TCK)
41
- #endif
42
-
43
- #ifndef NAME_MAX
44
- #define NAME_MAX 255
45
- #endif
46
-
47
- /* Ruby 1.8.3 or later */
48
- #ifdef HAVE_TYPE_RB_PID_T
49
- #define pid_t rb_pid_t
50
- #endif
51
-
52
- #define COMM_MAX 64
53
- #define STATE_MAX 20
54
- #define WCHAN_MAX 64
55
-
56
- /* Function prototypes */
57
- static void getprusage(pid_t pid, prusage_t* pr_usage);
58
-
59
- /* Process state strings that we return */
60
- #define SLEEP "sleep"
61
- #define WAIT "wait"
62
- #define RUN "run"
63
- #define IDLE "idle"
64
- #define ZOMBIE "zombie"
65
- #define STOP "stop"
66
- #define ONPROC "onprocessor"
67
-
68
- /*
69
- * A simple static structure, mainly for use with the 'fields()' class method.
70
- * The fields here *should* be identical to the fields listed in the ps_struct.
71
- * The exception is the 'comm' field, which I added to give it a bit of
72
- * (foolish?) consistency with the other platforms. I will try to make sure
73
- * that field is common to all platforms.
74
- */
75
- static char* fields[] = {
76
- "flag",
77
- #ifdef HAVE_PROCFS_H
78
- "nlwp",
79
- #endif
80
- "pid",
81
- "ppid",
82
- "pgid",
83
- "sid",
84
- "uid",
85
- "euid",
86
- "gid",
87
- "egid",
88
- "priority",
89
- "nice",
90
- "ttydev",
91
- "time",
92
- "ctime",
93
- "size",
94
- "rss",
95
- "wchan",
96
- "pctcpu",
97
- "pctmem",
98
- "state",
99
- "fname",
100
- "cmdline",
101
- "start",
102
- #ifdef HAVE_PROCFS_H
103
- "processor",
104
- #endif
105
- "comm",
106
- "num_args",
107
- "cmd_args",
108
- "lwpid",
109
- "count",
110
- "tstamp",
111
- "create",
112
- "term",
113
- "rtime",
114
- "utime",
115
- "stime",
116
- "ttime",
117
- "tftime",
118
- "dftime",
119
- "kftime",
120
- "ltime",
121
- "slptime",
122
- "wtime",
123
- "stoptime",
124
- "minf",
125
- "majf",
126
- "nswap",
127
- "inblk",
128
- "oublk",
129
- "msnd",
130
- "mrcv",
131
- "sigs",
132
- "vctx",
133
- "ictx",
134
- "sysc",
135
- "ioch"
136
- };
137
-
138
- /*
139
- * Private function for getting data out of the /proc/self/usage directory.
140
- * Based on Rich Teer's function in "Solaris Systems Programming", p.329
141
- * and p.332.
142
- */
143
- #if defined(HAVE_PROCFS_H)
144
- static void getprusage(pid_t pid, prusage_t* pr_usage){
145
- int fd;
146
- char name[PATH_MAX];
147
-
148
- snprintf(name, PATH_MAX, "/proc/%ld/usage", (long)pid);
149
-
150
- if((fd = open(name, O_RDONLY)) == -1)
151
- rb_sys_fail(0);
152
-
153
- if(read(fd,pr_usage,sizeof(prusage_t)) == -1){
154
- close(fd);
155
- rb_sys_fail(0);
156
- }
157
-
158
- close(fd);
159
- }
160
- #else
161
- static void getprusage(pid_t pid, prusage_t* pr_usage){
162
- int fd;
163
- char name[PATH_MAX];
164
-
165
- snprintf(name, PATH_MAX, "/proc/%ld", (long)pid);
166
-
167
- if((fd = open(name, O_RDONLY)) == -1)
168
- rb_sys_fail(0);
169
-
170
- if(ioctl(fd,PIOCUSAGE,pr_usage) == -1){
171
- close(fd);
172
- rb_sys_fail(0);
173
- }
174
-
175
- close(fd);
176
- }
177
- #endif
@@ -1,2 +0,0 @@
1
- /* version.h - stores the version number for all platforms (that use C) */
2
- #define SYS_PROCTABLE_VERSION "0.7.6"
@@ -1,59 +0,0 @@
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
@@ -1,45 +0,0 @@
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
@@ -1,49 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,45 +0,0 @@
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
@@ -1,52 +0,0 @@
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