Class: HeapProfiler::Analyzer::StringDimension::StringGroup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



130
131
132
# File 'lib/heap_profiler/analyzer.rb', line 130

def count
  @count
end

#locationsObject (readonly)

Returns the value of attribute locations.



130
131
132
# File 'lib/heap_profiler/analyzer.rb', line 130

def locations
  @locations
end

#memsizeObject (readonly)

Returns the value of attribute memsize.



130
131
132
# File 'lib/heap_profiler/analyzer.rb', line 130

def memsize
  @memsize
end

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