Skip to content

Instantly share code, notes, and snippets.

@andreas andreas/gist:5432990
Created Apr 22, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.