Module: TestProf::StackProf
- Extended by:
- Logging
- Defined in:
- lib/test_prof/stack_prof.rb,
lib/test_prof/stack_prof/rspec.rb
Overview
StackProf wrapper.
Has 2 modes: global and per-example.
Example:
# To activate global profiling you can use env variable
TEST_STACK_PROF=1 rspec ...
# or in your code
TestProf::StackProf.run
To profile a specific examples add :sprof tag to it:
it "is doing heavy stuff", :sprof do
...
end
Defined Under Namespace
Classes: Configuration, Listener
Constant Summary
Constants included from Logging
Class Method Summary collapse
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .dump(name) ⇒ Object
- .profile(name = nil) ⇒ Object
-
.run ⇒ Object
Run StackProf and automatically dump a report when the process exits or when the application is booted.
Methods included from Logging
Class Method Details
.config ⇒ Object
60 61 62 |
# File 'lib/test_prof/stack_prof.rb', line 60 def config @config ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
64 65 66 |
# File 'lib/test_prof/stack_prof.rb', line 64 def configure yield config end |
.dump(name) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/test_prof/stack_prof.rb', line 110 def dump(name) ::StackProf.stop path = build_path(name) ::StackProf.results(path) log :info, "StackProf report generated: #{path}" return unless config.raw send("dump_#{config.format}_report", path) end |
.profile(name = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/test_prof/stack_prof.rb', line 81 def profile(name = nil) if locked? log :warn, " StackProf has been already activated.\n\n Make sure you have not set the TEST_STACK_PROF environmental variable.\n MSG\n return false\n end\n\n return false unless init_stack_prof\n\n options = {\n mode: config.mode,\n raw: config.raw\n }\n\n options[:interval] = config.interval if config.interval\n options[:ignore_gc] = true if config.ignore_gc\n\n if block_given?\n options[:out] = build_path(name)\n ::StackProf.run(**options) { yield }\n else\n ::StackProf.start(**options)\n end\n true\nend\n" |
.run ⇒ Object
Run StackProf and automatically dump a report when the process exits or when the application is booted.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/test_prof/stack_prof.rb', line 70 def run return unless profile @locked = true log :info, "StackProf#{config.raw? ? " (raw)" : ""} enabled globally: " \ "mode – #{config.mode}, target – #{config.target}" at_exit { dump("total") } if config.suite? end |