memory_profiler 0.9.10 → 0.9.11

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: 36702507c9914c94dfb3218eff88eb04baedbfd19e17773b0cc0783003fbd773
4
- data.tar.gz: 447062d601138e3640117983a523380f455798f921294d63f61e72da55c1a620
3
+ metadata.gz: 7da6190dc6c838833e47d41765b0cfff971a88fd650968126345a022b7adab9f
4
+ data.tar.gz: 99c847bf242406d438b06a9a4c747bf7200556f7380e4c93fa69476e523d0675
5
5
  SHA512:
6
- metadata.gz: 35cf530186236d02baa145fec37e519f24eb3322334154559af3f938b955c648ad8eb298b830e83d9ab1751842e49b59aa52f8c7b2e350c7f1fec77cd065d28a
7
- data.tar.gz: a4d24d2a9c3f985fdbdec38c3d14b9dcb0db816aef70c2f590565c5a5e81beb5ffc353a56c220f814f3f135ee1d5a4a6c1e100b1a95b080a351eace0d3f0c6b6
6
+ metadata.gz: 821c0b5746630a740e23570b31bc1faab53b2be90d1f53000310ca2fab122b8e254f93ae25fffa63ca95b7c350b721d62320276dada82c05712945047446a683
7
+ data.tar.gz: a354ea734d19c16510c6c76612d58ea6d830f39883ef215accbc9f3c33a3f745b55a90275cdef8779b03d1dc4779fe156a9e0bfb1aa1f1073cd03f4b54696e4f
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.11
4
+ - Reduce memory needed for string allocation tracing @dgynn
5
+ - Use yield rather than block.call to reduce an allocation @dgynn
6
+ - Ensure string allocation locations sort consistently @dgynn
7
+
3
8
  ## 0.9.10
4
9
  - Add better detection for stdlib "gems"
5
10
 
@@ -32,7 +32,10 @@ module MemoryProfiler
32
32
  end
33
33
 
34
34
  def lookup_string(obj)
35
- @string_cache[obj] ||= String.new << obj
35
+ # This string is shortened to 200 characters which is what the string report shows
36
+ # The string report can still list unique strings longer than 200 characters
37
+ # separately because the object_id of the shortened string will be different
38
+ @string_cache[obj] ||= obj[0,200]
36
39
  end
37
40
  end
38
41
  end
@@ -65,7 +65,7 @@ module MemoryProfiler
65
65
  def run(&block)
66
66
  start
67
67
  begin
68
- block.call
68
+ yield
69
69
  rescue Exception
70
70
  ObjectSpace.trace_object_allocations_stop
71
71
  GC.enable
@@ -47,16 +47,26 @@ module MemoryProfiler
47
47
  end
48
48
 
49
49
  def string_report(data, top)
50
- data.values
51
- .keep_if { |stat| stat.string_value }
52
- .map! { |stat| [stat.string_value, stat.location] }
53
- .group_by { |string, _location| string }
54
- .sort_by {|string, list| [-list.size, string] }
55
- .first(top)
56
- .map { |string, list| [string, list.group_by { |_string, location| location }
57
- .map { |location, locations| [location, locations.size] }
58
- ]
59
- }
50
+ grouped_strings = data.values.
51
+ keep_if { |stat| stat.string_value }.
52
+ group_by { |stat| stat.string_value.object_id }.
53
+ values
54
+
55
+ if grouped_strings.size > top
56
+ cutoff = grouped_strings.sort_by!(&:size)[-top].size
57
+ grouped_strings.keep_if { |list| list.size >= cutoff }
58
+ end
59
+
60
+ grouped_strings.
61
+ sort! { |a, b| a.size == b.size ? a[0].string_value <=> b[0].string_value : b.size <=> a.size }.
62
+ first(top).
63
+ # Return array of [string, [[location, count], [location, count], ...]
64
+ map! { |list| [list[0].string_value,
65
+ list.group_by { |stat| stat.location }.
66
+ map { |location, stat_list| [location, stat_list.size] }.
67
+ sort_by!(&:last).reverse!
68
+ ]
69
+ }
60
70
  end
61
71
 
62
72
  # Output the results of the report
@@ -110,7 +120,7 @@ module MemoryProfiler
110
120
  io.puts "#{title} String Report"
111
121
  io.puts @colorize.line("-----------------------------------")
112
122
  strings.each do |string, stats|
113
- io.puts "#{stats.reduce(0) { |a, b| a + b[1] }.to_s.rjust(10)} #{@colorize.string((string[0..200].inspect))}"
123
+ io.puts "#{stats.reduce(0) { |a, b| a + b[1] }.to_s.rjust(10)} #{@colorize.string((string.inspect))}"
114
124
  stats.sort_by { |x, y| [-y, x] }.each do |location, count|
115
125
  io.puts "#{@colorize.path(count.to_s.rjust(10))} #{location}"
116
126
  end
@@ -1,3 +1,3 @@
1
1
  module MemoryProfiler
2
- VERSION = "0.9.10"
2
+ VERSION = "0.9.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Memory profiling routines for Ruby 2.1+
14
14
  email:
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.7.3
53
+ rubygems_version: 2.7.6
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Memory profiling routines for Ruby 2.1+