Module: TestProf::RubyProf

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

Overview

RubyProf wrapper.

Has 2 modes: global and per-example.

Example:

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

# or in your code
TestProf::RubyProf.run

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

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

Defined Under Namespace

Modules: RSpecExclusions Classes: Configuration, Listener, Report

Constant Summary

Constants included from Logging

Logging::COLORS

Class Method Summary collapse

Methods included from Logging

build_log_msg, colorize, log

Class Method Details

.configObject



140
141
142
# File 'lib/test_prof/ruby_prof.rb', line 140

def config
  @config ||= Configuration.new
end

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

Yields:



144
145
146
# File 'lib/test_prof/ruby_prof.rb', line 144

def configure
  yield config
end

.profileObject



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/test_prof/ruby_prof.rb', line 164

def profile
  return if locked?
  return unless init_ruby_prof

  options = {
    merge_fibers: true
  }

  options[:include_threads] = [Thread.current] unless
    config.include_threads?

  profiler = ::RubyProf::Profile.new(options)
  profiler.exclude_common_methods! if config.exclude_common_methods?

  if config.test_prof_exclusions_enabled?
    # custom test-prof exclusions
    exclude_rspec_methods(profiler)

    # custom global exclusions
    exclude_common_methods(profiler)
  end

  config.custom_exclusions.each do |klass, mids|
    profiler.exclude_methods! klass, *mids
  end

  profiler.start

  Report.new(profiler)
end

.runObject

Run RubyProf and automatically dump a report when the process exits.

Use this method to profile the whole run.



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/test_prof/ruby_prof.rb', line 152

def run
  report = profile

  return unless report

  @locked = true

  log :info, "RubyProf enabled"

  at_exit { report.dump("total") }
end