Module: TestProf::TagProf::Printers::Simple

Extended by:
Logging
Defined in:
lib/test_prof/tag_prof/printers/simple.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

.dump(result) ⇒ 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/test_prof/tag_prof/printers/simple.rb', line 12

def dump(result)
  msgs = []

  msgs <<
    <<~MSG
      TagProf report for #{result.tag}
    MSG

  header = []

  header << format(
    '%15s  %12s  ',
    result.tag, 'time'
  )

  events_format = nil

  unless result.events.empty?
    events_format = result.events.map { |event| "%#{event.size + 2}s  " }.join

    header << format(
      events_format,
      *result.events
    )
  end

  header << format(
    '%6s  %6s  %6s  %12s',
    'total', '%total', '%time', 'avg'
  )

  msgs << header.join

  msgs << ""

  total = result.data.values.inject(0) { |acc, v| acc + v[:count] }
  total_time = result.data.values.inject(0) { |acc, v| acc + v[:time] }

  result.data.values.sort_by { |v| -v[:time] }.each do |tag|
    line = []
    line << format(
      "%15s  %12s  ",
      tag[:value], tag[:time].duration
    )

    unless result.events.empty?
      line << format(
        events_format,
        *result.events.map { |event| tag[event].duration }
      )
    end

    line << format(
      "%6d  %6.2f  %6.2f  %12s",
      tag[:count],
      100 * tag[:count].to_f / total,
      100 * tag[:time] / total_time,
      (tag[:time] / tag[:count]).duration
    )

    msgs << line.join
  end

  log :info, msgs.join("\n")
end