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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 138368be13088153dc725009fa1921edf64a7a63
4
- data.tar.gz: a046d5a49a5071add7cb27ca153692dacf5234ff
3
+ metadata.gz: 536255fca496dc375430fe9698a5f277fdd8db10
4
+ data.tar.gz: f108e5642d8312dae6fc598023c2a2703320278a
5
5
  SHA512:
6
- metadata.gz: 0a75f3fc8d2190f04bf05e9ee0859a9c1e91321eb08980af50a5f990c93790f3482edb1c3218f6557e9667d565268d0a69352916898276738fbc2d45e8afaa1f
7
- data.tar.gz: c758a8a578c3ec13230b88f2d5801516ce57fee59d6352df1f7fcd2b6419046ec946d8e9eeaf0d9e281c588a1927bf54d3d74929add706fa0450f67d116efc71
6
+ metadata.gz: 113ed8abaa560fd6abaa75b545eb9d068c8a510c388ea0eda1c97ba80a2571df9ae11653888920e42f93e775920df151bc65ea9f835a94ef0bb3dcc7bad2f925
7
+ data.tar.gz: 7d0eb460512b0c1f9cb8173de138069cea86382f0b4173845479c79855e8cbfc8239dbb907b1b8dad00b1511438dfda4f3a40613e782183ec5ee17a47140085b
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.1.1 - 30-Jun-2016
2
+ * Added thread information for OS X.
3
+ * Fixed VERSION constant for HP-UX.
4
+
1
5
  == 1.1.0 - 27-Jun-2016
2
6
  * License was changed to Apache 2.0.
3
7
  * The OS X version now requires OS X 10.7 or later.
@@ -13,16 +13,16 @@ module Sys
13
13
 
14
14
  private
15
15
 
16
- PROC_ALL_PIDS = 1
17
16
  PROC_PIDTASKALLINFO = 2
18
- PROC_PIDTASKINFO = 4
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
- get_cmd_args_and_env(lpid, struct) # Pass by reference
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 sring
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 collect of key=value pairs which
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('=')
@@ -1,6 +1,6 @@
1
1
  module Sys
2
2
  class ProcTable
3
3
  # The version of the sys-proctable library
4
- VERSION = '1.1.0'.freeze
4
+ VERSION = '1.1.1'.freeze
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'sys-proctable'
5
- spec.version = '1.1.0'
5
+ spec.version = '1.1.1'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Apache 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
@@ -19,7 +19,7 @@ class TC_ProcTable_All < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  test "version is set to expected value" do
22
- assert_equal('1.1.0', ProcTable::VERSION)
22
+ assert_equal('1.1.1', ProcTable::VERSION)
23
23
  end
24
24
 
25
25
  test "fields basic functionality" do
@@ -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.0
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-06-27 00:00:00.000000000 Z
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