Reputation: 267140
Page load time, when in RoR lifecycle do you start/stop a timer to get this stat?
I know I can create a before/after at the controller level, is there anything higher up in the chain that I get start/stop this timer?
I want to get timings for a production release also, not just development mode where things are always slower.
Upvotes: 0
Views: 657
Reputation: 621
i did something like Ryan Bates in episode 151 as aforementioned
require 'rack/utils'
class ResponseTimer
def initialize(app, message = "Response Time")
@app = app
@message = message
end
def call(env)
dup._call(env)
end
def _call(env)
@start = Time.now
@status, @headers, @response = @app.call(env)
@stop = Time.now
[@status, @headers, self]
end
def each(&block)
block.call("<!-- #{@message}: #{@stop - @start} -->\n") if @headers["Content-Type"].include? "text/html"
@response.each(&block)
end
end
but it doesn't take into account external javascript/css loading time
= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
Upvotes: 0
Reputation: 176
If I were trying to get the most complete picture of my response time I'd use something like NewRelic's RPM, or build something not unlike the example here http://asciicasts.com/episodes/151-rack-middleware
By having it track it in the middleware you're getting most (if not all) of the Rails stack in the metric instead of just the controller call. Also you can use it for other things like Sinatra apps. :)
Upvotes: 3