Class: Rack::Profiler
- Inherits:
-
Object
- Object
- Rack::Profiler
- Defined in:
- lib/rack/contrib/profiler.rb
Overview
Set the profile=process_time query parameter to download a calltree profile of the request.
Pass the :printer option to pick a different result format. Note that some printers (such as CallTreePrinter) have broken the ‘AbstractPrinter` API, and thus will not work. Bug reports to `ruby-prof`, please, not us.
You can cause every request to be run multiple times by passing the ‘:times` option to the `use Rack::Profiler` call. You can also run a given request multiple times, by setting the `profiler_runs` query parameter in the request URL.
Constant Summary collapse
- MODES =
%w(process_time wall_time cpu_time allocations memory gc_runs gc_time)
- DEFAULT_PRINTER =
:call_stack
- CONTENT_TYPES =
Hash.new('application/octet-stream').merge( 'RubyProf::FlatPrinter' => 'text/plain', 'RubyProf::GraphPrinter' => 'text/plain', 'RubyProf::GraphHtmlPrinter' => 'text/html', 'RubyProf::CallStackPrinter' => 'text/html')
Instance Attribute Summary collapse
-
#maximum_runs ⇒ Object
readonly
Returns the value of attribute maximum_runs.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Profiler
constructor
Accepts a :printer => [:call_stack|:call_tree|:graph_html|:graph|:flat] option defaulting to :call_stack.
Constructor Details
#initialize(app, options = {}) ⇒ Profiler
Accepts a :printer => [:call_stack|:call_tree|:graph_html|:graph|:flat] option defaulting to :call_stack.
33 34 35 36 37 38 39 |
# File 'lib/rack/contrib/profiler.rb', line 33 def initialize(app, = {}) @app = app @profile = nil @printer = parse_printer([:printer] || DEFAULT_PRINTER) @times = ([:times] || 1).to_i @maximum_runs = .fetch(:maximum_runs, 10) end |
Instance Attribute Details
#maximum_runs ⇒ Object (readonly)
Returns the value of attribute maximum_runs.
41 42 43 |
# File 'lib/rack/contrib/profiler.rb', line 41 def maximum_runs @maximum_runs end |
Instance Method Details
#call(env) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/rack/contrib/profiler.rb', line 43 def call(env) if mode = profiling?(env) profile(env, mode) else @app.call(env) end end |