Class: HeapProfiler::Analyzer::StringDimension::StringGroup
- Inherits:
-
Object
- Object
- HeapProfiler::Analyzer::StringDimension::StringGroup
- Defined in:
- lib/heap_profiler/analyzer.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
-
#memsize ⇒ Object
readonly
Returns the value of attribute memsize.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ StringGroup
constructor
TODO: should we consider encoding?.
- #process(object) ⇒ Object
- #top_n(max) ⇒ Object
Constructor Details
#initialize(value) ⇒ StringGroup
TODO: should we consider encoding?
131 132 133 134 135 136 |
# File 'lib/heap_profiler/analyzer.rb', line 131 def initialize(value) # TODO: should we consider encoding? @value = value @locations_counts = Hash.new { |h, k| h[k] = StringLocation.new(k) } @count = 0 @memsize = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
130 131 132 |
# File 'lib/heap_profiler/analyzer.rb', line 130 def count @count end |
#locations ⇒ Object (readonly)
Returns the value of attribute locations.
130 131 132 |
# File 'lib/heap_profiler/analyzer.rb', line 130 def locations @locations end |
#memsize ⇒ Object (readonly)
Returns the value of attribute memsize.
130 131 132 |
# File 'lib/heap_profiler/analyzer.rb', line 130 def memsize @memsize end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
130 131 132 |
# File 'lib/heap_profiler/analyzer.rb', line 130 def value @value end |
Instance Method Details
#process(object) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/heap_profiler/analyzer.rb', line 138 def process(object) @count += 1 @memsize += object[:memsize] if (file = object[:file]) && (line = object[:line]) @locations_counts["#{file}:#{line}"].process(object) end end |
#top_n(max) ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/heap_profiler/analyzer.rb', line 146 def top_n(max) values = @locations_counts.values values.sort! do |a, b| cmp = b.count <=> a.count cmp == 0 ? b.location <=> a.location : cmp end values.take(max) end |