Class: Memory::ValueAggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/memory/aggregate.rb

Instance Method Summary collapse

Constructor Details

#initialize(title, &block) ⇒ ValueAggregate

Returns a new instance of ValueAggregate.



101
102
103
104
105
106
# File 'lib/memory/aggregate.rb', line 101

def initialize(title, &block)
	@title = title
	@metric = block
	
	@aggregates = Hash.new{|h,k| h[k] = Aggregate.new(k.inspect, &@metric)}
end

Instance Method Details

#<<(allocation) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/memory/aggregate.rb', line 108

def << allocation
	if value = allocation.value
		aggregate = @aggregates[value]
		
		aggregate << allocation
	end
end

#aggregates_by(key) ⇒ Object



116
117
118
# File 'lib/memory/aggregate.rb', line 116

def aggregates_by(key)
	@aggregates.sort_by{|value, aggregate| [aggregate.total[key], value]}
end


120
121
122
123
124
125
126
# File 'lib/memory/aggregate.rb', line 120

def print(io = $stderr, limit: 10, level: 2)
	io.puts "#{'#' * level} #{@title}", nil
	
	aggregates_by(:count).last(limit).reverse_each do |value, aggregate|
		aggregate.print(io, level: level+1)
	end
end