Class: Rack::RubyProf
- Inherits:
-
Object
- Object
- Rack::RubyProf
- Defined in:
- lib/ruby-prof/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RubyProf
constructor
A new instance of RubyProf.
- #print(data) ⇒ Object
Constructor Details
#initialize(app) ⇒ RubyProf
Returns a new instance of RubyProf.
5 6 7 |
# File 'lib/ruby-prof/rack.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ruby-prof/rack.rb', line 9 def call(env) ::RubyProf.start result = @app.call(env) data = ::RubyProf.stop print(data) result end |
#print(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby-prof/rack.rb', line 18 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 |