Sha256: 35f376686bf55fd3b1f5e7c6a9d1510d6eb8d93cfb5dce0e21fa52275c4240c3

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

require 'tmpdir'

module Rack
  class RubyProf
    def initialize(app)
      @app = app
    end

    def call(env)
      ::RubyProf.start
      result = @app.call(env)
      data = ::RubyProf.stop

      print(data)
      result
    end

    def print(data)
      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
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ruby-prof-0.10.2 lib/ruby-prof/rack.rb
acunote-ruby-prof-0.9.2 lib/ruby-prof/rack.rb