sys-proctable 1.2.6 → 1.3.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES.rdoc → CHANGES.md} +69 -49
- data/Gemfile +2 -0
- data/{MANIFEST.rdoc → MANIFEST.md} +9 -1
- data/README.md +9 -3
- data/Rakefile +10 -7
- data/certs/djberg96_pub.pem +26 -0
- data/lib/bsd/sys/dragonfly/sys/proctable/constants.rb +11 -0
- data/lib/bsd/sys/dragonfly/sys/proctable/functions.rb +14 -0
- data/lib/bsd/sys/dragonfly/sys/proctable/structs.rb +298 -0
- data/lib/bsd/sys/dragonfly/sys/proctable.rb +175 -0
- data/lib/bsd/sys/freebsd/sys/proctable/constants.rb +0 -0
- data/lib/bsd/sys/freebsd/sys/proctable/functions.rb +0 -0
- data/lib/bsd/sys/freebsd/sys/proctable/structs.rb +0 -0
- data/lib/{freebsd → bsd/sys/freebsd}/sys/proctable.rb +1 -1
- data/lib/bsd/sys/proctable.rb +8 -0
- data/lib/darwin/sys/proctable.rb +53 -20
- data/lib/linux/sys/proctable/cgroup_entry.rb +4 -2
- data/lib/linux/sys/proctable/smaps.rb +29 -17
- data/lib/linux/sys/proctable.rb +41 -35
- data/lib/sunos/sys/proctable.rb +2 -2
- data/lib/sys/proctable/version.rb +1 -1
- data/lib/sys/proctable.rb +2 -2
- data/lib/sys/top.rb +7 -2
- data/lib/windows/sys/proctable.rb +36 -32
- data/spec/spec_helper.rb +15 -0
- data/spec/sys_proctable_aix_spec.rb +74 -76
- data/spec/sys_proctable_all_spec.rb +45 -45
- data/spec/sys_proctable_bsd_spec.rb +244 -0
- data/spec/sys_proctable_darwin_spec.rb +85 -58
- data/spec/sys_proctable_linux_spec.rb +196 -195
- data/spec/sys_proctable_sunos_spec.rb +190 -192
- data/spec/sys_proctable_windows_spec.rb +153 -153
- data/spec/sys_top_spec.rb +20 -21
- data/sys-proctable.gemspec +16 -24
- data.tar.gz.sig +0 -0
- metadata +78 -18
- metadata.gz.sig +0 -0
- data/spec/sys_proctable_freebsd_spec.rb +0 -210
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sys
|
2
4
|
class ProcTable
|
3
5
|
# This represents a cgroup entry
|
@@ -20,7 +22,7 @@ module Sys
|
|
20
22
|
def initialize(string)
|
21
23
|
@string = string.chomp
|
22
24
|
@fields = @string.split(/:/)
|
23
|
-
rescue
|
25
|
+
rescue StandardError
|
24
26
|
@fields = []
|
25
27
|
end
|
26
28
|
|
@@ -32,7 +34,7 @@ module Sys
|
|
32
34
|
# Return sets of subsystems bound to the hierarchy
|
33
35
|
def subsystems
|
34
36
|
@fields[1].split(/,/)
|
35
|
-
rescue
|
37
|
+
rescue StandardError
|
36
38
|
[]
|
37
39
|
end
|
38
40
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sys
|
2
4
|
class ProcTable
|
3
5
|
# Smaps represents a process' memory size for all mapped files
|
@@ -25,7 +27,18 @@ module Sys
|
|
25
27
|
# Example:
|
26
28
|
#
|
27
29
|
# smaps = Smaps.new(123, IO.read("/proc/1234/smaps")
|
28
|
-
#
|
30
|
+
#
|
31
|
+
# # result
|
32
|
+
#
|
33
|
+
# #<Sys::ProcTable::Smaps:0x007f8ac5930768
|
34
|
+
# @pid=123,
|
35
|
+
# @pss=107000,
|
36
|
+
# @rss=368000,
|
37
|
+
# @uss=96000,
|
38
|
+
# @swap=192000,
|
39
|
+
# @vss=136752000
|
40
|
+
# >
|
41
|
+
#
|
29
42
|
# smaps.pss # => 109568
|
30
43
|
# smaps.rss # => 376832
|
31
44
|
# smaps.uss # => 98304
|
@@ -33,7 +46,6 @@ module Sys
|
|
33
46
|
# smaps.vss # => 140034048
|
34
47
|
#
|
35
48
|
class Smaps
|
36
|
-
|
37
49
|
# Process ID for this smaps
|
38
50
|
attr_reader :pid
|
39
51
|
|
@@ -51,19 +63,19 @@ module Sys
|
|
51
63
|
# 4k + (4k / 2) + (3k / 3) = 7k
|
52
64
|
#
|
53
65
|
attr_reader :pss
|
54
|
-
|
66
|
+
alias proportional_set_size pss
|
55
67
|
|
56
68
|
# Resident set size
|
57
69
|
#
|
58
70
|
# RSS is the total size of all pages, shared or not, mapped to a process.
|
59
71
|
attr_reader :rss
|
60
|
-
|
72
|
+
alias resident_set_size rss
|
61
73
|
|
62
74
|
# Unique set size
|
63
75
|
#
|
64
76
|
# USS is the total size of all private pages mapped to a process.
|
65
77
|
attr_reader :uss
|
66
|
-
|
78
|
+
alias unique_set_size uss
|
67
79
|
|
68
80
|
# Swap
|
69
81
|
#
|
@@ -76,7 +88,7 @@ module Sys
|
|
76
88
|
# lazily loaded, this value represents the total size of all mapped files
|
77
89
|
# if they were all loaded.
|
78
90
|
attr_reader :vss
|
79
|
-
|
91
|
+
alias virtual_set_size vss
|
80
92
|
|
81
93
|
# Create a new smaps object
|
82
94
|
#
|
@@ -95,22 +107,22 @@ module Sys
|
|
95
107
|
smaps_contents.each_line { |line| parse_smaps_line(line) }
|
96
108
|
end
|
97
109
|
|
98
|
-
|
110
|
+
alias to_s inspect
|
99
111
|
|
100
112
|
private
|
101
113
|
|
102
114
|
def parse_smaps_line(line)
|
103
115
|
case line
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
116
|
+
when /^Pss:\s+?(\d+)/
|
117
|
+
@pss += Regexp.last_match[1].to_i * 1000
|
118
|
+
when /^Rss:\s+?(\d+)/
|
119
|
+
@rss += Regexp.last_match[1].to_i * 1000
|
120
|
+
when /^Size:\s+?(\d+)/
|
121
|
+
@vss += Regexp.last_match[1].to_i * 1000
|
122
|
+
when /^Swap:\s+?(\d+)/
|
123
|
+
@swap += Regexp.last_match[1].to_i * 1000
|
124
|
+
when /^Private_(Clean|Dirty):\s+?(\d+)/
|
125
|
+
@uss += Regexp.last_match[2].to_i * 1000
|
114
126
|
end
|
115
127
|
end
|
116
128
|
end
|
data/lib/linux/sys/proctable.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'sys/proctable/version'
|
2
4
|
require_relative 'proctable/cgroup_entry'
|
3
5
|
require_relative 'proctable/smaps'
|
4
6
|
|
5
7
|
# The Sys module serves as a namespace only.
|
6
8
|
module Sys
|
7
|
-
|
8
9
|
# The ProcTable class encapsulates process table information.
|
9
10
|
class ProcTable
|
10
|
-
|
11
11
|
# Error typically raised if the ProcTable.ps method fails.
|
12
12
|
class Error < StandardError; end
|
13
13
|
|
14
14
|
# There is no constructor
|
15
15
|
private_class_method :new
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
@mem_total = IO.read("/proc/meminfo")[/MemTotal.*/].split[1].to_i * 1024 rescue nil
|
20
|
-
@boot_time = IO.read("/proc/stat")[/btime.*/].split.last.to_i rescue nil
|
17
|
+
@mem_total = File.read("/proc/meminfo")[/MemTotal.*/].split[1].to_i * 1024 rescue nil
|
18
|
+
@boot_time = File.read("/proc/stat")[/btime.*/].split.last.to_i rescue nil
|
21
19
|
|
22
20
|
@fields = [
|
23
21
|
'cmdline', # Complete command line
|
@@ -83,10 +81,10 @@ module Sys
|
|
83
81
|
'smaps' # Process memory size for all mapped files
|
84
82
|
]
|
85
83
|
|
86
|
-
public
|
87
|
-
|
88
84
|
ProcTableStruct = Struct.new('ProcTableStruct', *@fields)
|
89
85
|
|
86
|
+
private_constant :ProcTableStruct
|
87
|
+
|
90
88
|
# In block form, yields a ProcTableStruct for each process entry that you
|
91
89
|
# have rights to. This method returns an array of ProcTableStruct's in
|
92
90
|
# non-block form.
|
@@ -121,19 +119,19 @@ module Sys
|
|
121
119
|
array = block_given? ? nil : []
|
122
120
|
struct = nil
|
123
121
|
|
124
|
-
raise TypeError
|
122
|
+
raise TypeError if pid && !pid.is_a?(Numeric)
|
125
123
|
|
126
|
-
Dir.foreach("/proc")
|
124
|
+
Dir.foreach("/proc") do |file|
|
127
125
|
next if file =~ /\D/ # Skip non-numeric directories
|
128
|
-
next
|
126
|
+
next if pid && file.to_i != pid
|
129
127
|
|
130
128
|
struct = ProcTableStruct.new
|
131
129
|
|
132
130
|
# Get /proc/<pid>/cmdline information. Strip out embedded nulls.
|
133
131
|
begin
|
134
|
-
data =
|
132
|
+
data = File.read("/proc/#{file}/cmdline").tr("\000", ' ').strip
|
135
133
|
struct.cmdline = data
|
136
|
-
rescue
|
134
|
+
rescue StandardError
|
137
135
|
next # Process terminated, on to the next process
|
138
136
|
end
|
139
137
|
|
@@ -146,10 +144,10 @@ module Sys
|
|
146
144
|
struct.environ = {}
|
147
145
|
|
148
146
|
begin
|
149
|
-
|
147
|
+
File.read("/proc/#{file}/environ").force_encoding("UTF-8").split("\0").each do |str|
|
150
148
|
key, value = str.split('=')
|
151
149
|
struct.environ[key] = value
|
152
|
-
|
150
|
+
end
|
153
151
|
rescue Errno::EACCES, Errno::ESRCH, Errno::ENOENT
|
154
152
|
# Ignore and move on.
|
155
153
|
end
|
@@ -166,7 +164,7 @@ module Sys
|
|
166
164
|
Dir["/proc/#{file}/fd/*"].each do |fd|
|
167
165
|
struct.fd[File.basename(fd)] = File.readlink(fd) rescue nil
|
168
166
|
end
|
169
|
-
rescue
|
167
|
+
rescue StandardError
|
170
168
|
# Ignore and move on
|
171
169
|
end
|
172
170
|
|
@@ -174,7 +172,7 @@ module Sys
|
|
174
172
|
struct.root = File.readlink("/proc/#{file}/root") rescue nil
|
175
173
|
|
176
174
|
# Get /proc/<pid>/stat information
|
177
|
-
stat =
|
175
|
+
stat = File.read("/proc/#{file}/stat") rescue next
|
178
176
|
|
179
177
|
# Get number of LWP, one directory for each in /proc/<pid>/task/
|
180
178
|
# Every process has at least one thread, so if we fail to read the task directory, set nlwp to 1.
|
@@ -182,7 +180,7 @@ module Sys
|
|
182
180
|
|
183
181
|
# Get control groups to which the process belongs
|
184
182
|
unless cgroup == false
|
185
|
-
struct.cgroup =
|
183
|
+
struct.cgroup = File.readlines("/proc/#{file}/cgroup").map { |l| CgroupEntry.new(l) } rescue []
|
186
184
|
end
|
187
185
|
|
188
186
|
# Read smaps, returning a parsable string if we don't have permissions.
|
@@ -190,12 +188,18 @@ module Sys
|
|
190
188
|
# are true for a file in the /proc fileystem but raises a Errno:EACCESS
|
191
189
|
# when your try to read it without permissions.
|
192
190
|
unless smaps == false
|
193
|
-
smaps_contents =
|
191
|
+
smaps_contents = File.read("/proc/#{file}/smaps") rescue ""
|
194
192
|
struct.smaps = Smaps.new(file, smaps_contents)
|
195
193
|
end
|
196
194
|
|
197
|
-
# Deal with spaces in comm name.
|
198
|
-
|
195
|
+
# Deal with spaces in comm name. This isn't supposed to happen, but in
|
196
|
+
# rare cases - the original offending case was "(xzen thread)" - it can
|
197
|
+
# occur. So we parse it out, replace the spaces with hyphens, and
|
198
|
+
# re-insert it into the stat string so that it splits properly later on.
|
199
|
+
#
|
200
|
+
# Courtesy of Ara Howard.
|
201
|
+
#
|
202
|
+
re = /\([^)]+\)/
|
199
203
|
comm = stat[re]
|
200
204
|
comm.tr!(' ', '-')
|
201
205
|
stat[re] = comm
|
@@ -203,7 +207,7 @@ module Sys
|
|
203
207
|
stat = stat.split
|
204
208
|
|
205
209
|
struct.pid = stat[0].to_i
|
206
|
-
struct.comm = stat[1].tr('()','') # Remove parens
|
210
|
+
struct.comm = stat[1].tr('()', '') # Remove parens
|
207
211
|
struct.state = stat[2]
|
208
212
|
struct.ppid = stat[3].to_i
|
209
213
|
struct.pgrp = stat[4].to_i
|
@@ -250,16 +254,16 @@ module Sys
|
|
250
254
|
|
251
255
|
# Get /proc/<pid>/status information (name, uid, euid, gid, egid)
|
252
256
|
begin
|
253
|
-
|
257
|
+
File.foreach("/proc/#{file}/status") do |line|
|
254
258
|
case line
|
255
259
|
when /Name:\s*?(\w+)/
|
256
|
-
struct.name =
|
260
|
+
struct.name = Regexp.last_match(1)
|
257
261
|
when /Uid:\s*?(\d+)\s*?(\d+)/
|
258
|
-
struct.uid =
|
259
|
-
struct.euid =
|
262
|
+
struct.uid = Regexp.last_match(1).to_i
|
263
|
+
struct.euid = Regexp.last_match(2).to_i
|
260
264
|
when /Gid:\s*?(\d+)\s*?(\d+)/
|
261
|
-
struct.gid =
|
262
|
-
struct.egid =
|
265
|
+
struct.gid = Regexp.last_match(1).to_i
|
266
|
+
struct.egid = Regexp.last_match(2).to_i
|
263
267
|
end
|
264
268
|
end
|
265
269
|
rescue Errno::ESRCH, Errno::ENOENT
|
@@ -280,7 +284,7 @@ module Sys
|
|
280
284
|
else
|
281
285
|
array << struct
|
282
286
|
end
|
283
|
-
|
287
|
+
end
|
284
288
|
|
285
289
|
pid ? struct : array
|
286
290
|
end
|
@@ -295,21 +299,21 @@ module Sys
|
|
295
299
|
# puts "Field: #{field}"
|
296
300
|
# }
|
297
301
|
#
|
298
|
-
|
299
|
-
|
302
|
+
class << self
|
303
|
+
attr_reader :fields
|
300
304
|
end
|
301
305
|
|
302
|
-
private
|
303
|
-
|
304
306
|
# Calculate the percentage of memory usage for the given process.
|
305
307
|
#
|
306
308
|
def self.get_pctmem(rss)
|
307
309
|
return nil unless @mem_total
|
308
310
|
page_size = 4096
|
309
311
|
rss_total = rss * page_size
|
310
|
-
|
312
|
+
format("%3.2f", (rss_total.to_f / @mem_total) * 100).to_f
|
311
313
|
end
|
312
314
|
|
315
|
+
private_class_method :get_pctmem
|
316
|
+
|
313
317
|
# Calculate the percentage of CPU usage for the given process.
|
314
318
|
#
|
315
319
|
def self.get_pctcpu(utime, start_time)
|
@@ -317,7 +321,9 @@ module Sys
|
|
317
321
|
hertz = 100.0
|
318
322
|
utime = (utime * 10000).to_f
|
319
323
|
stime = (start_time.to_f / hertz) + @boot_time
|
320
|
-
|
324
|
+
format("%3.2f", (utime / 10000.0) / (Time.now.to_i - stime)).to_f
|
321
325
|
end
|
326
|
+
|
327
|
+
private_class_method :get_pctcpu
|
322
328
|
end
|
323
329
|
end
|
data/lib/sunos/sys/proctable.rb
CHANGED
@@ -110,7 +110,7 @@ module Sys
|
|
110
110
|
:pr_slptime, Timeval,
|
111
111
|
:pr_wtime, Timeval,
|
112
112
|
:pr_stoptime, Timeval,
|
113
|
-
:pr_filetime, [Timeval,6],
|
113
|
+
:pr_filetime, [Timeval, 6],
|
114
114
|
:pr_minf, :ulong_t,
|
115
115
|
:pr_majf, :ulong_t,
|
116
116
|
:pr_nswap, :ulong_t,
|
@@ -343,7 +343,7 @@ module Sys
|
|
343
343
|
env_address += data.length + 1 # Add 1 for the space
|
344
344
|
end
|
345
345
|
end
|
346
|
-
rescue Errno::EACCES, Errno::EOVERFLOW, EOFError, RangeError
|
346
|
+
rescue Errno::EACCES, Errno::EBADF, Errno::EOVERFLOW, EOFError, RangeError
|
347
347
|
# Skip this if we don't have proper permissions, if there's
|
348
348
|
# no associated environment, or if there's a largefile issue.
|
349
349
|
rescue Errno::ENOENT
|
data/lib/sys/proctable.rb
CHANGED
@@ -5,8 +5,8 @@ case RbConfig::CONFIG['host_os']
|
|
5
5
|
require_relative '../aix/sys/proctable'
|
6
6
|
when /darwin/i
|
7
7
|
require_relative '../darwin/sys/proctable'
|
8
|
-
when /freebsd/i
|
9
|
-
require_relative '../
|
8
|
+
when /freebsd|dragonfly/i
|
9
|
+
require_relative '../bsd/sys/proctable'
|
10
10
|
when /linux/i
|
11
11
|
require_relative '../linux/sys/proctable'
|
12
12
|
when /sunos|solaris/i
|
data/lib/sys/top.rb
CHANGED
@@ -15,18 +15,23 @@ module Sys
|
|
15
15
|
#
|
16
16
|
# Exception: the default sort field is 'pid' on AIX, Darwin and Windows.
|
17
17
|
#
|
18
|
-
def self.top(num=10, field='pctcpu')
|
18
|
+
def self.top(num = 10, field = 'pctcpu')
|
19
19
|
field = field.to_s if field.is_a?(Symbol)
|
20
20
|
|
21
21
|
aix = RbConfig::CONFIG['host_os'] =~ /aix/i
|
22
22
|
darwin = RbConfig::CONFIG['host_os'] =~ /darwin/i
|
23
|
+
dragonfly = RbConfig::CONFIG['host_os'] =~ /dragonfly/i
|
23
24
|
|
24
25
|
# Sort by pid on Windows and AIX by default
|
25
26
|
if (File::ALT_SEPARATOR || aix || darwin) && field == 'pctcpu'
|
26
27
|
field = 'pid'
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
if dragonfly && field == 'pctcpu'
|
31
|
+
Sys::ProcTable.ps.sort_by{ |obj| obj.lwp.pctcpu }[0..num-1]
|
32
|
+
else
|
33
|
+
Sys::ProcTable.ps.sort_by{ |obj| obj.send(field) || '' }[0..num-1]
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'win32ole'
|
2
4
|
require 'socket'
|
3
5
|
require 'date'
|
@@ -5,10 +7,8 @@ require 'sys/proctable/version'
|
|
5
7
|
|
6
8
|
# The Sys module serves as a namespace only
|
7
9
|
module Sys
|
8
|
-
|
9
10
|
# The ProcTable class encapsulates process table information
|
10
11
|
class ProcTable
|
11
|
-
|
12
12
|
# There is no constructor
|
13
13
|
private_class_method :new
|
14
14
|
|
@@ -77,8 +77,8 @@ module Sys
|
|
77
77
|
# may be useful if you want to know in advance what fields are available
|
78
78
|
# without having to perform at least one read of the /proc table.
|
79
79
|
#
|
80
|
-
|
81
|
-
|
80
|
+
class << self
|
81
|
+
attr_reader :fields
|
82
82
|
end
|
83
83
|
|
84
84
|
# call-seq:
|
@@ -96,19 +96,21 @@ module Sys
|
|
96
96
|
pid = kwargs[:pid]
|
97
97
|
host = kwargs[:host] || Socket.gethostname
|
98
98
|
|
99
|
-
|
99
|
+
if pid && !pid.is_a?(Numeric)
|
100
|
+
raise TypeError
|
101
|
+
end
|
100
102
|
|
101
103
|
array = block_given? ? nil : []
|
102
104
|
struct = nil
|
103
105
|
|
104
106
|
begin
|
105
107
|
wmi = WIN32OLE.connect("winmgmts://#{host}/root/cimv2")
|
106
|
-
rescue WIN32OLERuntimeError =>
|
107
|
-
raise Error,
|
108
|
+
rescue WIN32OLERuntimeError => err
|
109
|
+
raise Error, err # Re-raise as ProcTable::Error
|
108
110
|
else
|
109
|
-
wmi.InstancesOf("Win32_Process").each
|
110
|
-
if pid
|
111
|
-
next
|
111
|
+
wmi.InstancesOf("Win32_Process").each do |wproc|
|
112
|
+
if pid && wproc.ProcessId != pid
|
113
|
+
next
|
112
114
|
end
|
113
115
|
|
114
116
|
# Some fields are added later, and so are nil initially
|
@@ -117,7 +119,7 @@ module Sys
|
|
117
119
|
nil, # Added later, based on OS version
|
118
120
|
wproc.Name,
|
119
121
|
wproc.CreationClassName,
|
120
|
-
|
122
|
+
parse_ms_date(wproc.CreationDate),
|
121
123
|
wproc.CSCreationClassName,
|
122
124
|
wproc.CSName,
|
123
125
|
wproc.Description,
|
@@ -125,40 +127,40 @@ module Sys
|
|
125
127
|
wproc.ExecutionState,
|
126
128
|
wproc.Handle,
|
127
129
|
wproc.HandleCount,
|
128
|
-
|
129
|
-
|
130
|
+
parse_ms_date(wproc.InstallDate),
|
131
|
+
convert(wproc.KernelModeTime),
|
130
132
|
wproc.MaximumWorkingSetSize,
|
131
133
|
wproc.MinimumWorkingSetSize,
|
132
134
|
wproc.Name,
|
133
135
|
wproc.OSCreationClassName,
|
134
136
|
wproc.OSName,
|
135
|
-
|
136
|
-
|
137
|
+
convert(wproc.OtherOperationCount),
|
138
|
+
convert(wproc.OtherTransferCount),
|
137
139
|
wproc.PageFaults,
|
138
140
|
wproc.PageFileUsage,
|
139
141
|
wproc.ParentProcessId,
|
140
|
-
|
141
|
-
|
142
|
-
|
142
|
+
convert(wproc.PeakPageFileUsage),
|
143
|
+
convert(wproc.PeakVirtualSize),
|
144
|
+
convert(wproc.PeakWorkingSetSize),
|
143
145
|
wproc.Priority,
|
144
|
-
|
146
|
+
convert(wproc.PrivatePageCount),
|
145
147
|
wproc.ProcessId,
|
146
148
|
wproc.QuotaNonPagedPoolUsage,
|
147
149
|
wproc.QuotaPagedPoolUsage,
|
148
150
|
wproc.QuotaPeakNonPagedPoolUsage,
|
149
151
|
wproc.QuotaPeakPagedPoolUsage,
|
150
|
-
|
151
|
-
|
152
|
+
convert(wproc.ReadOperationCount),
|
153
|
+
convert(wproc.ReadTransferCount),
|
152
154
|
wproc.SessionId,
|
153
155
|
wproc.Status,
|
154
|
-
|
156
|
+
parse_ms_date(wproc.TerminationDate),
|
155
157
|
wproc.ThreadCount,
|
156
|
-
|
157
|
-
|
158
|
+
convert(wproc.UserModeTime),
|
159
|
+
convert(wproc.VirtualSize),
|
158
160
|
wproc.WindowsVersion,
|
159
|
-
|
160
|
-
|
161
|
-
|
161
|
+
convert(wproc.WorkingSetSize),
|
162
|
+
convert(wproc.WriteOperationCount),
|
163
|
+
convert(wproc.WriteTransferCount)
|
162
164
|
)
|
163
165
|
|
164
166
|
###############################################################
|
@@ -179,30 +181,32 @@ module Sys
|
|
179
181
|
else
|
180
182
|
array << struct
|
181
183
|
end
|
182
|
-
|
184
|
+
end
|
183
185
|
end
|
184
186
|
|
185
187
|
pid ? struct : array
|
186
188
|
end
|
187
189
|
|
188
|
-
private
|
189
|
-
|
190
190
|
#######################################################################
|
191
191
|
# Converts a string in the format '20040703074625.015625-360' into a
|
192
192
|
# Ruby Time object.
|
193
193
|
#######################################################################
|
194
194
|
def self.parse_ms_date(str)
|
195
195
|
return if str.nil?
|
196
|
-
|
196
|
+
DateTime.parse(str)
|
197
197
|
end
|
198
198
|
|
199
|
+
private_class_method :parse_ms_date
|
200
|
+
|
199
201
|
#####################################################################
|
200
202
|
# There is a bug in win32ole where uint64 types are returned as a
|
201
203
|
# String instead of a Fixnum. This method deals with that for now.
|
202
204
|
#####################################################################
|
203
205
|
def self.convert(str)
|
204
206
|
return nil if str.nil? # Return nil, not 0
|
205
|
-
|
207
|
+
str.to_i
|
206
208
|
end
|
209
|
+
|
210
|
+
private_class_method :convert
|
207
211
|
end
|
208
212
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'sys-proctable'
|
3
|
+
require 'sys-top'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.filter_run_excluding(:aix) unless RbConfig::CONFIG['host_os'] =~ /aix/i
|
7
|
+
config.filter_run_excluding(:darwin) unless RbConfig::CONFIG['host_os'] =~ /mac|darwin/i
|
8
|
+
config.filter_run_excluding(:linux) unless RbConfig::CONFIG['host_os'] =~ /linux/i
|
9
|
+
config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i
|
10
|
+
config.filter_run_excluding(:freebsd) unless RbConfig::CONFIG['host_os'] =~ /freebsd/i
|
11
|
+
config.filter_run_excluding(:dragonfly) unless RbConfig::CONFIG['host_os'] =~ /dragonfly/i
|
12
|
+
config.filter_run_excluding(:sunos) unless RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
|
13
|
+
config.filter_run_excluding(:windows) unless Gem.win_platform?
|
14
|
+
config.filter_run_excluding(:jruby) if RUBY_PLATFORM == 'java'
|
15
|
+
end
|