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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94fcbfe333ae0cfed19b0152cc0ac30185ade620dfdee8602c650d2af0e2f335
4
- data.tar.gz: 1ae8b971296e8707f11709c351e914b24dcf78cdcb35a137b43e24ac6f228bce
3
+ metadata.gz: 7b60fae7d8331f5398f41d526da4b9fa66259afc4c6241565aac397b2bc55fc9
4
+ data.tar.gz: 64b2eec9b3ab7ad3c34c139cab0b40160e893849e4d556b502a46eba3e958dff
5
5
  SHA512:
6
- metadata.gz: 84f9147a2c2ac5de19db50ef12a0d0ce281f0e17c616d7ddcda88bef6660b4e13b6c588d746330d566fffc6d9af657fe3d630ca52307b3a40147dc7ce26e2e77
7
- data.tar.gz: 2db59b624cd6ed098685b8851eb4776c36c83ec63da54e6da5b885c562311f37ee2792c9de59bad1b7fa138aff7f90a1e2de84db5806c204330149736a8e47c5
6
+ metadata.gz: 21462917fdd94d4e3c155a6aa6f2ef209e1556a653aa245b8d721938b91c6de0adef11cd026ec83fda36934fe32e6cf7223a31c3b127c64e26042e0b8df3c71e
7
+ data.tar.gz: 868292113b42ed941431a05977b6590c72a8a7415db1d56cdde5d5243212200a91c2a36ad788588fe8d48614107f66a47f28d803f044daed89e8306ef6530043
@@ -4,9 +4,8 @@ before_install:
4
4
  - gem install bundler -v 1.12.5
5
5
 
6
6
  rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.0
7
+ - 2.2.0
8
+ - 2.5.0
10
9
  - ruby-head
11
10
  - jruby-19mode
12
11
  - rbx-19mode
@@ -1,3 +1,7 @@
1
+ ## 0.2.3
2
+
3
+ - Silence BigDecimal deprecation warning under Ruby 2.5 (#26)
4
+
1
5
  ## 0.2.2
2
6
 
3
7
  - Fix support for Ruby 2.4 (#23)
@@ -3,11 +3,25 @@ require 'bigdecimal'
3
3
 
4
4
  # Cribbed from Unicorn Worker Killer, thanks!
5
5
  class GetProcessMem
6
- KB_TO_BYTE = 1024 # 2**10 = 1024
7
- MB_TO_BYTE = 1_048_576 # 1024**2 = 1_048_576
8
- GB_TO_BYTE = 1_073_741_824 # 1024**3 = 1_073_741_824
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 = BigDecimal.new("0.5")
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/BigDecimal.new(KB_TO_BYTE)).to_f
57
+ (b/KB_TO_BYTE).to_f
44
58
  end
45
59
 
46
60
  def mb(b = bytes)
47
- (b/BigDecimal.new(MB_TO_BYTE)).to_f
61
+ (b/MB_TO_BYTE).to_f
48
62
  end
49
63
 
50
64
  def gb(b = bytes)
51
- (b/BigDecimal.new(GB_TO_BYTE)).to_f
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 = BigDecimal.new(m[:value]) + ROUND_UP
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
- BigDecimal.new(size)
105
+ number_to_bigdecimal(size)
92
106
  else
93
107
  mem = `ps -o rss= -p #{pid}`
94
- KB_TO_BYTE * BigDecimal.new(mem == "" ? 0 : mem)
108
+ KB_TO_BYTE * number_to_bigdecimal(mem == "" ? 0 : mem)
95
109
  end
96
110
  end
97
111
  end
@@ -1,3 +1,3 @@
1
1
  class GetProcessMem
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
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.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-05-11 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable