Skip to content

Instantly share code, notes, and snippets.

@andreas
Created April 22, 2013 07:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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