sys-proctable 1.1.0-universal-darwin → 1.1.1-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGES +4 -0
- data/lib/darwin/sys/proctable.rb +79 -8
- data/lib/sys/proctable/version.rb +1 -1
- data/sys-proctable.gemspec +1 -1
- data/test/test_sys_proctable_all.rb +1 -1
- data/test/test_sys_proctable_darwin.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 536255fca496dc375430fe9698a5f277fdd8db10
|
4
|
+
data.tar.gz: f108e5642d8312dae6fc598023c2a2703320278a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 113ed8abaa560fd6abaa75b545eb9d068c8a510c388ea0eda1c97ba80a2571df9ae11653888920e42f93e775920df151bc65ea9f835a94ef0bb3dcc7bad2f925
|
7
|
+
data.tar.gz: 7d0eb460512b0c1f9cb8173de138069cea86382f0b4173845479c79855e8cbfc8239dbb907b1b8dad00b1511438dfda4f3a40613e782183ec5ee17a47140085b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGES
CHANGED
data/lib/darwin/sys/proctable.rb
CHANGED
@@ -13,16 +13,16 @@ module Sys
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
PROC_ALL_PIDS = 1
|
17
16
|
PROC_PIDTASKALLINFO = 2
|
18
|
-
|
17
|
+
PROC_PIDTHREADINFO = 5
|
18
|
+
PROC_PIDLISTTHREADS = 6
|
19
19
|
|
20
20
|
CTL_KERN = 1
|
21
21
|
KERN_PROCARGS = 38
|
22
|
-
KERN_PROCARGS2 = 49
|
23
22
|
MAXCOMLEN = 16
|
24
23
|
MAXPATHLEN = 256
|
25
24
|
|
25
|
+
MAXTHREADNAMESIZE = 64
|
26
26
|
PROC_PIDPATHINFO_MAXSIZE = MAXPATHLEN * 4
|
27
27
|
|
28
28
|
class ProcBsdInfo < FFI::Struct
|
@@ -75,6 +75,22 @@ module Sys
|
|
75
75
|
)
|
76
76
|
end
|
77
77
|
|
78
|
+
class ProcThreadInfo < FFI::Struct
|
79
|
+
layout(
|
80
|
+
:pth_user_time, :uint64_t,
|
81
|
+
:pth_system_time, :uint64_t,
|
82
|
+
:pth_cpu_usage, :int32_t,
|
83
|
+
:pth_policy, :int32_t,
|
84
|
+
:pth_run_state, :int32_t,
|
85
|
+
:pth_flags, :int32_t,
|
86
|
+
:pth_sleep_time, :int32_t,
|
87
|
+
:pth_curpri, :int32_t,
|
88
|
+
:pth_priority, :int32_t,
|
89
|
+
:pth_maxpriority, :int32_t,
|
90
|
+
:pth_name, [:char, MAXTHREADNAMESIZE]
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
78
94
|
class ProcTaskAllInfo < FFI::Struct
|
79
95
|
layout(:pbsd, ProcBsdInfo, :ptinfo, ProcTaskInfo)
|
80
96
|
end
|
@@ -95,7 +111,7 @@ module Sys
|
|
95
111
|
virtual_size resident_size total_user total_system threads_user
|
96
112
|
threads_system policy faults pageins cow_faults messages_sent
|
97
113
|
messages_received syscalls_mach syscalls_unix csw threadnum numrunning
|
98
|
-
priority cmdline exe environ
|
114
|
+
priority cmdline exe environ threadinfo
|
99
115
|
]
|
100
116
|
|
101
117
|
# Add a couple aliases to make it similar to Linux
|
@@ -104,6 +120,11 @@ module Sys
|
|
104
120
|
alias rss resident_size
|
105
121
|
end
|
106
122
|
|
123
|
+
ThreadInfoStruct = Struct.new("ThreadInfo", :user_time, :system_time,
|
124
|
+
:cpu_usage, :policy, :run_state, :flags, :sleep_time, :curpri,
|
125
|
+
:priority, :maxpriority, :name
|
126
|
+
)
|
127
|
+
|
107
128
|
public
|
108
129
|
|
109
130
|
# Returns an array of fields that each ProcTableStruct will contain. This
|
@@ -162,7 +183,10 @@ module Sys
|
|
162
183
|
end
|
163
184
|
|
164
185
|
struct = ProcTableStruct.new
|
165
|
-
|
186
|
+
|
187
|
+
# Pass by reference
|
188
|
+
get_cmd_args_and_env(lpid, struct)
|
189
|
+
get_thread_info(lpid, struct, info[:ptinfo])
|
166
190
|
|
167
191
|
# Chop the leading xx_ from the FFI struct members for our ruby struct.
|
168
192
|
info.members.each do |nested|
|
@@ -192,6 +216,53 @@ module Sys
|
|
192
216
|
|
193
217
|
private
|
194
218
|
|
219
|
+
# Returns an array of ThreadInfo objects for the given pid.
|
220
|
+
#
|
221
|
+
def self.get_thread_info(pid, struct, ptinfo)
|
222
|
+
buf = FFI::MemoryPointer.new(:uint64_t, ptinfo[:pti_threadnum])
|
223
|
+
num = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, buf, buf.size)
|
224
|
+
|
225
|
+
if num <= 0
|
226
|
+
if [Errno::EPERM::Errno, Errno::ESRCH::Errno].include?(FFI.errno)
|
227
|
+
return # Either we don't have permission, or the pid no longer exists
|
228
|
+
else
|
229
|
+
raise SystemCallError.new('proc_pidinfo', FFI.errno)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
max = ptinfo[:pti_threadnum]
|
234
|
+
struct[:threadinfo] = []
|
235
|
+
|
236
|
+
0.upto(max-1) do |index|
|
237
|
+
tinfo = ProcThreadInfo.new
|
238
|
+
nb = proc_pidinfo(pid, PROC_PIDTHREADINFO, buf[index].read_uint64, tinfo, tinfo.size)
|
239
|
+
|
240
|
+
if nb <= 0
|
241
|
+
if [Errno::EPERM::Errno, Errno::ESRCH::Errno].include?(FFI.errno)
|
242
|
+
return # Either we don't have permission, or the pid no longer exists
|
243
|
+
else
|
244
|
+
raise SystemCallError.new('proc_pidinfo', FFI.errno)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
tinfo_struct = ThreadInfoStruct.new(
|
249
|
+
tinfo[:pth_user_time],
|
250
|
+
tinfo[:pth_system_time],
|
251
|
+
tinfo[:pth_cpu_usage],
|
252
|
+
tinfo[:pth_policy],
|
253
|
+
tinfo[:pth_run_state],
|
254
|
+
tinfo[:pth_flags],
|
255
|
+
tinfo[:pth_sleep_time],
|
256
|
+
tinfo[:pth_curpri],
|
257
|
+
tinfo[:pth_priority],
|
258
|
+
tinfo[:pth_maxpriority],
|
259
|
+
tinfo[:pth_name].to_s,
|
260
|
+
)
|
261
|
+
|
262
|
+
struct[:threadinfo] << tinfo_struct
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
195
266
|
# Get the command line arguments, as well as the environment settings,
|
196
267
|
# for the given PID.
|
197
268
|
#
|
@@ -211,7 +282,7 @@ module Sys
|
|
211
282
|
exe = buf.read_string # Read up to first null, does not include args
|
212
283
|
struct[:exe] = exe
|
213
284
|
|
214
|
-
# Parse the rest of the information out of big, ugly
|
285
|
+
# Parse the rest of the information out of a big, ugly string
|
215
286
|
array = buf.read_bytes(len.read_ulong).split(0.chr)
|
216
287
|
array.shift # Delete first exe
|
217
288
|
array.delete('') # Delete empty strings
|
@@ -225,8 +296,8 @@ module Sys
|
|
225
296
|
|
226
297
|
struct[:cmdline] = File.basename(cmdline.strip)
|
227
298
|
|
228
|
-
# Anything remaining at this point is a
|
229
|
-
# we convert into a hash.
|
299
|
+
# Anything remaining at this point is a collection of key=value
|
300
|
+
# pairs which we convert into a hash.
|
230
301
|
environ = array.inject({}) do |hash, string|
|
231
302
|
if string && string.include?('=')
|
232
303
|
key, value = string.split('=')
|
data/sys-proctable.gemspec
CHANGED
@@ -16,7 +16,7 @@ class TC_ProcTable_Darwin < Test::Unit::TestCase
|
|
16
16
|
virtual_size resident_size total_user total_system threads_user
|
17
17
|
threads_system policy faults pageins cow_faults messages_sent
|
18
18
|
messages_received syscalls_mach syscalls_unix csw threadnum numrunning
|
19
|
-
priority cmdline exe environ
|
19
|
+
priority cmdline exe environ threadinfo
|
20
20
|
]
|
21
21
|
|
22
22
|
@@pid = fork do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-proctable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: universal-darwin
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
|
31
31
|
tGSHgAmcLlkdGgan182qsE/4kKM=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: test-unit
|
metadata.gz.sig
CHANGED
Binary file
|