Class: Memory::Aggregate
- Inherits:
-
Object
- Object
- Memory::Aggregate
- Defined in:
- lib/memory/aggregate.rb
Defined Under Namespace
Classes: Total
Instance Attribute Summary collapse
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #<<(allocation) ⇒ Object
-
#initialize(title, &block) ⇒ Aggregate
constructor
A new instance of Aggregate.
- #print(io = $stderr, limit: 10, title: @title, level: 2) ⇒ Object
- #totals_by(key) ⇒ Object
Constructor Details
Instance Attribute Details
#total ⇒ Object (readonly)
Returns the value of attribute total.
72 73 74 |
# File 'lib/memory/aggregate.rb', line 72 def total @total end |
Instance Method Details
#<<(allocation) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# 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) ⇒ Object
85 86 87 |
# File 'lib/memory/aggregate.rb', line 85 def totals_by(key) @totals.sort_by{|metric, total| [total[key], metric]} end |