sys-proctable 1.2.1 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb96b1cfb746706244c26f2ce85f54740163cb9f9174237fd06767849ca62cb8
4
- data.tar.gz: f8b0b6d47efb86e64a630331a3408deb5baf2a6c8b1256bf55a0bad76f9c17c7
3
+ metadata.gz: 67e97600844b87fee76e66de7ca9ce8dc437c4b0e37d8760a1a1211629ca0ad4
4
+ data.tar.gz: 8f3940b17936f4fa4fdcbaae499728d54a0d20160f320021882435dc42fa8e1d
5
5
  SHA512:
6
- metadata.gz: 72bf0ffb98c4362deeb9506c6d2f50147c327fe0862575b06f5de1d342e6c9b3a7d5a0fd9a51d69e15cd2f1f68f8d8a9d67ceba12b8a8350f123498b759c4ac0
7
- data.tar.gz: 9acdc748cffeee40be36cff671b9f8057ec7fd9f416609f326882c28dfa5b9dd4fddba07a56ed9d64fe9d27b2743c242a3a9b04f902a2f9c3b442ab4ca38a2e1
6
+ metadata.gz: 7d9abfefc12b38b3e9961aaed71e4c0cf220418d6e719e945bcb72fe0d66a9782375ad860bb9f9dd37cedb5aefa410d689cdc97cfeb8ecc9f61e9c6eecf6fcf1
7
+ data.tar.gz: b1bb3b2a1fad203879b6a3c79066e730c074e9b6a5c090da0abdaebe86e4648dbccf07955c27e575ea52aa0c38acc08ae781754ee68dc50c8527f7c054433c56
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,40 @@
1
+ == 1.2.6 - 25-Aug-2020
2
+ * Made some updates so that it worked properly with TruffleRuby on Mac.
3
+ * Fixed an issue on Linux where non-ascii environ strings could cause failure.
4
+ Thanks go to deemytch for the spot and original patch.
5
+ * Removed the spec_helper.rb file, just use Process.spawn instead of messing
6
+ around with custom fork implementations. This also helps with implementations
7
+ that don't support fork.
8
+ * Updated the MANIFEST.
9
+
10
+ == 1.2.5 - 19-Jun-2020
11
+ * Added the delayacct_blkio_ticks, guest_time, and cguest_time fields on Linux.
12
+ These require 2.6.18 or later, but will simply be nil on earlier versions.
13
+ * Added the rsslim synonym for the rlim field for Linux.
14
+
15
+ == 1.2.4 - 18-Jun-2020
16
+ * Added the num_threads field for Linux. This was originally a dead field in
17
+ older versions of Linux that was skipped, but as of Linux 2.6+ it actually
18
+ holds meaningful data.
19
+ * Updated the specs for Linux.
20
+
21
+ == 1.2.3 - 17-Mar-2020
22
+ * Properly include a copy of Apache-2.0 in LICENSE file as part of library.
23
+ * Add explicit .rdoc extensions to CHANGES and MANIFEST files.
24
+
25
+ == 1.2.2 - 12-Aug-2019
26
+ * Added compatibility for JRuby on Mac which apparently doesn't define a
27
+ read_uint64 method, nor a CharArray. Thanks go to Adithya Pentela for
28
+ the spot.
29
+ * Refactored the specs a bit, adding a spec_helper.rb. This was mainly
30
+ for JRuby compatibility.
31
+ * Updates to the travis.yml file for both Ruby and JRuby versions.
32
+ * Removed the doc directory and all the files it contained. It was
33
+ redundant, and some of the information was wrong. All of the
34
+ documentation you need is on the wiki.
35
+ * Cleaned up the MANIFEST file, updated the gemspec, and fixed the
36
+ license name, which was missing a hyphen.
37
+
1
38
  == 1.2.1 - 8-Jun-2018
2
39
  * The code for OSX is now more efficient when a pid argument is provided.
3
40
  Thanks go to Nick LaMuro for his efforts.
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,28 @@
1
+ * CHANGES
2
+ * LICENSE
3
+ * MANIFEST
4
+ * Rakefile
5
+ * README
6
+ * sys-proctable.gemspec
7
+ * benchmarks/bench_ps.rb
8
+ * benchmarks/bench_ips_ps.rb
9
+ * example/example_ps.rb
10
+ * lib/sys-proctable.rb
11
+ * lib/sys-top.rb
12
+ * lib/sys/proctable.rb
13
+ * lib/sys/top.rb
14
+ * lib/sys/proctable/version.rb
15
+ * lib/aix/sys/proctable.rb
16
+ * lib/darwin/sys/proctable.rb
17
+ * lib/freebsd/sys/proctable.rb
18
+ * lib/linux/sys/proctable.rb
19
+ * lib/sunos/sys/proctable.rb
20
+ * lib/windows/sys/proctable.rb
21
+ * spec/sys_proctable_aix_spec.rb
22
+ * spec/sys_proctable_all_spec.rb
23
+ * spec/sys_proctable_darwin_spec.rb
24
+ * spec/sys_proctable_freebsd_spec.rb
25
+ * spec/sys_proctable_linux_spec.rb
26
+ * spec/sys_proctable_sunos_spec.rb
27
+ * spec/sys_proctable_windows_spec.rb
28
+ * spec/sys_top_spec.rb
data/README.md CHANGED
@@ -150,7 +150,7 @@ Apache 2.0
150
150
 
151
151
  ## Copyright
152
152
 
153
- (C) 2003-2018 Daniel J. Berger
153
+ (C) 2003-2019 Daniel J. Berger
154
154
  All Rights Reserved.
155
155
 
156
156
  ## Author
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'rbconfig'
6
+ require 'benchmark/ips'
7
+
8
+ @source, @gem = false
9
+
10
+ OptionParser.new do |opt|
11
+ opt.banner = "Usage: #{File.basename $0} [--gem|--source]"
12
+
13
+ opt.separator ""
14
+ opt.separator "Benchmark IPS (iterations per second) changes between"
15
+ opt.separator "source version of sys-proctable and previous gem"
16
+ opt.separator "version."
17
+ opt.separator ""
18
+ opt.separator "Requires that the both the source version of the gem"
19
+ opt.separator "be installed (run `rake install` to do this after"
20
+ opt.separator "each of your changes) and version installed via"
21
+ opt.separator "rubygems."
22
+ opt.separator ""
23
+ opt.separator "To run, call with `--gem` two times, and then with "
24
+ opt.separator "`--source` two times again."
25
+ opt.separator ""
26
+
27
+ opt.on("--source") { @source = true }
28
+ opt.on("--gem") { @gem = true }
29
+ end.parse!
30
+
31
+ if @source && !@gem
32
+ # Being paranoid here and making sure we get the version installed to
33
+ # sitelibdir
34
+ require File.join(RbConfig::CONFIG["sitelibdir"], "sys", "proctable")
35
+ else
36
+ @gem = true
37
+ require 'sys-proctable'
38
+ end
39
+
40
+ Benchmark.ips do |bench|
41
+ bench.report("Block form - pre patch") do
42
+ (puts "ERR: Please run with --gem"; exit 1) unless @gem
43
+ Sys::ProcTable.ps {}
44
+ end
45
+
46
+ bench.report("Non-block form - pre patch") do
47
+ (puts "ERR: Please run with --gem"; exit 1) unless @gem
48
+ Sys::ProcTable.ps
49
+ end
50
+
51
+ bench.report("Block form - post patch") do
52
+ (puts "ERR: Please run with --source"; exit 1) unless @source
53
+ Sys::ProcTable.ps {}
54
+ end
55
+
56
+ bench.report("Non-block form - post patch") do
57
+ (puts "ERR: Please run with --source"; exit 1) unless @source
58
+ Sys::ProcTable.ps
59
+ end
60
+
61
+ bench.hold! "bench_ips_ps.results"
62
+ bench.compare!
63
+ end
@@ -26,6 +26,15 @@ module Sys
26
26
  MAXTHREADNAMESIZE = 64
27
27
  PROC_PIDPATHINFO_MAXSIZE = MAXPATHLEN * 4
28
28
 
29
+ # JRuby/Truffleruby on Mac
30
+ unless defined? FFI::StructLayout::CharArray
31
+ if defined? FFI::StructLayout::CharArrayProxy
32
+ FFI::StructLayout::CharArray = FFI::StructLayout::CharArrayProxy
33
+ else
34
+ FFI::StructLayout::CharArray = FFI::Struct::CharArray
35
+ end
36
+ end
37
+
29
38
  class ProcBsdInfo < FFI::Struct
30
39
  layout(
31
40
  :pbi_flags, :uint32_t,
@@ -285,7 +294,13 @@ module Sys
285
294
 
286
295
  0.upto(max-1) do |index|
287
296
  tinfo = ProcThreadInfo.new
288
- nb = proc_pidinfo(pid, PROC_PIDTHREADINFO, buf[index].read_uint64, tinfo, tinfo.size)
297
+
298
+ # Use read_array_of_uint64 for compatibility with JRuby if necessary.
299
+ if buf[index].respond_to?(:read_uint64)
300
+ nb = proc_pidinfo(pid, PROC_PIDTHREADINFO, buf[index].read_uint64, tinfo, tinfo.size)
301
+ else
302
+ nb = proc_pidinfo(pid, PROC_PIDTHREADINFO, buf[index].read_array_of_uint64(1).first, tinfo, tinfo.size)
303
+ end
289
304
 
290
305
  if nb <= 0
291
306
  if [Errno::EPERM::Errno, Errno::ESRCH::Errno].include?(FFI.errno)
@@ -20,62 +20,67 @@ module Sys
20
20
  @boot_time = IO.read("/proc/stat")[/btime.*/].split.last.to_i rescue nil
21
21
 
22
22
  @fields = [
23
- 'cmdline', # Complete command line
24
- 'cwd', # Current working directory
25
- 'environ', # Environment
26
- 'exe', # Actual pathname of the executed command
27
- 'fd', # File descriptors open by process
28
- 'root', # Root directory of process
29
- 'pid', # Process ID
30
- 'comm', # Filename of executable
31
- 'state', # Single character state abbreviation
32
- 'ppid', # Parent process ID
33
- 'pgrp', # Process group
34
- 'session', # Session ID
35
- 'tty_nr', # TTY (terminal) associated with the process
36
- 'tpgid', # Group ID of the TTY
37
- 'flags', # Kernel flags
38
- 'minflt', # Number of minor faults
39
- 'cminflt', # Number of minor faults of waited-for children
40
- 'majflt', # Number of major faults
41
- 'cmajflt', # Number of major faults of waited-for children
42
- 'utime', # Number of user mode jiffies
43
- 'stime', # Number of kernel mode jiffies
44
- 'cutime', # Number of children's user mode jiffies
45
- 'cstime', # Number of children's kernel mode jiffies
46
- 'priority', # Nice value plus 15
47
- 'nice', # Nice value
48
- 'itrealvalue', # Time in jiffies before next SIGALRM
49
- 'starttime', # Time in jiffies since system boot
50
- 'vsize', # Virtual memory size in bytes
51
- 'rss', # Resident set size
52
- 'rlim', # Current limit on the rss in bytes
53
- 'startcode', # Address above which program text can run
54
- 'endcode', # Address below which program text can run
55
- 'startstack', # Address of the startstack
56
- 'kstkesp', # Kernel stack page address
57
- 'kstkeip', # Kernel instruction pointer
58
- 'signal', # Bitmap of pending signals
59
- 'blocked', # Bitmap of blocked signals
60
- 'sigignore', # Bitmap of ignored signals
61
- 'sigcatch', # Bitmap of caught signals
62
- 'wchan', # Channel in which the process is waiting
63
- 'nswap', # Number of pages swapped
64
- 'cnswap', # Cumulative nswap for child processes
65
- 'exit_signal', # Signal to be sent to parent when process dies
66
- 'processor', # CPU number last executed on
67
- 'rt_priority', # Real time scheduling priority
68
- 'policy', # Scheduling policy
69
- 'name', # Process name
70
- 'uid', # Real user ID
71
- 'euid', # Effective user ID
72
- 'gid', # Real group ID
73
- 'egid', # Effective group ID
74
- 'pctcpu', # Percent of CPU usage (custom field)
75
- 'pctmem', # Percent of Memory usage (custom field)
76
- 'nlwp', # Number of Light-Weight Processes associated with the process (threads)
77
- 'cgroup', # Control groups to which the process belongs
78
- 'smaps' # Process memory size for all mapped files
23
+ 'cmdline', # Complete command line
24
+ 'cwd', # Current working directory
25
+ 'environ', # Environment
26
+ 'exe', # Actual pathname of the executed command
27
+ 'fd', # File descriptors open by process
28
+ 'root', # Root directory of process
29
+ 'pid', # Process ID
30
+ 'comm', # Filename of executable
31
+ 'state', # Single character state abbreviation
32
+ 'ppid', # Parent process ID
33
+ 'pgrp', # Process group
34
+ 'session', # Session ID
35
+ 'tty_nr', # TTY (terminal) associated with the process
36
+ 'tpgid', # Group ID of the TTY
37
+ 'flags', # Kernel flags
38
+ 'minflt', # Number of minor faults
39
+ 'cminflt', # Number of minor faults of waited-for children
40
+ 'majflt', # Number of major faults
41
+ 'cmajflt', # Number of major faults of waited-for children
42
+ 'utime', # Number of user mode jiffies
43
+ 'stime', # Number of kernel mode jiffies
44
+ 'cutime', # Number of children's user mode jiffies
45
+ 'cstime', # Number of children's kernel mode jiffies
46
+ 'priority', # Nice value plus 15
47
+ 'nice', # Nice value
48
+ 'num_threads', # Number of threads in this process
49
+ 'itrealvalue', # Time in jiffies before next SIGALRM
50
+ 'starttime', # Time in jiffies since system boot
51
+ 'vsize', # Virtual memory size in bytes
52
+ 'rss', # Resident set size
53
+ 'rlim', # Current limit on the rss in bytes (old)
54
+ 'rsslim', # Current limit on the rss in bytes (current)
55
+ 'startcode', # Address above which program text can run
56
+ 'endcode', # Address below which program text can run
57
+ 'startstack', # Address of the startstack
58
+ 'kstkesp', # Kernel stack page address
59
+ 'kstkeip', # Kernel instruction pointer
60
+ 'signal', # Bitmap of pending signals
61
+ 'blocked', # Bitmap of blocked signals
62
+ 'sigignore', # Bitmap of ignored signals
63
+ 'sigcatch', # Bitmap of caught signals
64
+ 'wchan', # Channel in which the process is waiting
65
+ 'nswap', # Number of pages swapped
66
+ 'cnswap', # Cumulative nswap for child processes
67
+ 'exit_signal', # Signal to be sent to parent when process dies
68
+ 'processor', # CPU number last executed on
69
+ 'rt_priority', # Real time scheduling priority
70
+ 'policy', # Scheduling policy
71
+ 'delayacct_blkio_ticks', # Aggregated block I/O delays
72
+ 'guest_time', # Guest time of the process
73
+ 'cguest_time', # Guest time of the process's children
74
+ 'name', # Process name
75
+ 'uid', # Real user ID
76
+ 'euid', # Effective user ID
77
+ 'gid', # Real group ID
78
+ 'egid', # Effective group ID
79
+ 'pctcpu', # Percent of CPU usage (custom field)
80
+ 'pctmem', # Percent of Memory usage (custom field)
81
+ 'nlwp', # Number of Light-Weight Processes associated with the process (threads)
82
+ 'cgroup', # Control groups to which the process belongs
83
+ 'smaps' # Process memory size for all mapped files
79
84
  ]
80
85
 
81
86
  public
@@ -141,7 +146,7 @@ module Sys
141
146
  struct.environ = {}
142
147
 
143
148
  begin
144
- IO.read("/proc/#{file}/environ").split("\0").each{ |str|
149
+ IO.read("/proc/#{file}/environ").force_encoding("UTF-8").split("\0").each{ |str|
145
150
  key, value = str.split('=')
146
151
  struct.environ[key] = value
147
152
  }
@@ -197,47 +202,51 @@ module Sys
197
202
 
198
203
  stat = stat.split
199
204
 
200
- struct.pid = stat[0].to_i
201
- struct.comm = stat[1].tr('()','') # Remove parens
202
- struct.state = stat[2]
203
- struct.ppid = stat[3].to_i
204
- struct.pgrp = stat[4].to_i
205
- struct.session = stat[5].to_i
206
- struct.tty_nr = stat[6].to_i
207
- struct.tpgid = stat[7].to_i
208
- struct.flags = stat[8].to_i
209
- struct.minflt = stat[9].to_i
210
- struct.cminflt = stat[10].to_i
211
- struct.majflt = stat[11].to_i
212
- struct.cmajflt = stat[12].to_i
213
- struct.utime = stat[13].to_i
214
- struct.stime = stat[14].to_i
215
- struct.cutime = stat[15].to_i
216
- struct.cstime = stat[16].to_i
217
- struct.priority = stat[17].to_i
218
- struct.nice = stat[18].to_i
219
- # Skip 19
220
- struct.itrealvalue = stat[20].to_i
221
- struct.starttime = stat[21].to_i
222
- struct.vsize = stat[22].to_i
223
- struct.rss = stat[23].to_i
224
- struct.rlim = stat[24].to_i
225
- struct.startcode = stat[25].to_i
226
- struct.endcode = stat[26].to_i
227
- struct.startstack = stat[27].to_i
228
- struct.kstkesp = stat[28].to_i
229
- struct.kstkeip = stat[29].to_i
230
- struct.signal = stat[30].to_i
231
- struct.blocked = stat[31].to_i
232
- struct.sigignore = stat[32].to_i
233
- struct.sigcatch = stat[33].to_i
234
- struct.wchan = stat[34].to_i
235
- struct.nswap = stat[35].to_i
236
- struct.cnswap = stat[36].to_i
237
- struct.exit_signal = stat[37].to_i
238
- struct.processor = stat[38].to_i
239
- struct.rt_priority = stat[39].to_i
240
- struct.policy = stat[40].to_i
205
+ struct.pid = stat[0].to_i
206
+ struct.comm = stat[1].tr('()','') # Remove parens
207
+ struct.state = stat[2]
208
+ struct.ppid = stat[3].to_i
209
+ struct.pgrp = stat[4].to_i
210
+ struct.session = stat[5].to_i
211
+ struct.tty_nr = stat[6].to_i
212
+ struct.tpgid = stat[7].to_i
213
+ struct.flags = stat[8].to_i
214
+ struct.minflt = stat[9].to_i
215
+ struct.cminflt = stat[10].to_i
216
+ struct.majflt = stat[11].to_i
217
+ struct.cmajflt = stat[12].to_i
218
+ struct.utime = stat[13].to_i
219
+ struct.stime = stat[14].to_i
220
+ struct.cutime = stat[15].to_i
221
+ struct.cstime = stat[16].to_i
222
+ struct.priority = stat[17].to_i
223
+ struct.nice = stat[18].to_i
224
+ struct.num_threads = stat[19].to_i
225
+ struct.itrealvalue = stat[20].to_i
226
+ struct.starttime = stat[21].to_i
227
+ struct.vsize = stat[22].to_i
228
+ struct.rss = stat[23].to_i
229
+ struct.rlim = stat[24].to_i # Old name for backwards compatibility
230
+ struct.rsslim = stat[24].to_i
231
+ struct.startcode = stat[25].to_i
232
+ struct.endcode = stat[26].to_i
233
+ struct.startstack = stat[27].to_i
234
+ struct.kstkesp = stat[28].to_i
235
+ struct.kstkeip = stat[29].to_i
236
+ struct.signal = stat[30].to_i
237
+ struct.blocked = stat[31].to_i
238
+ struct.sigignore = stat[32].to_i
239
+ struct.sigcatch = stat[33].to_i
240
+ struct.wchan = stat[34].to_i
241
+ struct.nswap = stat[35].to_i
242
+ struct.cnswap = stat[36].to_i
243
+ struct.exit_signal = stat[37].to_i
244
+ struct.processor = stat[38].to_i
245
+ struct.rt_priority = stat[39].to_i
246
+ struct.policy = stat[40].to_i
247
+ struct.delayacct_blkio_ticks = stat[41].to_i
248
+ struct.guest_time = stat[42].to_i
249
+ struct.cguest_time = stat[43].to_i
241
250
 
242
251
  # Get /proc/<pid>/status information (name, uid, euid, gid, egid)
243
252
  begin
@@ -1,6 +1,6 @@
1
1
  module Sys
2
2
  class ProcTable
3
3
  # The version of the sys-proctable library
4
- VERSION = '1.2.1'.freeze
4
+ VERSION = '1.2.6'.freeze
5
5
  end
6
6
  end
@@ -16,7 +16,8 @@ describe Sys::ProcTable do
16
16
  end
17
17
 
18
18
  it "has a VERSION constant set to the expected value" do
19
- expect(Sys::ProcTable::VERSION).to eql('1.2.1')
19
+ expect(Sys::ProcTable::VERSION).to eql('1.2.6')
20
+ expect(Sys::ProcTable::VERSION).to be_frozen
20
21
  end
21
22
 
22
23
  it "defines a custom error class" do
@@ -21,8 +21,8 @@ describe Sys::ProcTable do
21
21
  }
22
22
 
23
23
  before(:all) do
24
- @pid1 = fork { exec('env', '-i', 'A=B', 'Z=', 'sleep', '60') }
25
- @pid2 = fork { exec('ruby', '-Ilib', '-e', 'sleep \'120\'.to_i', '--', 'foo bar') }
24
+ @pid1 = Process.spawn({'A' => 'B', 'Z' => nil}, "sleep 60")
25
+ @pid2 = Process.spawn("ruby", "-Ilib", "-e", "sleep \'120\'.to_i", "--", "foo bar")
26
26
  sleep 1 # wait to make sure env is replaced by sleep
27
27
  end
28
28
 
@@ -38,7 +38,7 @@ describe Sys::ProcTable do
38
38
 
39
39
  it "returns the expected results for the fields method" do
40
40
  expect(described_class.fields).to be_kind_of(Array)
41
- expect(described_class.fields).to eql(fields)
41
+ expect(described_class.fields).to eq(fields)
42
42
  end
43
43
  end
44
44
 
@@ -48,72 +48,72 @@ describe Sys::ProcTable do
48
48
  it "contains a pid member and returns the expected value" do
49
49
  expect(subject).to respond_to(:pid)
50
50
  expect(subject.pid).to be_kind_of(Numeric)
51
- expect(subject.pid).to eql(@pid1)
51
+ expect(subject.pid).to eq(@pid1)
52
52
  end
53
53
 
54
54
  it "contains a ppid member and returns the expected value" do
55
55
  expect(subject).to respond_to(:ppid)
56
56
  expect(subject.ppid).to be_kind_of(Numeric)
57
- expect(subject.ppid).to eql(Process.pid)
57
+ expect(subject.ppid).to eq(Process.pid)
58
58
  end
59
59
 
60
60
  it "contains a pgid member and returns the expected value" do
61
61
  expect(subject).to respond_to(:pgid)
62
62
  expect(subject.pgid).to be_kind_of(Numeric)
63
- expect(subject.pgid).to eql(Process.getpgrp)
63
+ expect(subject.pgid).to eq(Process.getpgrp)
64
64
  end
65
65
 
66
66
  it "contains a ruid member and returns the expected value" do
67
67
  expect(subject).to respond_to(:ruid)
68
68
  expect(subject.ruid).to be_kind_of(Numeric)
69
- expect(subject.ruid).to eql(Process.uid)
69
+ expect(subject.ruid).to eq(Process.uid)
70
70
  end
71
71
 
72
72
  it "contains an rgid member and returns the expected value" do
73
73
  expect(subject).to respond_to(:rgid)
74
74
  expect(subject.rgid).to be_kind_of(Numeric)
75
- expect(subject.rgid).to eql(Process.gid)
75
+ expect(subject.rgid).to eq(Process.gid)
76
76
  end
77
77
 
78
78
  it "contains an svuid member and returns the expected value" do
79
79
  expect(subject).to respond_to(:svuid)
80
80
  expect(subject.svuid).to be_kind_of(Numeric)
81
- expect(subject.svuid).to eql(Process.uid)
81
+ expect(subject.svuid).to eq(Process.uid)
82
82
  end
83
83
 
84
84
  it "contains an svgid member and returns the expected value" do
85
85
  expect(subject).to respond_to(:svgid)
86
86
  expect(subject.svgid).to be_kind_of(Numeric)
87
- expect(subject.svgid).to eql(Process.gid)
87
+ expect(subject.svgid).to eq(Process.gid)
88
88
  end
89
89
 
90
90
  it "contains a comm member and returns the expected value" do
91
91
  expect(subject).to respond_to(:comm)
92
92
  expect(subject.comm).to be_kind_of(String)
93
- expect(subject.comm).to eql('sleep')
93
+ expect(subject.comm).to eq('sleep')
94
94
  end
95
95
 
96
96
  it "contains a cmdline member and returns the expected value" do
97
97
  expect(subject).to respond_to(:cmdline)
98
98
  expect(subject.cmdline).to be_kind_of(String)
99
- expect(subject.cmdline).to eql('sleep 60')
99
+ expect(subject.cmdline).to eq('sleep 60')
100
100
  end
101
101
 
102
102
  it "returns a string with the expected arguments for the cmdline member" do
103
103
  ptable = Sys::ProcTable.ps(pid: @pid2)
104
- expect(ptable.cmdline).to eql('ruby -Ilib -e sleep \'120\'.to_i -- foo bar')
104
+ expect(ptable.cmdline).to eq('ruby -Ilib -e sleep \'120\'.to_i -- foo bar')
105
105
  end
106
106
 
107
107
  it "contains an exe member and returns the expected value" do
108
108
  expect(subject).to respond_to(:exe)
109
109
  expect(subject.exe).to be_kind_of(String)
110
- expect(subject.exe).to eql(`which sleep`.chomp)
110
+ expect(subject.exe).to eq(`which sleep`.chomp)
111
111
  end
112
112
 
113
113
  it "contains an environ member and returns the expected value" do
114
114
  expect(subject).to respond_to(:environ)
115
115
  expect(subject.environ).to be_kind_of(Hash)
116
- expect(subject.environ['A']).to eql('B')
116
+ expect(subject.environ['A']).to eq('B')
117
117
  expect(subject.environ['Z']).to be_nil
118
118
  end
119
119
  end
@@ -10,12 +10,12 @@ require_relative 'sys_proctable_all_spec'
10
10
 
11
11
  describe Sys::ProcTable do
12
12
  let(:fields){ %w[
13
- cmdline cwd exe pid name uid euid gid egid comm state ppid pgrp
14
- session tty_num tpgid flags minflt cminflt majflt cmajflt utime
15
- stime cutime cstime priority nice itrealvalue starttime vsize
16
- rss rlim startcode endcode startstack kstkesp kstkeip signal blocked
17
- sigignore sigcatch wchan nswap cnswap exit_signal processor environ
18
- pctcpu pctmem nlwp cgroup smaps
13
+ cmdline cwd environ exe fd root pid name uid euid gid egid comm state ppid pgrp
14
+ session tty_nr tpgid flags minflt cminflt majflt cmajflt utime
15
+ stime cutime cstime priority nice num_threads itrealvalue starttime vsize
16
+ rss rlim rsslim startcode endcode startstack kstkesp kstkeip signal blocked
17
+ sigignore sigcatch wchan nswap cnswap exit_signal processor rt_priority
18
+ policy delayacct_blkio_ticks guest_time cguest_time pctcpu pctmem nlwp cgroup smaps
19
19
  ]
20
20
  }
21
21
 
@@ -147,6 +147,11 @@ describe Sys::ProcTable do
147
147
  expect(subject.nice).to be_kind_of(Numeric)
148
148
  end
149
149
 
150
+ it "contains a num_threads member and returns the expected value" do
151
+ expect(subject).to respond_to(:num_threads)
152
+ expect(subject.num_threads).to be_kind_of(Numeric)
153
+ end
154
+
150
155
  it "contains a itrealvalue member and returns the expected value" do
151
156
  expect(subject).to respond_to(:itrealvalue)
152
157
  expect(subject.itrealvalue).to be_kind_of(Numeric)
@@ -167,9 +172,10 @@ describe Sys::ProcTable do
167
172
  expect(subject.rss).to be_kind_of(Numeric)
168
173
  end
169
174
 
170
- it "contains an rlim member and returns the expected value" do
171
- expect(subject).to respond_to(:rlim)
172
- expect(subject.rlim).to be_kind_of(Numeric)
175
+ it "contains an rsslim member and returns the expected value" do
176
+ expect(subject).to respond_to(:rsslim)
177
+ expect(subject.rsslim).to be_kind_of(Numeric)
178
+ expect(subject.rsslim).to eq(subject.rlim)
173
179
  end
174
180
 
175
181
  it "contains an startcode member and returns the expected value" do
@@ -252,6 +258,21 @@ describe Sys::ProcTable do
252
258
  expect(subject.policy).to be_kind_of(Integer)
253
259
  end
254
260
 
261
+ it "contains a delayacct_blkio_ticks member and returns the expected value" do
262
+ expect(subject).to respond_to(:delayacct_blkio_ticks)
263
+ expect(subject.delayacct_blkio_ticks).to be_kind_of(Integer)
264
+ end
265
+
266
+ it "contains a guest_time member and returns the expected value" do
267
+ expect(subject).to respond_to(:guest_time)
268
+ expect(subject.guest_time).to be_kind_of(Integer)
269
+ end
270
+
271
+ it "contains a cguest_time member and returns the expected value" do
272
+ expect(subject).to respond_to(:cguest_time)
273
+ expect(subject.cguest_time).to be_kind_of(Integer)
274
+ end
275
+
255
276
  it "contains a name member and returns the expected value" do
256
277
  expect(subject).to respond_to(:name)
257
278
  expect(subject.name).to be_kind_of(String)
@@ -307,4 +328,12 @@ describe Sys::ProcTable do
307
328
  expect(subject.smaps).to be_kind_of(Sys::ProcTable::Smaps)
308
329
  end
309
330
  end
331
+
332
+ context "fields" do
333
+ it "has a fields method that returns the expected results" do
334
+ expect(described_class).to respond_to(:fields)
335
+ expect(described_class.fields).to be_kind_of(Array)
336
+ expect(described_class.fields).to match_array(fields)
337
+ end
338
+ end
310
339
  end
@@ -2,9 +2,9 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-proctable'
5
- spec.version = '1.2.1'
5
+ spec.version = '1.2.6'
6
6
  spec.author = 'Daniel J. Berger'
7
- spec.license = 'Apache 2.0'
7
+ spec.license = 'Apache-2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'http://github.com/djberg96/sys-proctable'
10
10
  spec.summary = 'An interface for providing process table information'
@@ -15,14 +15,15 @@ Gem::Specification.new do |spec|
15
15
  "benchmarks/**/*.rb",
16
16
  "examples/**/*.rb",
17
17
  "lib/**/*.rb",
18
- 'CHANGES',
19
- 'MANIFEST',
18
+ 'CHANGES.rdoc',
19
+ 'LICENSE',
20
+ 'MANIFEST.rdoc',
20
21
  'Rakefile',
21
22
  'README.md',
22
23
  'sys-proctable.gemspec'
23
24
  ]
24
25
 
25
- spec.extra_rdoc_files = ['CHANGES', 'README.md', 'MANIFEST', 'doc/top.txt']
26
+ spec.extra_rdoc_files = ['CHANGES.rdoc', 'README.md', 'MANIFEST.rdoc']
26
27
 
27
28
  spec.add_dependency('ffi')
28
29
  spec.add_development_dependency('rspec')
@@ -31,7 +32,7 @@ Gem::Specification.new do |spec|
31
32
  spec.metadata = {
32
33
  'homepage_uri' => 'https://github.com/djberg96/sys-proctable',
33
34
  'bug_tracker_uri' => 'https://github.com/djberg96/sys-proctable/issues',
34
- 'changelog_uri' => 'https://github.com/djberg96/sys-proctable/blob/master/CHANGES',
35
+ 'changelog_uri' => 'https://github.com/djberg96/sys-proctable/blob/master/CHANGES.rdoc',
35
36
  'documentation_uri' => 'https://github.com/djberg96/sys-proctable/wiki',
36
37
  'source_code_uri' => 'https://github.com/djberg96/sys-proctable',
37
38
  'wiki_uri' => 'https://github.com/djberg96/sys-proctable/wiki'
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-proctable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date: 2018-06-08 00:00:00.000000000 Z
38
+ date:
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: ffi
@@ -89,11 +89,11 @@ email: djberg96@gmail.com
89
89
  executables: []
90
90
  extensions: []
91
91
  extra_rdoc_files:
92
- - CHANGES
92
+ - CHANGES.rdoc
93
93
  - README.md
94
- - MANIFEST
95
- - doc/top.txt
94
+ - MANIFEST.rdoc
96
95
  files:
96
+ - benchmarks/bench_ips_ps.rb
97
97
  - benchmarks/bench_ps.rb
98
98
  - examples/example_ps.rb
99
99
  - lib/aix/sys/proctable.rb
@@ -109,22 +109,23 @@ files:
109
109
  - lib/sys/proctable/version.rb
110
110
  - lib/sys/top.rb
111
111
  - lib/windows/sys/proctable.rb
112
- - CHANGES
113
- - MANIFEST
112
+ - CHANGES.rdoc
113
+ - LICENSE
114
+ - MANIFEST.rdoc
114
115
  - Rakefile
115
116
  - README.md
116
117
  - sys-proctable.gemspec
117
118
  homepage: http://github.com/djberg96/sys-proctable
118
119
  licenses:
119
- - Apache 2.0
120
+ - Apache-2.0
120
121
  metadata:
121
122
  homepage_uri: https://github.com/djberg96/sys-proctable
122
123
  bug_tracker_uri: https://github.com/djberg96/sys-proctable/issues
123
- changelog_uri: https://github.com/djberg96/sys-proctable/blob/master/CHANGES
124
+ changelog_uri: https://github.com/djberg96/sys-proctable/blob/master/CHANGES.rdoc
124
125
  documentation_uri: https://github.com/djberg96/sys-proctable/wiki
125
126
  source_code_uri: https://github.com/djberg96/sys-proctable
126
127
  wiki_uri: https://github.com/djberg96/sys-proctable/wiki
127
- post_install_message:
128
+ post_install_message:
128
129
  rdoc_options: []
129
130
  require_paths:
130
131
  - lib
@@ -139,9 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.6
144
- signing_key:
143
+ rubygems_version: 3.1.4
144
+ signing_key:
145
145
  specification_version: 4
146
146
  summary: An interface for providing process table information
147
147
  test_files:
metadata.gz.sig CHANGED
Binary file
data/MANIFEST DELETED
@@ -1,33 +0,0 @@
1
- * CHANGES
2
- * MANIFEST
3
- * Rakefile
4
- * README
5
- * sys-proctable.gemspec
6
- * doc/aix.txt
7
- * doc/bsd.txt
8
- * doc/hpux.txt
9
- * doc/linux.txt
10
- * doc/solaris.txt
11
- * doc/top.txt
12
- * doc/windows.txt
13
- * example/example_ps.rb
14
- * ext/hpux/extconf.rb
15
- * ext/hpux/sys/proctable.c
16
- * lib/sys-proctable.rb
17
- * lib/sys/top.rb
18
- * lib/sys/proctable/version.rb
19
- * lib/aix/sys/proctable.rb
20
- * lib/darwin/sys/proctable.rb
21
- * lib/freebsd/sys/proctable.rb
22
- * lib/linux/sys/proctable.rb
23
- * lib/sunos/sys/proctable.rb
24
- * lib/windows/sys/proctable.rb
25
- * test/test_sys_proctable_aix.rb
26
- * test/test_sys_proctable_all.rb
27
- * test/test_sys_proctable_darwin.rb
28
- * test/test_sys_proctable_freebsd.rb
29
- * test/test_sys_proctable_hpux.rb
30
- * test/test_sys_proctable_linux.rb
31
- * test/test_sys_proctable_sunos.rb
32
- * test/test_sys_proctable_windows.rb
33
- * test/test_sys_top.rb
@@ -1,47 +0,0 @@
1
- = Description
2
- A simple 'top' interface for Ruby
3
-
4
- = Prerequisites
5
- Requires the "sys/proctable" package (which should be installed along
6
- with this package).
7
-
8
- = Synopsis
9
- require "sys/top"
10
-
11
- Sys::Top.top(5).each{ |ps|
12
- p ps
13
- }
14
-
15
- = Constants
16
- VERSION
17
- Returns the version number of this package as a String.
18
-
19
- = Class Methods
20
- Sys::Top.top(number=10, field="pctcpu")
21
- Returns an array of ProcTableStruct's. The size of the array (i.e. the
22
- number of processes) that it returns is based on +number+, and sorted by
23
- +pctcpu+. By default, the size and field values are 10 and "pctcpu",
24
- respectively.
25
-
26
- = Notes
27
- Not all fields are available on all platforms. Please check your
28
- platform specific documentation for which fields are available.
29
-
30
- = Bugs
31
- None that I'm aware of. Please log bug reports on the project page at
32
- http://www.rubyforge.org/projects/sysutils
33
-
34
- = License
35
- Artistic 2.0
36
-
37
- = Copyright
38
- (C) 2004-2009 Daniel J. Berger
39
- All Rights Reserved.
40
-
41
- = Warranty
42
- This package is provided "as is" and without any express or
43
- implied warranties, including, without limitation, the implied
44
- warranties of merchantability and fitness for a particular purpose.
45
-
46
- = Author
47
- Daniel J. Berger