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.



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

def default_collector
  @default_collector
end

Class Method Details

.configObject



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

def config
  @config ||= Configuration.new
end

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

Yields:



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

def configure
  yield config
end

.dump(collector, name) ⇒ Object



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

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



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
97
98
# File 'lib/test_prof/vernier.rb', line 70

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
  options[:hooks] = config.hooks if config.hooks

  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.



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

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