Class | Merb::Rack::Profiler |
In: |
merb-core/lib/merb-core/rack/middleware/profiler.rb
|
Parent: | Merb::Rack::Middleware |
:api: private
# File merb-core/lib/merb-core/rack/middleware/profiler.rb, line 12 12: def initialize(app, types = [RubyProf::ALLOCATIONS, RubyProf::PROCESS_TIME]) 13: super(app) 14: @types = types 15: end
:api: plugin
# File merb-core/lib/merb-core/rack/middleware/profiler.rb, line 18 18: def call(env) 19: measure_names = { RubyProf::ALLOCATIONS => 'allocations', 20: RubyProf::PROCESS_TIME => 'time', RubyProf::MEMORY => "memory" } 21: 22: ret = nil 23: 24: GC.disable 25: @types.each do |type| 26: next if type.nil? 27: 28: if GC.respond_to?(:enable_stats) 29: GC.enable_stats || GC.clear_stats 30: end 31: 32: RubyProf.measure_mode = type 33: RubyProf.start 34: 100.times do 35: ret = super 36: end 37: result = RubyProf.stop 38: printer = RubyProf::CallTreePrinter.new(result) 39: path = "merb_profile_results" / env["PATH_INFO"] 40: FileUtils.mkdir_p(path) 41: printer.print( 42: File.open( 43: "#{path}/callgrind.out.#{measure_names[RubyProf::measure_mode]}", 44: 'w')) 45: 46: GC.disable_stats if GC.respond_to?(:disable_stats) 47: end 48: GC.enable 49: ret 50: end