Class: HeapProfiler::Analyzer::GroupedDimension
Instance Attribute Summary
Attributes inherited from Dimension
#memory, #objects
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Dimension
#stats
Constructor Details
Returns a new instance of GroupedDimension.
48
49
50
51
|
# File 'lib/heap_profiler/analyzer.rb', line 48
def initialize
@objects = Hash.new { |h, k| h[k] = 0 }
@memory = Hash.new { |h, k| h[k] = 0 }
end
|
Class Method Details
.build(grouping) ⇒ Object
Instance Method Details
#process(index, object) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/heap_profiler/analyzer.rb', line 53
def process(index, object)
if (group = @grouping.call(index, object))
@objects[group] += 1
@memory[group] += object[:memsize]
end
end
|
#top_n(metric, max) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/heap_profiler/analyzer.rb', line 60
def top_n(metric, max)
values = stats(metric).sort do |a, b|
b[1] <=> a[1]
end
top = values.take(max)
top.sort! do |a, b|
cmp = b[1] <=> a[1]
cmp == 0 ? b[0] <=> a[0] : cmp
end
top
end
|