Class: Memory::Report

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregates) ⇒ Report

Returns a new instance of Report.



38
39
40
41
42
43
# File 'lib/memory/report.rb', line 38

def initialize(aggregates)
  @total_allocated = Aggregate::Total.new
  @total_retained = Aggregate::Total.new
  
  @aggregates = aggregates
end

Instance Attribute Details

#total_allocatedObject (readonly)

Returns the value of attribute total_allocated.



45
46
47
# File 'lib/memory/report.rb', line 45

def total_allocated
  @total_allocated
end

Class Method Details

.generalObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/memory/report.rb', line 27

def self.general
  Report.new([
    Aggregate.new("By Gem", &:gem),
    Aggregate.new("By File", &:file),
    Aggregate.new("By Location", &:location),
    Aggregate.new("By Class", &:class_name),
    ValueAggregate.new("Strings By Gem", &:gem),
    ValueAggregate.new("Strings By Location", &:location),
  ])
end

Instance Method Details

#concat(allocations) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/memory/report.rb', line 47

def concat(allocations)
  allocations.each do |allocation|
    @total_allocated << allocation
    @total_retained << allocation if allocation.retained
    
    @aggregates.each do |aggregate|
      aggregate << allocation
    end
  end
end


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/memory/report.rb', line 58

def print(io = $stderr)
  io.puts "\# Memory Profile", nil
  
  io.puts "- Total Allocated: #{@total_allocated}"
  io.puts "- Total Retained: #{@total_retained}"
  io.puts
  
  @aggregates.each do |aggregate|
    aggregate.print(io)
  end
end