sys-proctable 0.9.1-universal-darwin → 0.9.2-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.9.2 - 8-Oct-2012
2
+ * Added cmdline support for OS X. Thanks go to Matthias Zirnstein for
3
+ the patch.
4
+ * Warning cleanup for 1.9.
5
+ * Updated the gem platform handling. Replaced the borked string approach
6
+ with a two element array for Gem::Platform.new.
7
+ * MS date strings are now parse with DateTime instead of Date.
8
+
1
9
  == 0.9.1 - 3-Aug-2011
2
10
  * Added the pctcpu and pctmem members for Linux.
3
11
  * Added Errno::ESRCH to a rescue clause on Linux that fixed a bug
data/README CHANGED
@@ -20,6 +20,7 @@
20
20
  gem install sys-proctable --platform mswin32 # Windows
21
21
  gem install sys-proctable --platform sunos # Solaris
22
22
  gem install sys-proctable --platform linux # Linux
23
+ gem install sys-proctable --platform freebsd # BSD (any flavor)
23
24
 
24
25
  == Synopsis
25
26
  require 'sys/proctable'
@@ -58,15 +59,6 @@
58
59
  The cmdline member on Solaris is limited to 80 characters unless you (or
59
60
  your program) own the process. This is a Solaris design flaw/feature.
60
61
 
61
- === OS X
62
- At the moment you do not get the full command line string. The code required
63
- to get this information is obnoxious and I don't have any compelling desire
64
- to add it. However, if you're willing to submit a patch I'll accept it.
65
-
66
- You can find a good starting point with the OS X code found in Dan Urist's
67
- Proc::ProcessTable module. You can find that module on CPAN. Point your
68
- browser at http://search.cpan.org.
69
-
70
62
  === Thread Safety
71
63
  I am not currently using a thread-safe version of readdir() for versions
72
64
  of this library that use C. I am not especially concerned about it either.
@@ -94,7 +86,8 @@
94
86
  euid, gid and guid info in the Linux version, along with some general
95
87
  debugging help.
96
88
 
97
- Thanks go to David Felstead for the original OS X code.
89
+ Thanks go to David Felstead for the original OS X code. Thanks also go
90
+ to Matthias Zirnstein for adding cmdline support for OS X.
98
91
 
99
92
  Finally I'd like to thank all the folks who have submitted bug reports
100
93
  and/or patches.
@@ -112,7 +105,7 @@
112
105
  Artistic 2.0
113
106
 
114
107
  == Copyright
115
- (C) 2003-2010 Daniel J. Berger
108
+ (C) 2003-2012 Daniel J. Berger
116
109
  All Rights Reserved.
117
110
 
118
111
  == Author
data/Rakefile CHANGED
@@ -2,12 +2,13 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rbconfig'
5
- include Config
5
+ include RbConfig
6
6
 
7
7
  CLEAN.include(
8
8
  '**/*.core', # Core dump files
9
9
  '**/*.gem', # Gem files
10
10
  '**/*.rbc', # Rubinius
11
+ '.rbx', '**/*/.rbx', # Rubinius
11
12
  '**/*.o', # C object file
12
13
  '**/*.log', # Ruby extension build log
13
14
  '**/Makefile', # C Makefile
@@ -17,7 +18,7 @@ CLEAN.include(
17
18
 
18
19
  desc 'Build the sys-proctable library for C versions of sys-proctable'
19
20
  task :build => [:clean] do
20
- case Config::CONFIG['host_os']
21
+ case CONFIG['host_os']
21
22
  when /bsd/i
22
23
  dir = 'ext/bsd'
23
24
  when /darwin/i
@@ -26,11 +27,11 @@ task :build => [:clean] do
26
27
  dir = 'ext/hpux'
27
28
  end
28
29
 
29
- unless Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
30
+ unless CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
30
31
  Dir.chdir(dir) do
31
32
  ruby 'extconf.rb'
32
33
  sh 'make'
33
- cp 'proctable.' + Config::CONFIG['DLEXT'], 'sys'
34
+ cp 'proctable.' + CONFIG['DLEXT'], 'sys'
34
35
  end
35
36
  end
36
37
  end
@@ -38,11 +39,11 @@ end
38
39
  desc 'Install the sys-proctable library'
39
40
  task :install => [:build] do
40
41
  file = nil
41
- dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
42
+ dir = File.join(CONFIG['sitelibdir'], 'sys')
42
43
 
43
44
  Dir.mkdir(dir) unless File.exists?(dir)
44
45
 
45
- case Config::CONFIG['host_os']
46
+ case CONFIG['host_os']
46
47
  when /mswin|win32|msdos|cygwin|mingw|windows/i
47
48
  file = 'lib/windows/sys/proctable.rb'
48
49
  when /linux/i
@@ -62,13 +63,13 @@ end
62
63
 
63
64
  desc 'Uninstall the sys-proctable library'
64
65
  task :uninstall do
65
- case Config::CONFIG['host_os']
66
+ case CONFIG['host_os']
66
67
  when /win32|mswin|dos|cygwin|mingw|windows|linux|sunos|solaris/i
67
- dir = File.join(Config::CONFIG['sitelibdir'], 'sys')
68
+ dir = File.join(CONFIG['sitelibdir'], 'sys')
68
69
  file = File.join(dir, 'proctable.rb')
69
70
  else
70
- dir = File.join(Config::CONFIG['sitearchdir'], 'sys')
71
- file = File.join(dir, 'proctable.' + Config::CONFIG['DLEXT'])
71
+ dir = File.join(CONFIG['sitearchdir'], 'sys')
72
+ file = File.join(dir, 'proctable.' + CONFIG['DLEXT'])
72
73
  end
73
74
 
74
75
  rm(file)
@@ -89,7 +90,7 @@ Rake::TestTask.new do |t|
89
90
  task :test => :build
90
91
  t.libs << 'test' << '.'
91
92
 
92
- case Config::CONFIG['host_os']
93
+ case CONFIG['host_os']
93
94
  when /mswin|msdos|cygwin|mingw|windows/i
94
95
  t.test_files = FileList['test/test_sys_proctable_windows.rb']
95
96
  t.libs << 'lib/windows'
@@ -120,46 +121,46 @@ namespace :gem do
120
121
  # in order to get the universal platform settings I want because
121
122
  # of some bugginess in Rubygems' platform.rb.
122
123
  #
123
- case Config::CONFIG['host_os']
124
+ case CONFIG['host_os']
124
125
  when /bsd/i
125
- spec.platform = Gem::Platform.new('universal-bsd')
126
+ spec.platform = Gem::Platform.new(['universal', 'freebsd'])
127
+ spec.platform.version = nil
126
128
  spec.files << 'ext/bsd/sys/proctable.c'
127
129
  spec.extra_rdoc_files << 'ext/bsd/sys/proctable.c'
128
130
  spec.test_files << 'test/test_sys_proctable_bsd.rb'
129
131
  spec.extensions = ['ext/bsd/extconf.rb']
130
132
  when /darwin/i
131
- spec.platform = Gem::Platform.new('universal-darwin')
133
+ spec.platform = Gem::Platform.new(['universal', 'darwin'])
132
134
  spec.files << 'ext/darwin/sys/proctable.c'
133
135
  spec.extra_rdoc_files << 'ext/darwin/sys/proctable.c'
134
136
  spec.test_files << 'test/test_sys_proctable_darwin.rb'
135
137
  spec.extensions = ['ext/darwin/extconf.rb']
136
138
  when /hpux/i
137
- spec.platform = Gem::Platform.new('universal-hpux')
139
+ spec.platform = Gem::Platform.new(['universal', 'hpux'])
138
140
  spec.files << 'ext/hpux/sys/proctable.c'
139
141
  spec.extra_rdoc_files << 'ext/hpux/sys/proctable.c'
140
142
  spec.test_files << 'test/test_sys_proctable_hpux.rb'
141
143
  spec.extensions = ['ext/hpux/extconf.rb']
142
144
  when /linux/i
143
- spec.platform = Gem::Platform.new('universal-linux')
145
+ spec.platform = Gem::Platform.new(['universal', 'linux'])
144
146
  spec.require_paths = ['lib', 'lib/linux']
145
147
  spec.files += ['lib/linux/sys/proctable.rb']
146
148
  spec.test_files << 'test/test_sys_proctable_linux.rb'
147
149
  when /sunos|solaris/i
148
- spec.platform = Gem::Platform.new('universal-solaris10.0')
149
- spec.platform.version = nil
150
+ spec.platform = Gem::Platform.new(['universal', 'solaris'])
150
151
  spec.require_paths = ['lib', 'lib/sunos']
151
152
  spec.files += ['lib/sunos/sys/proctable.rb']
152
153
  spec.test_files << 'test/test_sys_proctable_sunos.rb'
153
154
  when /mswin|win32|dos|cygwin|mingw|windows/i
154
- spec.platform = Gem::Platform::CURRENT
155
- spec.platform.cpu = 'universal'
156
- spec.platform.version = nil
155
+ spec.platform = Gem::Platform.new(['universal', 'mingw'])
157
156
  spec.require_paths = ['lib', 'lib/windows']
158
157
  spec.files += ['lib/windows/sys/proctable.rb']
159
158
  spec.test_files << 'test/test_sys_proctable_windows.rb'
160
159
  end
161
-
160
+
161
+ # https://github.com/rubygems/rubygems/issues/147
162
162
  spec.original_platform = spec.platform
163
+
163
164
  Gem::Builder.new(spec).build
164
165
  end
165
166
 
@@ -13,7 +13,12 @@
13
13
  #include <sys/user.h>
14
14
  #include <errno.h>
15
15
 
16
- #define SYS_PROCTABLE_VERSION "0.9.1"
16
+ #include <stdio.h>
17
+ #include <stdlib.h>
18
+ #include <string.h>
19
+ #define pid_of(pproc) pproc->kp_proc.p_pid
20
+
21
+ #define SYS_PROCTABLE_VERSION "0.9.2"
17
22
 
18
23
  #define PROC_MIB_LEN 4
19
24
  #define ARGS_MIB_LEN 3
@@ -28,6 +33,160 @@ const char* fields[] = {
28
33
  "nivcsw", "utime", "stime"
29
34
  };
30
35
 
36
+ int argv_of_pid(int pid, char* cmdline) {
37
+ int mib[3], argmax, nargs, c = 0;
38
+ size_t size;
39
+ char *procargs, *sp, *np, *cp;
40
+ int show_args = 1;
41
+
42
+ /* fprintf(stderr, "Getting argv of PID %d\n", pid); */
43
+
44
+ mib[0] = CTL_KERN;
45
+ mib[1] = KERN_ARGMAX;
46
+
47
+ size = sizeof(argmax);
48
+ if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1) {
49
+ goto ERROR_A;
50
+ }
51
+
52
+ /* Allocate space for the arguments. */
53
+ procargs = (char *)malloc(argmax);
54
+ if (procargs == NULL) {
55
+ goto ERROR_A;
56
+ }
57
+
58
+
59
+ /*
60
+ * Make a sysctl() call to get the raw argument space of the process.
61
+ * The layout is documented in start.s, which is part of the Csu
62
+ * project. In summary, it looks like:
63
+ *
64
+ * /---------------\ 0x00000000
65
+ * : :
66
+ * : :
67
+ * |---------------|
68
+ * | argc |
69
+ * |---------------|
70
+ * | arg[0] |
71
+ * |---------------|
72
+ * : :
73
+ * : :
74
+ * |---------------|
75
+ * | arg[argc - 1] |
76
+ * |---------------|
77
+ * | 0 |
78
+ * |---------------|
79
+ * | env[0] |
80
+ * |---------------|
81
+ * : :
82
+ * : :
83
+ * |---------------|
84
+ * | env[n] |
85
+ * |---------------|
86
+ * | 0 |
87
+ * |---------------| <-- Beginning of data returned by sysctl() is here.
88
+ * | argc |
89
+ * |---------------|
90
+ * | exec_path |
91
+ * |:::::::::::::::|
92
+ * | |
93
+ * | String area. |
94
+ * | |
95
+ * |---------------| <-- Top of stack.
96
+ * : :
97
+ * : :
98
+ * \---------------/ 0xffffffff
99
+ */
100
+ mib[0] = CTL_KERN;
101
+ mib[1] = KERN_PROCARGS2;
102
+ mib[2] = pid;
103
+
104
+
105
+ size = (size_t)argmax;
106
+ if (sysctl(mib, 3, procargs, &size, NULL, 0) == -1) {
107
+ goto ERROR_B;
108
+ }
109
+
110
+ memcpy(&nargs, procargs, sizeof(nargs));
111
+ cp = procargs + sizeof(nargs);
112
+
113
+ /* Skip the saved exec_path. */
114
+ for (; cp < &procargs[size]; cp++) {
115
+ if (*cp == '\0') {
116
+ /* End of exec_path reached. */
117
+ break;
118
+ }
119
+ }
120
+ if (cp == &procargs[size]) {
121
+ goto ERROR_B;
122
+ }
123
+
124
+ /* Skip trailing '\0' characters. */
125
+ for (; cp < &procargs[size]; cp++) {
126
+ if (*cp != '\0') {
127
+ /* Beginning of first argument reached. */
128
+ break;
129
+ }
130
+ }
131
+ if (cp == &procargs[size]) {
132
+ goto ERROR_B;
133
+ }
134
+ /* Save where the argv[0] string starts. */
135
+ sp = cp;
136
+
137
+ /*
138
+ * Iterate through the '\0'-terminated strings and convert '\0' to ' '
139
+ * until a string is found that has a '=' character in it (or there are
140
+ * no more strings in procargs). There is no way to deterministically
141
+ * know where the command arguments end and the environment strings
142
+ * start, which is why the '=' character is searched for as a heuristic.
143
+ */
144
+ for (np = NULL; c < nargs && cp < &procargs[size]; cp++) {
145
+ if (*cp == '\0') {
146
+ c++;
147
+ if (np != NULL) {
148
+ /* Convert previous '\0'. */
149
+ *np = ' ';
150
+ } else {
151
+ /* *argv0len = cp - sp; */
152
+ }
153
+ /* Note location of current '\0'. */
154
+ np = cp;
155
+
156
+ if (!show_args) {
157
+ /*
158
+ * Don't convert '\0' characters to ' '.
159
+ * However, we needed to know that the
160
+ * command name was terminated, which we
161
+ * now know.
162
+ */
163
+ break;
164
+ }
165
+ }
166
+ }
167
+
168
+ /*
169
+ * sp points to the beginning of the arguments/environment string, and
170
+ * np should point to the '\0' terminator for the string.
171
+ */
172
+ if (np == NULL || np == sp) {
173
+ /* Empty or unterminated string. */
174
+ goto ERROR_B;
175
+ }
176
+
177
+ /* Make a copy of the string. */
178
+ strcpy(cmdline, sp);
179
+
180
+ /* Clean up. */
181
+ free(procargs);
182
+ return 0;
183
+
184
+ ERROR_B:
185
+ free(procargs);
186
+ ERROR_A:
187
+ return -1;
188
+ }
189
+
31
190
  /*
32
191
  * call-seq:
33
192
  * ProcTable.ps(pid=nil)
@@ -102,6 +261,10 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
102
261
  } else {
103
262
  fprintf(stderr, "err: %s LEN: %d\n", strerror(errno), args_size);
104
263
  }*/
264
+ char cmdline[ARGS_MAX_LEN+1];
265
+
266
+ argv_of_pid(procs[i].kp_proc.p_pid, &cmdline);
267
+ /* free(cmdline); */
105
268
 
106
269
  // Get the start time of the process
107
270
  v_start_time = rb_time_new(
@@ -156,7 +319,7 @@ static VALUE pt_ps(int argc, VALUE* argv, VALUE klass){
156
319
  INT2FIX(procs[i].kp_proc.p_priority),
157
320
  INT2FIX(procs[i].kp_proc.p_usrpri),
158
321
  INT2FIX(procs[i].kp_proc.p_nice),
159
- rb_str_new2(args),
322
+ rb_str_new2(cmdline),
160
323
  v_start_time,
161
324
  (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_maxrss) : Qnil,
162
325
  (procs[i].kp_proc.p_ru && procs[i].kp_proc.p_stat != 5) ? LONG2NUM(procs[i].kp_proc.p_ru->ru_ixrss) : Qnil,
@@ -253,3 +416,4 @@ void Init_proctable(){
253
416
  "utime","stime", NULL
254
417
  );
255
418
  }
419
+
@@ -1,5 +1,4 @@
1
1
  require 'sys/proctable'
2
- require 'rbconfig'
3
2
 
4
3
  # The Sys module serves as a namespace only
5
4
  module Sys
@@ -19,10 +18,8 @@ module Sys
19
18
  def self.top(num=10, field='pctcpu')
20
19
  field = field.to_s if field.is_a?(Symbol)
21
20
 
22
- windows = /mswin|win32|windows|dos|cygwin|mingw/i
23
-
24
21
  # Sort by pid on Windows by default
25
- if Config::CONFIG['host_os'].match(windows) && field == 'pctcpu'
22
+ if File::ALT_SEPARATOR && field == 'pctcpu'
26
23
  field = 'pid'
27
24
  end
28
25
 
@@ -1,9 +1,8 @@
1
1
  require 'rubygems'
2
- require 'rbconfig'
3
2
 
4
3
  Gem::Specification.new do |spec|
5
4
  spec.name = 'sys-proctable'
6
- spec.version = '0.9.1'
5
+ spec.version = '0.9.2'
7
6
  spec.author = 'Daniel J. Berger'
8
7
  spec.license = 'Artistic 2.0'
9
8
  spec.email = 'djberg96@gmail.com'
@@ -27,7 +26,7 @@ Gem::Specification.new do |spec|
27
26
  spec.rubyforge_project = 'sysutils'
28
27
  spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST', 'doc/top.txt']
29
28
 
30
- spec.add_development_dependency('test-unit', '>= 2.1.2')
29
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
31
30
 
32
31
  spec.description = <<-EOF
33
32
  The sys-proctable library provides an interface for gathering information
@@ -9,13 +9,12 @@ gem 'test-unit'
9
9
 
10
10
  require 'test/unit'
11
11
  require 'sys/proctable'
12
- require 'rbconfig'
13
12
  require 'test/test_sys_top'
14
13
  include Sys
15
14
 
16
15
  class TC_ProcTable_All < Test::Unit::TestCase
17
16
  def self.startup
18
- @@windows = Config::CONFIG['host_os'] =~ /windows|win32|msdos|mswin32|mingw|cygwin/i
17
+ @@windows = File::ALT_SEPARATOR
19
18
  end
20
19
 
21
20
  def setup
@@ -23,7 +22,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
23
22
  end
24
23
 
25
24
  def test_version
26
- assert_equal('0.9.1', ProcTable::VERSION)
25
+ assert_equal('0.9.2', ProcTable::VERSION)
27
26
  end
28
27
 
29
28
  def test_fields
metadata CHANGED
@@ -1,50 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ prerelease:
10
6
  platform: universal-darwin
11
- authors:
7
+ authors:
12
8
  - Daniel J. Berger
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-08-20 00:00:00 -06:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: test-unit
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 1
31
- - 2
32
- version: 2.1.2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
33
22
  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"
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.4.0
30
+ description: ! " The sys-proctable library provides an interface for gathering
31
+ information\n about processes on your system, i.e. the process table. Most major\n
32
+ \ platforms are supported and, while different platforms may return\n different
33
+ information, the external interface is identical across\n platforms.\n"
36
34
  email: djberg96@gmail.com
37
35
  executables: []
38
-
39
- extensions:
36
+ extensions:
40
37
  - ext/darwin/extconf.rb
41
- extra_rdoc_files:
38
+ extra_rdoc_files:
42
39
  - CHANGES
43
40
  - README
44
41
  - MANIFEST
45
42
  - doc/top.txt
46
43
  - ext/darwin/sys/proctable.c
47
- files:
44
+ files:
48
45
  - benchmarks/bench_ps.rb
49
46
  - examples/example_ps.rb
50
47
  - lib/sys/top.rb
@@ -58,38 +55,31 @@ files:
58
55
  - ext/darwin/sys/proctable.c
59
56
  - test/test_sys_proctable_darwin.rb
60
57
  - ext/darwin/extconf.rb
61
- has_rdoc: true
62
58
  homepage: http://www.rubyforge.org/projects/sysutils
63
- licenses:
59
+ licenses:
64
60
  - Artistic 2.0
65
61
  post_install_message:
66
62
  rdoc_options: []
67
-
68
- require_paths:
63
+ require_paths:
69
64
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
71
66
  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
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
72
  none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
86
77
  requirements: []
87
-
88
78
  rubyforge_project: sysutils
89
- rubygems_version: 1.3.7
79
+ rubygems_version: 1.8.24
90
80
  signing_key:
91
81
  specification_version: 3
92
82
  summary: An interface for providing process table information
93
- test_files:
83
+ test_files:
94
84
  - test/test_sys_proctable_all.rb
95
85
  - test/test_sys_proctable_darwin.rb