Class: Memtf::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/memtf/reporter.rb

Overview

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    |
...

Constant Summary collapse

HEADERS =

The report table headers

['Class', 'Impact', 'Leakage', 'Change', 'Objects', 'Change']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, options = {}) ⇒ Reporter

Returns a new instance of Reporter.



26
27
28
29
# File 'lib/memtf/reporter.rb', line 26

def initialize(group, options={})
  @group   = group
  @options = options
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



17
18
19
# File 'lib/memtf/reporter.rb', line 17

def group
  @group
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/memtf/reporter.rb', line 17

def options
  @options
end

Class Method Details

.report(group) ⇒ Object

Print the analysis in a concise tabular format.

Parameters:

  • group (String)


22
23
24
# File 'lib/memtf/reporter.rb', line 22

def self.report(group)
  new(group).report
end

Instance Method Details

#reportTerminal::Table

Print the analysis in a concise tabular format.

Returns:

  • (Terminal::Table)


34
35
36
37
38
39
40
41
42
43
44
45
46
# 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