class Memtf::Reporter

Encapsulates the formatting and output of Memtf analysis.

Example Report:

+-----------------------------+--------+---------+---------+---------+---------+
| Class                       | Impact | Leakage | Change  | Objects | Change  |
+-----------------------------+--------+---------+---------+---------+---------+
| Array                       | 96.85% | 4.972MB | 4.972MB | 2189    | 1985    |
...

Constants

HEADERS

The report table headers

Attributes

group[R]
options[R]

Public Class Methods

new(group, options={}) click to toggle source
# File lib/memtf/reporter.rb, line 26
def initialize(group, options={})
  @group   = group
  @options = options
end
report(group) click to toggle source

Print the analysis in a concise tabular format.

@param [String] group

# File lib/memtf/reporter.rb, line 22
def self.report(group)
  new(group).report
end

Public Instance Methods

report() click to toggle source

Print the analysis in a concise tabular format.

@return [Terminal::Table]

# File lib/memtf/reporter.rb, line 34
def report
  Terminal::Table.new(:headings => HEADERS) do |t|
    group_analysis = Memtf::Analyzer.analyze_group(group)
    group_analysis.sort_by { |k,v| -v['impact'] }.each do |k,v|
      t << [k,
            to_pct(v['impact']),
            to_MB(v['size']),
            to_MB(v['size_delta']),
            v['count'],
            v['count_delta']]
    end
  end
end

Private Instance Methods

to_MB(bytes) click to toggle source

@param [Number] bytes

# File lib/memtf/reporter.rb, line 51
def to_MB(bytes)
  "%.3fMB" % [bytes]
end
to_pct(num) click to toggle source

@param [Number] num

# File lib/memtf/reporter.rb, line 56
def to_pct(num)
  "%.2f%" % [num * 100]
end