Class: Minitest::GCStatsReporter

Inherits:
AbstractReporter
  • Object
show all
Defined in:
lib/minitest/gcstats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max) ⇒ GCStatsReporter

Returns a new instance of GCStatsReporter.



68
69
70
71
72
73
# File 'lib/minitest/gcstats.rb', line 68

def initialize max
  super()

  self.max = max
  self.stats = {}
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



66
67
68
# File 'lib/minitest/gcstats.rb', line 66

def max
  @max
end

#statsObject

Returns the value of attribute stats.



66
67
68
# File 'lib/minitest/gcstats.rb', line 66

def stats
  @stats
end

Instance Method Details

#record(result) ⇒ Object



75
76
77
# File 'lib/minitest/gcstats.rb', line 75

def record result
  self.stats[result] = result.gc_stats
end

#reportObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/minitest/gcstats.rb', line 79

def report
  total = stats.values.inject(&:+)
  pct = total / 100.0

  puts
  puts "Top #{max} tests by objects allocated"
  puts
  stats.sort_by { |k,v| [-v, k.class.name, k.name] }.first(max).each do |k,v|
    puts "%6d (%5.2f%%): %s" % [v, v / pct, k]
  end
  puts

  puts "%6d: %s" % [total, "Total"]
end