Module: TestProf::EventProf

Defined in:
lib/test_prof/event_prof.rb,
lib/test_prof/event_prof/rspec.rb,
lib/test_prof/event_prof/monitor.rb,
lib/test_prof/event_prof/profiler.rb,
lib/test_prof/event_prof/custom_events.rb,
lib/test_prof/event_prof/printers/base.rb,
lib/test_prof/event_prof/printers/json.rb,
lib/test_prof/event_prof/printers/simple.rb,
lib/test_prof/event_prof/instrumentations/active_support.rb

Overview

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

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.

Defined Under Namespace

Modules: CustomEvents, Instrumentations, Monitor, Printers Classes: Configuration, Profiler, ProfilersGroup, RSpecListener

Class Method Summary collapse

Class Method Details

.build(event = config.event) ⇒ Object

Returns new configured instance of profilers group



89
90
91
92
93
94
95
96
97
# File 'lib/test_prof/event_prof.rb', line 89

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 ⇒ Object



80
81
82
# File 'lib/test_prof/event_prof.rb', line 80

def config
  @config ||= Configuration.new
end

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

Yields:



84
85
86
# File 'lib/test_prof/event_prof.rb', line 84

def configure
  yield config
end

.instrumenter ⇒ Object



99
100
101
# File 'lib/test_prof/event_prof.rb', line 99

def instrumenter
  @instrumenter ||= config.resolve_instrumenter
end

.monitor(mod, event, *mids, **kwargs) ⇒ Object

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

Use it to profile arbitrary methods:

TestProf::EventProf.monitor(MyModule, "my_module.call", :call)


109
110
111
# File 'lib/test_prof/event_prof.rb', line 109

def monitor(mod, event, *mids, **kwargs)
  Monitor.call(mod, event, *mids, **kwargs)
end