Class: Memory::Aggregate
- Inherits:
-
Object
- Object
- Memory::Aggregate
- Defined in:
- lib/memory/aggregate.rb
Defined Under Namespace
Classes: Total
Instance Attribute Summary collapse
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#totals ⇒ Object
readonly
Returns the value of attribute totals.
Instance Method Summary collapse
- #<<(allocation) ⇒ Object
- #as_json ⇒ 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
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
63 64 65 |
# File 'lib/memory/aggregate.rb', line 63 def metric @metric end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
62 63 64 |
# File 'lib/memory/aggregate.rb', line 62 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
64 65 66 |
# File 'lib/memory/aggregate.rb', line 64 def total @total end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
65 66 67 |
# File 'lib/memory/aggregate.rb', line 65 def totals @totals end |
Instance Method Details
#<<(allocation) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/memory/aggregate.rb', line 67 def << allocation metric = @metric.call(allocation) total = @totals[metric] total.memory += allocation.memsize total.count += 1 @total.memory += allocation.memsize @total.count += 1 end |
#as_json ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/memory/aggregate.rb', line 92 def as_json { title: @title, total: @total.as_json, totals: @totals.map{|k, v| [k, v.as_json]} } end |
#print(io = $stderr, limit: 10, title: @title, level: 2) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/memory/aggregate.rb', line 82 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
78 79 80 |
# File 'lib/memory/aggregate.rb', line 78 def totals_by(key) @totals.sort_by{|metric, total| [total[key], metric]} end |