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.

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.



22
23
24
25
26
# File 'lib/rack/contrib/profiler.rb', line 22

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



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

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