memory_tracker 1.2.4 → 1.3.0

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
  SHA1:
3
- metadata.gz: eb923ce2e1e745654ec6424cc6991c1672db8e92
4
- data.tar.gz: 6c57f86823beb6905a70c5cb09a7ac787fa7f997
3
+ metadata.gz: 5d034885b36b92cbe3e175ffdb7fb26890e3ba1a
4
+ data.tar.gz: 037010fff3c82ee9a487d6b36cd4abe37beaeee8
5
5
  SHA512:
6
- metadata.gz: 5ad3423a35aa91e1937cca83504a155d5b512fc1dd0dffa7ea98aae21814efb7968134cf3a23fe1e1150bbf886db0d41d2c369950e7760e4ebdea1a2f1c41bd5
7
- data.tar.gz: c7d76c6f94d49bdad4224c152339ff504aee7d7a70829f1b4b40b6c1467575f542e9cee69032a52c88e1a398a8304b2c296c27b709d9dffac4f67b72c9d4a690
6
+ metadata.gz: 0dffc3d046e6a7622d6379c1c0dad2e3d175603f9b10b1516b6f7329f0b53b860759a07069087f5b6174977365ce42551ec410ce93c351b3664caea88639f7d5
7
+ data.tar.gz: 7ec5aaa4cde2bdf10d8d828c3f6d33c1318d34110028c6b90cc1ccdfd440a88fc4161cbce41a37ff3748b4792edf234c9bd1a2b53b947d5a1ba6a89d8644e921
data/Gemfile.lock CHANGED
@@ -14,7 +14,7 @@ GEM
14
14
  minitest (~> 5.1)
15
15
  thread_safe (~> 0.3, >= 0.3.4)
16
16
  tzinfo (~> 1.1)
17
- byebug (4.0.3)
17
+ byebug (4.0.5)
18
18
  columnize (= 0.9.0)
19
19
  columnize (0.9.0)
20
20
  diff-lcs (1.2.5)
@@ -22,7 +22,7 @@ module MemoryTracker
22
22
  @pid = Process.pid
23
23
  @rss = Request.rss
24
24
  @vsize = Request.vsize
25
- @num_heaps = GC.stat[:heap_used]
25
+ @num_heaps = GcStat.heap_used
26
26
 
27
27
  respond_to do |format|
28
28
  format.json do
@@ -1,20 +1,74 @@
1
1
  module MemoryTracker
2
2
  class GcStat
3
- attr_reader :stats
3
+
4
+ include Enumerable
5
+
6
+ RUBY22_TO_CANONICAL_MAPPING = { total_allocated_objects: :total_allocated_object,
7
+ total_freed_objects: :total_freed_object,
8
+ heap_allocated_pages: :heap_used,
9
+ heap_live_slots: :heap_live_num,
10
+ heap_free_slots: :heap_free_num,
11
+ heap_final_slots: :heap_final_num,
12
+ heap_sorted_length: :heap_length
13
+ }
14
+ CANONICAL_TO_RUBY22_MAPPING = RUBY22_TO_CANONICAL_MAPPING.invert
4
15
 
5
16
  def initialize(rss, vsize)
6
17
  @stats = GC.stat.merge({ :rss => rss, :vsize => vsize})
7
18
  end
8
19
 
20
+ def each(&block)
21
+ @stats.each do |k, v|
22
+ yield canonical_key_name(k), v
23
+ end
24
+ end
25
+
26
+ def keys
27
+ @stats.keys
28
+ end
29
+
9
30
  def ordered_keys
10
- @stats.keys.sort
31
+ @stats.keys.map { |k| canonical_key_name(k) }.sort
11
32
  end
12
33
 
13
34
  def ordered_values(ordered_columns = ordered_keys)
14
35
  ordered_columns.inject([]) do |vals, key|
15
- vals << @stats[key]
16
- vals
36
+ vals << @stats[current_version_key_name(key)]
37
+ end
38
+ end
39
+
40
+ def [](key)
41
+ @stats[current_version_key_name(key)]
42
+ end
43
+
44
+ def canonical_key_name(key)
45
+ self.class.canonical_key_name(key)
46
+ end
47
+
48
+ def current_version_key_name(key)
49
+ self.class.current_version_key_name(key)
50
+ end
51
+
52
+ def self.canonical_key_name(key)
53
+ canonical = key
54
+ case RUBY_VERSION
55
+ when /\A2\.2\./
56
+ canonical = RUBY22_TO_CANONICAL_MAPPING.fetch(key, key)
17
57
  end
58
+ canonical
59
+ end
60
+
61
+ def self.current_version_key_name(key)
62
+ current_key_name = key
63
+ case RUBY_VERSION
64
+ when /\A2\.2\./
65
+ current_key_name = CANONICAL_TO_RUBY22_MAPPING.fetch(key, key)
66
+ end
67
+ current_key_name
68
+ end
69
+
70
+ def self.heap_used
71
+ GC.stat[current_version_key_name(:heap_used)]
18
72
  end
19
73
 
20
74
  def self.gcdiff(before, after)
@@ -43,8 +97,8 @@ module MemoryTracker
43
97
 
44
98
  def initialize(before, after)
45
99
  @after = after
46
- @stats = after.stats.inject({}) do |h, (k, v)|
47
- h[k] = after.stats[k] - before.stats[k]
100
+ @stats = after.inject({}) do |h, (k, v)|
101
+ h[k] = after[k] - before[k]
48
102
  h
49
103
  end
50
104
  end
@@ -55,8 +109,8 @@ module MemoryTracker
55
109
  h[:total_allocated_object] = stats[:total_allocated_object]
56
110
  h[:count] = stats[:count]
57
111
  h[:rss] = stats[:rss]
58
- h[:heap_used] = @after.stats[:heap_used]
59
- h[:in_use] = @after.stats[:total_allocated_object] - @after.stats[:total_freed_object]
112
+ h[:heap_used] = @after[:heap_used]
113
+ h[:in_use] = @after[:total_allocated_object] - @after[:total_freed_object]
60
114
  h
61
115
  end
62
116
  end
@@ -3,7 +3,7 @@ module MemoryTracker
3
3
  class GcstatLogfileStore < Base
4
4
  register_store :gcstat_logfile
5
5
 
6
- COLUMNS = [ :count, :heap_final_num, :heap_free_num, :heap_increment, :heap_length, :heap_live_num, :heap_used, :rss, :total_allocated_object, :total_freed_object, :vsize ]
6
+ COLUMNS = [ :count, :heap_final_num, :heap_free_num, :heap_length, :heap_live_num, :heap_used, :rss, :total_allocated_object, :total_freed_object, :vsize ]
7
7
 
8
8
  def initialize(opts)
9
9
  logger_class = opts.fetch(:logger_class, 'Logger')
@@ -32,8 +32,8 @@ module MemoryTracker
32
32
  def logline
33
33
  pid = Process.pid
34
34
 
35
- end_gcstats = @request.end_gcstat.stats
36
- start_gcstats = @request.start_gcstat.stats
35
+ end_gcstats = @request.end_gcstat
36
+ start_gcstats = @request.start_gcstat
37
37
  delta_gcstats = @request.gcstat_delta.stats
38
38
 
39
39
  log_msg = "#{Time.now.localtime.strftime("%m-%d %H:%M:%S")} pid:#{'%05d' % pid}"
@@ -1,3 +1,3 @@
1
1
  module MemoryTracker
2
- VERSION = "1.2.4"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -9,8 +9,8 @@ module MemoryTracker
9
9
 
10
10
  it 'should initalize start_gcstat' do
11
11
  @request.start_gcstat.should be_a(GcStat)
12
- @request.start_gcstat.stats.keys.should include :rss
13
- @request.start_gcstat.stats.keys.should include :vsize
12
+ @request.start_gcstat.keys.should include :rss
13
+ @request.start_gcstat.keys.should include :vsize
14
14
  end
15
15
 
16
16
  it 'should have a controller' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Le Rohellec
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.2.2
158
+ rubygems_version: 2.4.6
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Rails memory allocations tracker