get_process_mem 0.2.6 → 0.2.7

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: 9bb77afa418ea02d1e7d7416d88fc9706de5c581c84aa22d3199c405e406404e
4
- data.tar.gz: 1ee05474ce71701a823828452ee0d657422f790aafc8a0cdd7b2259843af4f0f
3
+ metadata.gz: 06a96e8d978fd95bcf546a1e5e8bbc01cc10635d50b2f87639eb9c1f8c7f4f76
4
+ data.tar.gz: 6c941ae4f0301ff698b9be4ba75597537ed3ae5a11bf9295ab81144ef8435047
5
5
  SHA512:
6
- metadata.gz: d70576115a29294f6e0bf456f5992b9f1aa208d1c0855ccf15492c93824ac602c8911bca6b819723d4f2a1faeb25828afe453ff5c1f3bb3715e632eae7b339e7
7
- data.tar.gz: cd0c1482f61ef34933cbe87afcbf281debd359b6f37e476dc765196b791c61fa768aab5f9a5f0eb98df0026ac174d3036633bce4135e5e7c650ff40f23d259a3
6
+ metadata.gz: 3cdb2baad08676298249f006b12f0c61bd0fdc1e13902211e2e0c3ea965c39fee2edb2ad3d2ceb617dcf450738e765c60c7e748830d85c52b044fa0ad8a3c8db
7
+ data.tar.gz: 35d717cc39f85a902adaa8ea6028d969b40b89465bcc0d1578de4e97308fe890e77ce9ff06b68855253030b3ab26fa130e2e44be06b041368a39a4cb4bc300f8
@@ -15,6 +15,8 @@ rvm:
15
15
 
16
16
  matrix:
17
17
  allow_failures:
18
+ - rvm: 2.2
19
+ if: os = osx
18
20
  - rvm: ruby-head
19
21
  - rvm: jruby-head
20
22
  - rvm: truffleruby
@@ -1,4 +1,8 @@
1
- ## Master - unreleased
1
+ ## HEAD (unreleased)
2
+
3
+ ## 0.2.7
4
+
5
+ - Native (faster) support for returning memory from different PIDs on mac (https://github.com/schneems/get_process_mem/pull/42)
2
6
 
3
7
  ## 0.2.6
4
8
 
@@ -58,7 +58,7 @@ class GetProcessMem
58
58
 
59
59
  def bytes
60
60
  memory = linux_status_memory if linux?
61
- memory ||= darwin_memory if RUNS_ON_DARWIN && Process.pid == pid
61
+ memory ||= darwin_memory if RUNS_ON_DARWIN
62
62
  memory ||= ps_memory
63
63
  end
64
64
 
@@ -119,6 +119,8 @@ class GetProcessMem
119
119
  end
120
120
 
121
121
  def darwin_memory
122
- Darwin.resident_size
122
+ Darwin.resident_size(pid)
123
+ rescue Errno::EPERM
124
+ nil
123
125
  end
124
126
  end
@@ -3,49 +3,59 @@ require 'ffi'
3
3
  class GetProcessMem
4
4
  class Darwin
5
5
  extend FFI::Library
6
- ffi_lib 'c'
7
- attach_function :mach_task_self, [], :__darwin_mach_port_t
8
- attach_function :task_info,
9
- [
10
- :__darwin_mach_port_t,
11
- :int, # return selector
12
- :pointer, #pointer to task info
13
- :pointer, #pointer to int (size of structure / bytes filled out)
14
- ],
15
- :int
6
+ ffi_lib 'proc'
16
7
 
17
- class IntPtr < FFI::Struct
18
- layout :value, :int
19
- end
20
8
 
21
9
  class TaskInfo < FFI::Struct
22
- layout :suspend_count, :int32,
23
- :virtual_size, :uint64,
24
- :resident_size, :uint64,
25
- :user_time, :uint64,
26
- :system_time, :uint64,
27
- :policy, :int32
10
+ layout :pti_virtual_size, :uint64,
11
+ :pti_resident_size, :uint64,
12
+ :pti_total_user, :uint64,
13
+ :pti_total_system, :uint64,
14
+ :pti_threads_user, :uint64,
15
+ :pti_threads_system, :uint64,
16
+ :pti_policy, :int32,
17
+ :pti_faults, :int32,
18
+ :pti_pageins, :int32,
19
+ :pti_cow_faults, :int32,
20
+ :pti_messages_sent, :int32,
21
+ :pti_messages_received, :int32,
22
+ :pti_syscalls_mach, :int32,
23
+ :pti_syscalls_unix, :int32,
24
+ :pti_csw, :int32,
25
+ :pti_threadnum, :int32,
26
+ :pti_numrunning, :int32,
27
+ :pti_priority, :int32
28
+
28
29
  end
29
30
 
30
- MACH_TASK_BASIC_INFO = 20
31
- MACH_TASK_BASIC_INFO_COUNT = TaskInfo.size / FFI.type_size(:uint)
31
+
32
+ attach_function :proc_pidinfo,
33
+ [
34
+ :int, #pid
35
+ :int, # flavour
36
+ :uint64, #arg, not needed for this selector
37
+ TaskInfo.by_ref, #output buffer
38
+ :int, #size of buffer
39
+ ],
40
+ :int
41
+
42
+
43
+ PROC_PIDTASKINFO = 4 #from sys/proc_info.h
32
44
 
33
45
  class << self
34
- def resident_size
35
- mach_task_info[:resident_size]
46
+ def resident_size(pid)
47
+ get_proc_pidinfo(pid)[:pti_resident_size]
36
48
  end
37
49
 
38
50
  private
39
51
 
40
- def mach_task_info
52
+ def get_proc_pidinfo(pid)
41
53
  data = TaskInfo.new
42
- out_count = IntPtr.new
43
- out_count[:value] = MACH_TASK_BASIC_INFO_COUNT
44
- result = task_info(mach_task_self, MACH_TASK_BASIC_INFO, data, out_count)
45
- if result == 0
54
+ result = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, data, TaskInfo.size)
55
+ if result == TaskInfo.size
46
56
  data
47
57
  else
48
- raise "task_info returned #{result}"
58
+ raise SystemCallError.new("proc_pidinfo returned #{result}", FFI.errno);
49
59
  end
50
60
  end
51
61
  end
@@ -1,3 +1,3 @@
1
1
  class GetProcessMem
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_process_mem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Schneeman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi