Skip to content

Instantly share code, notes, and snippets.

@andreas
Created April 22, 2013 07:14
Show Gist options
  • Save andreas/5432990 to your computer and use it in GitHub Desktop.
Save andreas/5432990 to your computer and use it in GitHub Desktop.
Use [rblineprof](https://github.com/tmm1/rblineprof) for profiling Rails apps
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment