Module: TestProf::FactoryProf::Printers::Flamegraph

Extended by:
Logging
Defined in:
lib/test_prof/factory_prof/printers/flamegraph.rb

Overview

:nodoc: all

Constant Summary

Constants included from Logging

Logging::COLORS

Class Method Summary collapse

Methods included from Logging

build_log_msg, colorize, log

Class Method Details

.convert_stacks(result) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/test_prof/factory_prof/printers/flamegraph.rb', line 25

def convert_stacks(result)
  res = []

  paths = {}

  result.stacks.each do |stack|
    parent = nil
    path = ""

    stack.each do |sample|
      path = "#{path}/#{sample}"

      if paths[path]
        node = paths[path]
        node[:value] += 1
      else
        node = { name: sample, value: 1, total: result.raw_stats.fetch(sample)[:total] }
        paths[path] = node

        if parent.nil?
          res << node
        else
          parent[:children] ||= []
          parent[:children] << node
        end
      end

      parent = node
    end
  end

  res
end

.dump(result) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/test_prof/factory_prof/printers/flamegraph.rb', line 11

def dump(result)
  return log(:info, "No factories detected") if result.raw_stats == {}
  report_data = {
    total_stacks: result.stacks.size,
    total: result.total
  }

  report_data[:roots] = convert_stacks(result)

  path = generate_html(report_data)

  log :info, "FactoryFlame report generated: #{path}"
end