Class: HeapProfiler::Analyzer::StringDimension

Inherits:
Object
  • Object
show all
Defined in:
lib/heap_profiler/analyzer.rb

Defined Under Namespace

Classes: StringGroup, StringLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStringDimension

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

#statsObject (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