You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ed Park <ep...@athenahealth.com> on 2000/12/14 18:10:44 UTC

showing mod_perl execute time in access_log

quick, obvious trick:
This is a trivial modification of Doug's original Apache::TimeIt script that
allows you to very precisely show the Apache execute time of the page.

This is particularly useful if you want to know which pages of your site you
could optimize.

Here's a question, though: does anyone know an easy way of measuring how
long apache keeps a socket to the client open, assuming that KeepAlive has
been turned off? This is relevant because I want to know how long on average
it is taking clients to receive certain pages in my application. I know that
I can approximately calculate it from bandwidth, but I would expect the
actual number to vary wildly throughout a given day due to Internet
congestion.

cheers,
Ed

---
package AccessTimer;

# USAGE:
# Just put the following line into your .conf file:
#
# PerlFixupHandler AccessTimer
#
# and use a custom Apache log (this logging piece is not at all
mod_perl-based...
# see http://httpd.apache.org/docs/mod/mod_log_config.html)
#
# CustomLog /path/to/your/log "%h %l %u %t \"%r\" %>s %b %{ELAPSED}e"
#

use strict;
use Apache::Constants qw(:common);
use Time::HiRes qw(gettimeofday tv_interval);
use vars qw($begin);

sub handler {
    my $r = shift;

    $begin = [gettimeofday];
    $r->push_handlers(PerlLogHandler=>\&log);

    return OK;
}

sub log {
    my $r = shift;

    my $elapsed = tv_interval($begin);
    $r->subprocess_env('ELAPSED' => "$elapsed");
    return DECLINED;
}

1;