get_process_mem 0.2.5 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d0fb74ff83b646fc0abdbbad624257304311fa98ea5204cce96d12957572432
4
- data.tar.gz: 8a51db8a8638d7d160b6a34d924244d4a28056168f3aea4341abf9d6fe890576
3
+ metadata.gz: 06a96e8d978fd95bcf546a1e5e8bbc01cc10635d50b2f87639eb9c1f8c7f4f76
4
+ data.tar.gz: 6c941ae4f0301ff698b9be4ba75597537ed3ae5a11bf9295ab81144ef8435047
5
5
  SHA512:
6
- metadata.gz: e3291519f57f2b44c5d8794098c5b87331bb49599f43ea1d06bc269560759e0e9ef0bb2318a4f1d261a4709634024cd00d0bb73bca559ff23440fb194cb25964
7
- data.tar.gz: 4c16b205f3a20b0f1a7a2110bb3ee370918107f2a4e509a044f9ab0dc01cf8285a3042c5cc656c65a6bd50d6e5f5d68c5bd2e980915d42632bf0fbed3faccfa3
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,12 @@
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)
6
+
7
+ ## 0.2.6
8
+
9
+ - Support returning memory from different PIDs on mac (https://github.com/schneems/get_process_mem/pull/41)
2
10
 
3
11
  ## 0.2.5
4
12
 
@@ -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.5"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -1,11 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class GetProcessMemTest < Test::Unit::TestCase
4
-
5
4
  def setup
6
5
  @mem = GetProcessMem.new
7
6
  end
8
7
 
8
+ def test_different_pid_returns_different_memory
9
+ pid = Process.spawn("tail -f Gemfile")
10
+
11
+ other_mem = GetProcessMem.new(pid)
12
+ assert @mem.kb > other_mem.kb
13
+ ensure
14
+ Process.kill('TERM', pid) if pid
15
+ Process.wait(pid) if pid
16
+ end
17
+
9
18
  def test_seems_to_work
10
19
  assert @mem.kb > 0
11
20
  assert @mem.mb > 0
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.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Schneeman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-05 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
@@ -93,7 +93,7 @@ homepage: https://github.com/schneems/get_process_mem
93
93
  licenses:
94
94
  - MIT
95
95
  metadata: {}
96
- post_install_message:
96
+ post_install_message:
97
97
  rdoc_options: []
98
98
  require_paths:
99
99
  - lib
@@ -108,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.3
112
- signing_key:
111
+ rubygems_version: 3.1.2
112
+ signing_key:
113
113
  specification_version: 4
114
114
  summary: Use GetProcessMem to find out the amount of RAM used by any process
115
115
  test_files: