module TestProf::EventProf

EventProf profiles your tests and suites against custom events, such as ActiveSupport::Notifacations.

It works very similar to `rspec –profile` but can track arbitrary events.

Example:

# Collect SQL queries stats for every suite and example
EVENT_PROF='sql.active_record' rspec ...

By default it collects information only about top-level groups (aka suites), but you can also profile individual examples. Just set the configuration option:

TestProf::EventProf.configure do |config|
  config.per_example = true
end

Or provide the EVENT_PROF_EXAMPLES=1 env variable.

Public Class Methods

build(event = config.event) click to toggle source

Returns new configured instance of profilers group

# File lib/test_prof/event_prof.rb, line 78
def build(event = config.event)
  ProfilersGroup.new(
    event: event,
    instrumenter: instrumenter,
    rank_by: config.rank_by,
    top_count: config.top_count,
    per_example: config.per_example?
  )
end
config() click to toggle source
# File lib/test_prof/event_prof.rb, line 69
def config
  @config ||= Configuration.new
end
configure() { |config| ... } click to toggle source
# File lib/test_prof/event_prof.rb, line 73
def configure
  yield config
end
instrumenter() click to toggle source
# File lib/test_prof/event_prof.rb, line 88
def instrumenter
  @instrumenter ||= config.resolve_instrumenter
end
monitor(mod, event, *mids, **kwargs) click to toggle source

Instrument specified module methods. Wraps them with `instrumenter.instrument(event) { … }`.

Use it to profile arbitrary methods:

TestProf::EventProf.monitor(MyModule, "my_module.call", :call)
# File lib/test_prof/event_prof.rb, line 98
def monitor(mod, event, *mids, **kwargs)
  Monitor.call(mod, event, *mids, **kwargs)
end