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
Class Method Summary collapse
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .profile(locked: false) ⇒ Object
-
.run ⇒ Object
Run RubyProf and automatically dump a report when the process exits.
Methods included from Logging
Class Method Details
.config ⇒ Object
161 162 163 |
# File 'lib/test_prof/ruby_prof.rb', line 161 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
165 166 167 |
# File 'lib/test_prof/ruby_prof.rb', line 165 def configure yield config end |
.profile(locked: false) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/test_prof/ruby_prof.rb', line 183 def profile(locked: false) if locked? log :warn, <<~MSG RubyProf is activated globally, you cannot generate per-example report. Make sure you haven not set the TEST_RUBY_PROF environmental variable. MSG return end return unless init_ruby_prof = {} [:include_threads] = [Thread.current] unless config.include_threads? [:measure_mode] = config.ruby_prof_mode profiler = ::RubyProf::Profile.new() 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 @locked = true if locked Report.new(profiler) end |
.run ⇒ Object
Run RubyProf and automatically dump a report when the process exits.
Use this method to profile the whole run.
173 174 175 176 177 178 179 180 181 |
# File 'lib/test_prof/ruby_prof.rb', line 173 def run report = profile(locked: true) return unless report log :info, "RubyProf enabled globally" at_exit { report.dump("total") } end |