Class: HeapProfiler::Analyzer::StringDimension
- Inherits:
-
Object
- Object
- HeapProfiler::Analyzer::StringDimension
- Defined in:
- lib/heap_profiler/analyzer.rb
Defined Under Namespace
Classes: StringGroup, StringLocation
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
-
#initialize ⇒ StringDimension
constructor
A new instance of StringDimension.
- #process(_index, object) ⇒ Object
- #top_n(max) ⇒ Object
Constructor Details
#initialize ⇒ StringDimension
Returns a new instance of StringDimension.
157 158 159 |
# File 'lib/heap_profiler/analyzer.rb', line 157 def initialize @stats = Hash.new { |h, k| h[k] = StringGroup.new(k) } end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
156 157 158 |
# File 'lib/heap_profiler/analyzer.rb', line 156 def stats @stats end |
Instance Method Details
#process(_index, object) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/heap_profiler/analyzer.rb', line 161 def process(_index, object) return unless object[:type] == :STRING value = object[:value] return unless value # broken strings etc @stats[value].process(object) end |
#top_n(max) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/heap_profiler/analyzer.rb', line 168 def top_n(max) values = @stats.values values.sort! do |a, b| b.count <=> a.count end top = values.take(max) top.sort! do |a, b| cmp = b.count <=> a.count cmp == 0 ? b.value <=> a.value : cmp end top end |