Show render time on pages


#1

hello all!
is it possible to access the render time variables in the view? i would
like to show

Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK
[http://localhost/person]

on each page like in the logs.

how can i do this?


#2

Simon S. wrote:

hello all!
is it possible to access the render time variables in the view? i would
like to show

Completed in 0.09574 (10 reqs/sec) | DB: 0.08729 (91%) | 200 OK
[http://localhost/person]

on each page like in the logs.

how can i do this?
If render time can only access in a controller, Try setting up a message
in
controller then. Moreover, you can use flash variable to do the job
since
you want the message to appear every page :),

Tom


#3

Anocha Yimsiriwattana wrote:

If render time can only access in a controller, Try setting up a message in
controller then.

I don’t know if it is accessible in the controller. I don’t know where
to look for them…

Moreover, you can use flash variable to do the job since
you want the message to appear every page :),

Oh well. Once I get to them, displaying them will be the last of th
problems :slight_smile:


#4

Simon S. wrote:

Oh well. Once I get to them, displaying them will be the last of th
problems :slight_smile:
Arr … I thought you know how to access it in controller, my bad. I was
going to ask you how to do that too :stuck_out_tongue:


#5

By definition, if you can see the page, you got a 200 response so that’s
very possibly not what you want. If render time is what you’re after, an
approximate way to capture that is:

RAILS_ROOT/app/views/layouts/application.rb

<%= @content_for_layout %>
<%= sprintf(’%f’, (Time.now.usec - @start_time.usec).to_f / 1000000) %>

RAILS_ROOT/app/views/layouts/controller_to_time.rb

def initialize
	@start_time = Time.now;
	super
end

Naturally, a better way to do this would be to actually change
ApplicationController on the fly so this initialize code happens all the
time.

Regarding DB, that’s kind of up to you, but a similar technique in
ActiveRecord would work.

By the way, Windows does not render the time to anywhere near the amount
of
precision *nix does.

Hope this helps.