Module: TestProf::FactoryProf::Printers::Simple

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

Overview

:nodoc: all

Constant Summary

Constants included from Logging

Logging::COLORS

Class Method Summary collapse

Methods included from Logging

log

Class Method Details

.dump(result, start_time:, threshold:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
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
# File 'lib/test_prof/factory_prof/printers/simple.rb', line 12

def dump(result, start_time:, threshold:)
  return log(:info, "No factories detected") if result.raw_stats == {}
  msgs = []

  total_run_time = TestProf.now - start_time
  total_count = result.stats.sum { |stat| stat[:total_count] }
  total_top_level_count = result.stats.sum { |stat| stat[:top_level_count] }
  total_time = result.stats.sum { |stat| stat[:top_level_time] }
  total_uniq_factories = result.stats.map { |stat| stat[:name] }.uniq.count

  msgs <<
    "      Factories usage\n\n       Total: \#{total_count}\n       Total top-level: \#{total_top_level_count}\n       Total time: \#{total_time.duration} (out of \#{total_run_time.duration})\n       Total uniq factories: \#{total_uniq_factories}\n\n         name                    total   top-level     total time      time per call      top-level time\n    MSG\n\n  result.stats.each do |stat|\n    next if stat[:total_count] < threshold\n\n    msgs << format(\"%-3s%-20s %8d %11d %13.4fs %17.4fs %18.4fs\", *format_args(stat))\n    # move other variation (\"[...]\") to the end of the array\n    sorted_variations = stat[:variations].sort_by.with_index do |variation, i|\n      (variation[:name] == \"[...]\") ? stat[:variations].size + 1 : i\n    end\n    sorted_variations.each do |variation_stat|\n      next if variation_stat[:total_count] < threshold\n\n      msgs << format(\"%-5s%-18s %8d %11d %13.4fs %17.4fs %18.4fs\", *format_args(variation_stat))\n    end\n  end\n\n  log :info, msgs.join(\"\\n\")\nend\n"