Module: TestProf::FactoryProf::Printers::Flamegraph
- Extended by:
- Logging
- Defined in:
- lib/test_prof/factory_prof/printers/flamegraph.rb
Overview
:nodoc: all
Constant Summary collapse
- TEMPLATE =
"flamegraph.template.html"
- OUTPUT_NAME =
"factory-flame.html"
Constants included from Logging
Class Method Summary collapse
Methods included from Logging
Class Method Details
.convert_stacks(result) ⇒ Object
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 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/test_prof/factory_prof/printers/flamegraph.rb', line 32 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_count] } 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
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/test_prof/factory_prof/printers/flamegraph.rb', line 14 def dump(result, **) return log(:info, "No factories detected") if result.raw_stats == {} report_data = { total_stacks: result.stacks.size, total: result.total_count } report_data[:roots] = convert_stacks(result) path = TestProf::Utils::HTMLBuilder.generate( data: report_data, template: TEMPLATE, output: OUTPUT_NAME ) log :info, "FactoryFlame report generated: #{path}" end |