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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +5 -1
- data/lib/get_process_mem.rb +4 -2
- data/lib/get_process_mem/darwin.rb +39 -29
- data/lib/get_process_mem/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a96e8d978fd95bcf546a1e5e8bbc01cc10635d50b2f87639eb9c1f8c7f4f76
|
4
|
+
data.tar.gz: 6c941ae4f0301ff698b9be4ba75597537ed3ae5a11bf9295ab81144ef8435047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cdb2baad08676298249f006b12f0c61bd0fdc1e13902211e2e0c3ea965c39fee2edb2ad3d2ceb617dcf450738e765c60c7e748830d85c52b044fa0ad8a3c8db
|
7
|
+
data.tar.gz: 35d717cc39f85a902adaa8ea6028d969b40b89465bcc0d1578de4e97308fe890e77ce9ff06b68855253030b3ab26fa130e2e44be06b041368a39a4cb4bc300f8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/get_process_mem.rb
CHANGED
@@ -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
|
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 '
|
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
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
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
|
52
|
+
def get_proc_pidinfo(pid)
|
41
53
|
data = TaskInfo.new
|
42
|
-
|
43
|
-
|
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 "
|
58
|
+
raise SystemCallError.new("proc_pidinfo returned #{result}", FFI.errno);
|
49
59
|
end
|
50
60
|
end
|
51
61
|
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.
|
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-
|
11
|
+
date: 2020-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|