get_process_mem 0.2.2 → 0.2.3
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 -3
- data/CHANGELOG.md +4 -0
- data/lib/get_process_mem.rb +24 -10
- 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: 7b60fae7d8331f5398f41d526da4b9fa66259afc4c6241565aac397b2bc55fc9
|
4
|
+
data.tar.gz: 64b2eec9b3ab7ad3c34c139cab0b40160e893849e4d556b502a46eba3e958dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21462917fdd94d4e3c155a6aa6f2ef209e1556a653aa245b8d721938b91c6de0adef11cd026ec83fda36934fe32e6cf7223a31c3b127c64e26042e0b8df3c71e
|
7
|
+
data.tar.gz: 868292113b42ed941431a05977b6590c72a8a7415db1d56cdde5d5243212200a91c2a36ad788588fe8d48614107f66a47f28d803f044daed89e8306ef6530043
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/get_process_mem.rb
CHANGED
@@ -3,11 +3,25 @@ require 'bigdecimal'
|
|
3
3
|
|
4
4
|
# Cribbed from Unicorn Worker Killer, thanks!
|
5
5
|
class GetProcessMem
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
if Kernel.respond_to?(:BigDecimal)
|
7
|
+
private_class_method def self.number_to_bigdecimal(value)
|
8
|
+
BigDecimal(value)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
private_class_method def self.number_to_bigdecimal(value)
|
12
|
+
BigDecimal.new(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private def number_to_bigdecimal(value)
|
17
|
+
self.class.send(:number_to_bigdecimal, value)
|
18
|
+
end
|
19
|
+
|
20
|
+
KB_TO_BYTE = number_to_bigdecimal 1024 # 2**10 = 1024
|
21
|
+
MB_TO_BYTE = number_to_bigdecimal 1_048_576 # 1024**2 = 1_048_576
|
22
|
+
GB_TO_BYTE = number_to_bigdecimal 1_073_741_824 # 1024**3 = 1_073_741_824
|
9
23
|
CONVERSION = { "kb" => KB_TO_BYTE, "mb" => MB_TO_BYTE, "gb" => GB_TO_BYTE }
|
10
|
-
ROUND_UP =
|
24
|
+
ROUND_UP = number_to_bigdecimal "0.5"
|
11
25
|
attr_reader :pid
|
12
26
|
|
13
27
|
RUNS_ON_WINDOWS = Gem.win_platform?
|
@@ -40,15 +54,15 @@ class GetProcessMem
|
|
40
54
|
end
|
41
55
|
|
42
56
|
def kb(b = bytes)
|
43
|
-
(b/
|
57
|
+
(b/KB_TO_BYTE).to_f
|
44
58
|
end
|
45
59
|
|
46
60
|
def mb(b = bytes)
|
47
|
-
(b/
|
61
|
+
(b/MB_TO_BYTE).to_f
|
48
62
|
end
|
49
63
|
|
50
64
|
def gb(b = bytes)
|
51
|
-
(b/
|
65
|
+
(b/GB_TO_BYTE).to_f
|
52
66
|
end
|
53
67
|
|
54
68
|
def inspect
|
@@ -73,7 +87,7 @@ class GetProcessMem
|
|
73
87
|
return if lines.empty?
|
74
88
|
lines.reduce(0) do |sum, line|
|
75
89
|
line.match(/(?<value>(\d*\.{0,1}\d+))\s+(?<unit>\w\w)/) do |m|
|
76
|
-
value =
|
90
|
+
value = number_to_bigdecimal(m[:value]) + ROUND_UP
|
77
91
|
unit = m[:unit].downcase
|
78
92
|
sum += CONVERSION[unit] * value
|
79
93
|
end
|
@@ -88,10 +102,10 @@ class GetProcessMem
|
|
88
102
|
def ps_memory
|
89
103
|
if RUNS_ON_WINDOWS
|
90
104
|
size = ProcTable.ps(pid).working_set_size
|
91
|
-
|
105
|
+
number_to_bigdecimal(size)
|
92
106
|
else
|
93
107
|
mem = `ps -o rss= -p #{pid}`
|
94
|
-
KB_TO_BYTE *
|
108
|
+
KB_TO_BYTE * number_to_bigdecimal(mem == "" ? 0 : mem)
|
95
109
|
end
|
96
110
|
end
|
97
111
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sys-proctable
|