Created
April 22, 2013 07:14
-
-
Save andreas/5432990 to your computer and use it in GitHub Desktop.
Revisions
-
Andreas created this gist
Apr 22, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ class RBLineProfiler WALL_TIME_LIMIT = 10e3 # ms def initialize(app) @app = app end def call(env) result = nil profile = lineprof(/./) { result = @app.call(env) } profile.each do |file, line_samples| file_lines = nil line_samples.each_with_index do |(wall_time, calls), num| if wall_time > WALL_TIME_LIMIT if !file_lines file_lines = File.readlines(file) puts file end printf "% 8.1fms | %s", wall_time/1000.0, file_lines[num-1] end end end result end end # Add to config/application.rb config.middleware.use RBLineProfiler