sys-proctable 0.7.3 → 0.7.4
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 +7 -3
- data/MANIFEST +41 -0
- data/README +119 -56
- data/doc/freebsd.txt +43 -54
- data/doc/hpux.txt +40 -52
- data/doc/linux.txt +36 -51
- data/doc/solaris.txt +50 -70
- data/doc/top.txt +44 -45
- data/doc/windows.txt +60 -60
- data/ext/extconf.rb +101 -0
- data/ext/sunos/sunos.c +374 -0
- data/ext/sunos/sunos.h +177 -0
- data/{lib → ext}/version.h +1 -1
- data/lib/sys/top.rb +23 -0
- data/test/tc_all.rb +17 -21
- data/test/tc_freebsd.rb +9 -5
- data/test/tc_hpux.rb +10 -7
- data/test/tc_kvm_bsd.rb +10 -5
- data/test/tc_linux.rb +9 -6
- data/test/tc_sunos.rb +9 -5
- data/test/tc_top.rb +14 -15
- data/test/tc_windows.rb +7 -9
- data/test/test_memleak.rb +2 -2
- metadata +23 -18
- data/extconf.rb +0 -104
- data/lib/os/linux.c +0 -315
- data/lib/os/linux.h +0 -138
- data/test/test.rb +0 -70
data/ext/sunos/sunos.h
ADDED
@@ -0,0 +1,177 @@
|
|
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
|
data/{lib → ext}/version.h
RENAMED
@@ -1,2 +1,2 @@
|
|
1
1
|
/* version.h - stores the version number for all platforms (that use C) */
|
2
|
-
#define SYS_PROCTABLE_VERSION "0.
|
2
|
+
#define SYS_PROCTABLE_VERSION "0.7.4"
|
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
CHANGED
@@ -5,35 +5,31 @@
|
|
5
5
|
##################################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
require
|
10
|
-
Dir.chdir
|
11
|
-
Dir.mkdir("sys") unless File.exists?("sys")
|
12
|
-
$LOAD_PATH.unshift Dir.pwd
|
13
|
-
end
|
14
|
-
|
15
|
-
if File::ALT_SEPARATOR
|
16
|
-
File.copy("lib/os/windows.rb","sys/proctable.rb")
|
17
|
-
else
|
18
|
-
extension = ".so"
|
19
|
-
extension = ".bundle" if RUBY_PLATFORM =~ /powerpc|darwin/i
|
20
|
-
extension = ".sl" if RUBY_PLATFORM =~ /hpux/i
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
Dir.chdir '..' if base == 'test'
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
if RUBY_PLATFORM.match('mswin')
|
13
|
+
File.rename('lib/sys/windows.rb', 'lib/sys/proctable.rb')
|
14
|
+
else
|
15
|
+
require 'rbconfig'
|
16
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
17
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
18
|
+
FileUtils.cp(file, 'sys')
|
26
19
|
end
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift(Dir.pwd)
|
22
|
+
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
27
23
|
end
|
28
24
|
|
29
|
-
require
|
30
|
-
require
|
25
|
+
require 'sys/proctable'
|
26
|
+
require 'test/unit'
|
31
27
|
include Sys
|
32
28
|
|
33
29
|
class TC_ProcTable_All < Test::Unit::TestCase
|
34
30
|
|
35
31
|
def test_version
|
36
|
-
assert_equal('0.
|
32
|
+
assert_equal('0.7.4', ProcTable::VERSION)
|
37
33
|
end
|
38
34
|
|
39
35
|
def test_fields
|
@@ -52,7 +48,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
|
|
52
48
|
def test_ps_with_args
|
53
49
|
assert_nothing_raised{ ProcTable.ps(0) }
|
54
50
|
assert_nothing_raised{ ProcTable.ps(nil) }
|
55
|
-
assert_raises(TypeError){ ProcTable.ps(
|
51
|
+
assert_raises(TypeError){ ProcTable.ps('vim') }
|
56
52
|
assert_raises(ArgumentError){ ProcTable.ps(0,1) }
|
57
53
|
end
|
58
54
|
|
data/test/tc_freebsd.rb
CHANGED
@@ -5,11 +5,15 @@
|
|
5
5
|
############################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
require
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
Dir.chdir '..' if base == 'test'
|
13
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
14
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
15
|
+
FileUtils.cp(file, 'sys')
|
16
|
+
|
13
17
|
$LOAD_PATH.unshift(Dir.pwd)
|
14
18
|
end
|
15
19
|
|
data/test/tc_hpux.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
##################################################
|
2
2
|
# tc_hpux.rb
|
3
3
|
#
|
4
|
-
# Test
|
5
|
-
# Requires testunit 0.1.6 or later.
|
4
|
+
# Test case for sys-proctable for HP-UX.
|
6
5
|
##################################################
|
7
6
|
base = File.basename(Dir.pwd)
|
8
7
|
|
9
|
-
if base ==
|
10
|
-
require
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
Dir.chdir('..') if base == 'test'
|
13
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
14
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
15
|
+
FileUtils.cp(file, 'sys')
|
16
|
+
|
14
17
|
$LOAD_PATH.unshift(Dir.pwd)
|
15
18
|
end
|
16
19
|
|
data/test/tc_kvm_bsd.rb
CHANGED
@@ -4,11 +4,16 @@
|
|
4
4
|
# Test suite for the BSD specific version of the kvm interface.
|
5
5
|
################################################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
Dir.chdir '..' if base == 'test'
|
13
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
14
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
15
|
+
FileUtils.cp(file, 'sys')
|
16
|
+
|
12
17
|
$LOAD_PATH.unshift(Dir.pwd)
|
13
18
|
end
|
14
19
|
|
data/test/tc_linux.rb
CHANGED
@@ -5,12 +5,15 @@
|
|
5
5
|
##########################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
require
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
Dir.chdir '..' if base == 'test'
|
13
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
14
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
15
|
+
FileUtils.cp(file, 'sys')
|
16
|
+
|
14
17
|
$LOAD_PATH.unshift(Dir.pwd)
|
15
18
|
end
|
16
19
|
|
data/test/tc_sunos.rb
CHANGED
@@ -5,11 +5,15 @@
|
|
5
5
|
##################################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
require
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
require 'rbconfig'
|
11
|
+
|
12
|
+
Dir.chdir '..' if base == 'test'
|
13
|
+
file = 'ext/proctable.' + Config::CONFIG['DLEXT']
|
14
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
15
|
+
FileUtils.cp(file, 'sys')
|
16
|
+
|
13
17
|
$LOAD_PATH.unshift(Dir.pwd)
|
14
18
|
end
|
15
19
|
|
data/test/tc_top.rb
CHANGED
@@ -5,33 +5,32 @@
|
|
5
5
|
##############################################################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
require
|
10
|
-
Dir.chdir(
|
11
|
-
Dir.mkdir(
|
12
|
-
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
require 'fileutils'
|
10
|
+
Dir.chdir('..') if base == 'test'
|
11
|
+
Dir.mkdir('sys') unless File.exists?('sys')
|
12
|
+
FileUtils.cp('lib/top.rb', 'sys')
|
13
13
|
$LOAD_PATH.unshift Dir.pwd
|
14
|
-
$LOAD_PATH.unshift Dir.pwd + "/lib"
|
15
14
|
end
|
16
15
|
|
17
|
-
require
|
18
|
-
require
|
16
|
+
require 'sys/top'
|
17
|
+
require 'test/unit'
|
19
18
|
include Sys
|
20
19
|
|
21
20
|
class TC_Top < Test::Unit::TestCase
|
22
21
|
def test_version
|
23
|
-
assert_equal(
|
22
|
+
assert_equal('1.0.1', Top::VERSION)
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_top
|
27
26
|
assert_respond_to(Top,:top)
|
28
27
|
assert_nothing_raised{ Top.top }
|
29
28
|
assert_nothing_raised{ Top.top(5) }
|
30
|
-
assert_nothing_raised{ Top.top(5,
|
31
|
-
assert_raises(ArgumentError){ Top.top(1,
|
32
|
-
assert_kind_of(Array,Top.top)
|
33
|
-
assert_equal(10,Top.top.length)
|
34
|
-
assert_equal(5,Top.top(5).length)
|
35
|
-
assert_kind_of(Struct::ProcTableStruct,Top.top.first)
|
29
|
+
assert_nothing_raised{ Top.top(5, 'cmdline') }
|
30
|
+
assert_raises(ArgumentError){ Top.top(1,'foo',2) }
|
31
|
+
assert_kind_of(Array, Top.top)
|
32
|
+
assert_equal(10, Top.top.length)
|
33
|
+
assert_equal(5, Top.top(5).length)
|
34
|
+
assert_kind_of(Struct::ProcTableStruct, Top.top.first)
|
36
35
|
end
|
37
36
|
end
|
data/test/tc_windows.rb
CHANGED
@@ -5,17 +5,15 @@
|
|
5
5
|
##################################################
|
6
6
|
base = File.basename(Dir.pwd)
|
7
7
|
|
8
|
-
if base ==
|
9
|
-
|
10
|
-
|
11
|
-
Dir.
|
12
|
-
File.copy("lib/os/windows.rb","sys/proctable.rb")
|
13
|
-
$LOAD_PATH.unshift Dir.pwd
|
8
|
+
if base == 'test' || base =~ /sys-proctable.*/
|
9
|
+
Dir.chdir('..') if base == 'test'
|
10
|
+
File.rename("lib/sys/windows.rb", "lib/sys/proctable.rb")
|
11
|
+
$LOAD_PATH.unshift(Dir.pwd + '/lib')
|
14
12
|
end
|
15
13
|
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
14
|
+
require 'sys/proctable'
|
15
|
+
require 'test/unit'
|
16
|
+
require 'test/tc_all'
|
19
17
|
include Sys
|
20
18
|
|
21
19
|
class TC_ProcTable_MSWindows < Test::Unit::TestCase
|