class Rack::RubyProf

  1. lib/ruby-prof/rack.rb
Parent: Rack

Methods

Public Class

  1. new

Public Instance

  1. call
  2. print

Public Class methods

new (app)
[show source]
# File lib/ruby-prof/rack.rb, line 4
def initialize(app)
  @app = app
end

Public Instance methods

call (env)
[show source]
# File lib/ruby-prof/rack.rb, line 8
def call(env)
  ::RubyProf.start
  result = @app.call(env)
  data = ::RubyProf.stop

  print(data)
  result
end
print (data)
[show source]
# File lib/ruby-prof/rack.rb, line 17
def print(data)
  require 'tmpdir' # late require so we load on demand only
  printers = {::RubyProf::FlatPrinter => ::File.join(Dir.tmpdir, 'profile.txt'),
              ::RubyProf::GraphHtmlPrinter => ::File.join(Dir.tmpdir, 'profile.html')}

  printers.each do |printer_klass, file_name|
    printer = printer_klass.new(data)
    ::File.open(file_name, 'wb') do |file|
      printer.print(file, :min_percent => 0.00000001 )
    end
  end
end