memory_profiler 0.9.6 → 0.9.7

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: e2825892e9a2cf16a0cb685f91b8f754e2d85183
4
- data.tar.gz: 248304fe60edea15abc9e501028bae8b1021d295
3
+ metadata.gz: b3f841c1bfcbaecdaccf8359aa37a7d42605c485
4
+ data.tar.gz: 599119026dfb887ffc810d81da2b17a9e71f29cf
5
5
  SHA512:
6
- metadata.gz: 2a6c49cf4df8caac5ddc61d7fe1541e79468a522a3519f1d1965586e7195a20740a4623fee1a07130d0b37d9169ed82c85e0758a05076a0f300c02c0e0031d61
7
- data.tar.gz: 9e9b0a6a4b5b5986d2b029fb12f6c1d3eb62613f61d25df15a3bf2888237f56ead9bb6a980c25cfe5029d8249cb8b265cd58ab427aeb115f9565c6a235e1f7e0
6
+ metadata.gz: ac957555ecad713d83c891c87bf118f1a00dcf0633d1f18b3d38181b472f654db5218eb3c6494d66ae7b3a5da8bdd9425a4457a3c5e77f69514d8628490cba98
7
+ data.tar.gz: 54eb5dc1456d906452b152b000abcaca1d6b229d70e259ca54b2bad36476d69a94edbb2666daa603595a174f468ea7edf619e8afe6554ad3e2606443fbd1d11a
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ ## 0.9.7
4
+ - Improved class name detection for proxy objects, BasicObject objects, and
5
+ other edge cases @inossidabile @Hamdiakoguz @dgynn
6
+
7
+ ## 0.9.6
8
+ - FIX: pretty_print was failing under some conditions @vincentwoo
9
+ - FIX: if #class is somehow nil don't crash @vincentwoo
10
+
11
+ ## 0.9.5
12
+ - Improved stability and performance @dgynn
13
+
14
+ ## 0.9.4
15
+ - FIX: remove incorrect RVALUE offset on 2.2 @dgynn
16
+ - FEATURE: add total memory usage @dgynn
17
+
18
+ ## 0.9.3
19
+ - Add class reporting
20
+
21
+ ## 0.9.2
22
+ - Fix incorrect syntax in rescue clause
23
+
24
+ ## 0.9.0
25
+ - This is quite stable, upping version to reflect
26
+ - Fixed bug where it would crash when location was nil for some reason
27
+
28
+ ## 0.0.4
29
+ - Added compatibility with released version of Ruby 2.1.0
30
+ - Cleanup to use latest APIs available in 2.1.0
31
+
32
+ ## 0.0.3
33
+ - Added string analysis
data/README.md CHANGED
@@ -362,33 +362,3 @@ Memory profiler also performs some String analysis to help you find strings that
362
362
  3. Commit your changes (`git commit -am 'Add some feature'`)
363
363
  4. Push to the branch (`git push origin my-new-feature`)
364
364
  5. Create new Pull Request
365
-
366
- ## Changelog
367
-
368
- ### 0.9.6
369
- - FIX: pretty_print was failing under some conditions @vincentwoo
370
- - FIX: if #class is somehow nil don't crash @vincentwoo
371
-
372
- ### 0.9.5
373
- - Improved stability and performance @dgynn
374
-
375
- ### 0.9.4
376
- - FIX: remove incorrect RVALUE offset on 2.2 @dgynn
377
- - FEATURE: add total memory usage @dgynn
378
-
379
- ### 0.9.3
380
- - Add class reporting
381
-
382
- ### 0.9.2
383
- - Fix incorrect syntax in rescue clause
384
-
385
- ### 0.9.0
386
- - This is quite stable, upping version to reflect
387
- - Fixed bug where it would crash when location was nil for some reason
388
-
389
- ### 0.0.4
390
- - Added compatibility with released version of Ruby 2.1.0
391
- - Cleanup to use latest APIs available in 2.1.0
392
-
393
- ### 0.0.3
394
- - Added string analysis
@@ -25,7 +25,7 @@ module MemoryProfiler
25
25
  end
26
26
 
27
27
  def lookup_class_name(klass)
28
- @class_name_cache[klass] ||= (klass && klass.name) || '<<Unknown>>'
28
+ @class_name_cache[klass] ||= ((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
29
29
  end
30
30
 
31
31
  end
@@ -88,10 +88,6 @@ module MemoryProfiler
88
88
  "\033[7m#{str}\033[27m"
89
89
  end
90
90
 
91
- def no_colors
92
- self.gsub /\033\[\d+m/, "";
93
- end
94
-
95
91
  end
96
92
 
97
93
  end
@@ -48,14 +48,8 @@ module MemoryProfiler
48
48
 
49
49
  ObjectSpace.each_object do |obj|
50
50
  next unless ObjectSpace.allocation_generation(obj) == generation
51
- begin
52
- found = allocated[obj.__id__]
53
- retained[obj.__id__] = found if found
54
- rescue
55
- # __id__ is not defined on BasicObject, skip it
56
- # we can probably transplant the object_id at this point,
57
- # but it is quite rare
58
- end
51
+ found = allocated[obj.__id__]
52
+ retained[obj.__id__] = found if found
59
53
  end
60
54
  ObjectSpace.trace_object_allocations_clear
61
55
 
@@ -70,52 +64,43 @@ module MemoryProfiler
70
64
  # Stores results along with meta data of objects collected.
71
65
  def object_list(generation)
72
66
 
73
- objs = []
74
-
75
- ObjectSpace.each_object do |obj|
76
- next unless ObjectSpace.allocation_generation(obj) == generation
77
- begin
78
- if !trace || trace.include?(obj.class)
79
- objs << obj
80
- end
81
- rescue
82
- # may not respond to class so skip
83
- end
84
- end
85
-
86
67
  rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
87
68
  rvalue_size_adjustment = RUBY_VERSION < '2.2' ? rvalue_size : 0
88
69
  helper = Helpers.new
89
70
 
90
71
  result = StatHash.new.compare_by_identity
91
72
 
92
- objs.each do |obj|
73
+ ObjectSpace.each_object do |obj|
74
+ next unless ObjectSpace.allocation_generation(obj) == generation
75
+
93
76
  file = ObjectSpace.allocation_sourcefile(obj) || "(no name)".freeze
94
77
  next if @ignore_files && @ignore_files =~ file
95
78
  next if @allow_files && !(@allow_files =~ file)
96
79
 
97
- line = ObjectSpace.allocation_sourceline(obj)
98
- location = helper.lookup_location(file, line)
99
- klass = obj.class rescue nil
100
- class_name = helper.lookup_class_name(klass)
101
- gem = helper.guess_gem(file)
102
- string = '' << obj if klass == String
80
+ klass = obj.class rescue nil
81
+ unless Class === klass
82
+ # attempt to determine the true Class when .class returns something other than a Class
83
+ klass = Kernel.instance_method(:class).bind(obj).call
84
+ end
85
+ next if @trace && !trace.include?(klass)
103
86
 
104
87
  begin
105
- object_id = obj.__id__
88
+ line = ObjectSpace.allocation_sourceline(obj)
89
+ location = helper.lookup_location(file, line)
90
+ class_name = helper.lookup_class_name(klass)
91
+ gem = helper.guess_gem(file)
92
+
93
+ string = '' << obj if klass == String
106
94
 
107
95
  memsize = ObjectSpace.memsize_of(obj) + rvalue_size_adjustment
108
96
  # compensate for API bug
109
97
  memsize = rvalue_size if memsize > 100_000_000_000
110
- result[object_id] = MemoryProfiler::Stat.new(class_name, gem, file, location, memsize, string)
98
+ result[obj.__id__] = MemoryProfiler::Stat.new(class_name, gem, file, location, memsize, string)
111
99
  rescue
112
- # __id__ is not defined, give up
100
+ # give up if any any error occurs inspecting the object
113
101
  end
114
102
  end
115
103
 
116
- # Although `objs` will go out of scope, clear the array so objects can definitely be GCd
117
- objs.clear
118
-
119
104
  result
120
105
  end
121
106
  end
@@ -63,7 +63,11 @@ module MemoryProfiler
63
63
  # @param [Hash] options the options for output
64
64
  # @option opts [String] :to_file a path to your log file
65
65
  # @option opts [Boolean] :color_output a flag for whether to colorize output
66
- def pretty_print(io = STDOUT, **options)
66
+ def pretty_print(io = $stdout, **options)
67
+ # Handle the special case that Ruby PrettyPrint expects `pretty_print`
68
+ # to be a customized pretty printing function for a class
69
+ return io.pp_object(self) if defined?(PP) && io.is_a?(PP)
70
+
67
71
  io = File.open(options[:to_file], "w") if options[:to_file]
68
72
 
69
73
  color_output = options.fetch(:color_output) { io.respond_to?(:isatty) && io.isatty }
@@ -2,16 +2,15 @@ module MemoryProfiler
2
2
  module TopN
3
3
  # Fast approach for determining the top_n entries in a Hash of Stat objects.
4
4
  # Returns results for both memory (memsize summed) and objects allocated (count) as a tuple.
5
- def top_n(max, metric)
5
+ def top_n(max, metric_method)
6
6
 
7
- stats_by_metric = self.values.map! { |stat| [stat.send(metric), stat.memsize] }
7
+ stat_totals = self.values.group_by(&metric_method).map do |metric, stats|
8
+ [metric, stats.reduce(0) { |sum, stat| sum + stat.memsize }, stats.size]
9
+ end
8
10
 
9
- stat_totals = stats_by_metric.group_by { |metric_value, _memsize| metric_value }.
10
- map { |key, values| [key, values.reduce(0) { |sum, item| _key, memsize = item ; sum + memsize }, values.size] }
11
-
12
- stats_by_memsize = stat_totals.sort_by! { |metric, memsize, _count| [-memsize, metric] }.first(max).
11
+ stats_by_memsize = stat_totals.sort_by! { |metric, memsize, _count| [-memsize, metric] }.take(max).
13
12
  map! { |metric, memsize, _count| { data: metric, count: memsize } }
14
- stats_by_count = stat_totals.sort_by! { |metric, _memsize, count| [-count, metric] }.first(max).
13
+ stats_by_count = stat_totals.sort_by! { |metric, _memsize, count| [-count, metric] }.take(max).
15
14
  map! { |metric, _memsize, count| { data: metric, count: count } }
16
15
 
17
16
  [stats_by_memsize, stats_by_count]
@@ -1,3 +1,3 @@
1
1
  module MemoryProfiler
2
- VERSION = "0.9.6"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -1,85 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
11
+ date: 2016-11-06 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description: Memory profiling routines for Ruby 2.1+
84
14
  email:
85
15
  - sam.saffron@gmail.com
@@ -87,6 +17,7 @@ executables: []
87
17
  extensions: []
88
18
  extra_rdoc_files: []
89
19
  files:
20
+ - CHANGELOG.md
90
21
  - LICENSE.txt
91
22
  - README.md
92
23
  - lib/memory_profiler.rb
@@ -119,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
50
  version: '0'
120
51
  requirements: []
121
52
  rubyforge_project:
122
- rubygems_version: 2.4.5.1
53
+ rubygems_version: 2.5.1
123
54
  signing_key:
124
55
  specification_version: 4
125
56
  summary: Memory profiling routines for Ruby 2.1+