Class: Rack::Profiler

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Profiler

Accepts a :printer => [:call_stack|:call_tree|:graph_html|:graph|:flat] option defaulting to :call_stack.



31
32
33
34
35
# File 'lib/rack/contrib/profiler.rb', line 31

def initialize(app, options = {})
  @app = app
  @printer = parse_printer(options[:printer] || DEFAULT_PRINTER)
  @times = (options[:times] || 1).to_i
end

Instance Method Details

#call(env) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rack/contrib/profiler.rb', line 37

def call(env)
  if mode = profiling?(env)
    profile(env, mode)
  else
    @app.call(env)
  end
end