Module: TestProf::Vernier

Extended by:
Logging
Defined in:
lib/test_prof/vernier.rb,
lib/test_prof/vernier/rspec.rb

Overview

Vernier wrapper.

Has 2 modes: global and per-example.

Example:

# To activate global profiling you can use env variable
TEST_VERNIER=1 rspec ...

To profile a specific examples add :vernier tag to it:

it "is doing heavy stuff", :vernier do
  ...
end

Defined Under Namespace

Classes: Configuration, Listener

Constant Summary

Constants included from Logging

Logging::COLORS

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Logging

log

Class Attribute Details

.default_collectorObject (readonly)

Returns the value of attribute default_collector.



52
53
54
# File 'lib/test_prof/vernier.rb', line 52

def default_collector
  @default_collector
end

Class Method Details

.configObject



44
45
46
# File 'lib/test_prof/vernier.rb', line 44

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



48
49
50
# File 'lib/test_prof/vernier.rb', line 48

def configure
  yield config
end

.dump(collector, name) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/test_prof/vernier.rb', line 98

def dump(collector, name)
  result = collector.stop

  path = build_path(name)

  File.write(path, ::Vernier::Output::Firefox.new(result).output)

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

.profile(name = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/test_prof/vernier.rb', line 69

def profile(name = nil)
  if locked?
    log :warn, <<~MSG
      Vernier has been already activated.

      Make sure you do not have the TEST_VERNIER environmental variable set somewhere.
    MSG

    return false
  end

  return false unless init_vernier

  options = {}

  options[:interval] = config.interval if config.interval

  if block_given?
    options[:mode] = config.mode
    options[:out] = build_path(name)
    ::Vernier.trace(**options) { yield }
  else
    collector = ::Vernier::Collector.new(config.mode, **options)
    collector.start

    collector
  end
end

.runObject

Run Vernier and automatically dump a report when the process exits or when the application is booted.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/test_prof/vernier.rb', line 56

def run
  collector = profile
  return unless collector

  @locked = true
  @default_collector = collector

  log :info, "Vernier enabled globally: " \
             "mode – #{config.mode}, target – #{config.target}"

  at_exit { dump(collector, "total") } if config.suite?
end