class Memory::Aggregate
Constants
- Total
Attributes
total[R]
Public Class Methods
new(title, &block)
click to toggle source
# File lib/memory/aggregate.rb, line 64 def initialize(title, &block) @title = title @metric = block @total = Total.new @totals = Hash.new{|h,k| h[k] = Total.new} end
Public Instance Methods
<<(allocation)
click to toggle source
# File lib/memory/aggregate.rb, line 74 def << allocation metric = @metric.call(allocation) total = @totals[metric] total.memory += allocation.memsize total.count += 1 @total.memory += allocation.memsize @total.count += 1 end
print(io = $stderr, limit: 10, title: @title, level: 2)
click to toggle source
# File lib/memory/aggregate.rb, line 89 def print(io = $stderr, limit: 10, title: @title, level: 2) io.puts "#{'#' * level} #{title} #{@total}", nil totals_by(:memory).last(limit).reverse_each do |metric, total| io.puts "- #{total}\t#{metric}" end io.puts nil end
totals_by(key)
click to toggle source
# File lib/memory/aggregate.rb, line 85 def totals_by(key) @totals.sort_by{|metric, total| [total[key], metric]} end