WWW::Mechanize::Timed - Time Mechanize requests


WWW-Mechanize-Timed documentation Contained in the WWW-Mechanize-Timed distribution.

Index


Code Index:

NAME

Top

WWW::Mechanize::Timed - Time Mechanize requests

SYNOPSIS

Top

  use WWW::Mechanize::Timed;
  my $ua = WWW::Mechanize::Timed->new();
  $ua->get($url);
  print "Total time: " . $ua->client_total_time . "\n";
  print "Elapsed time: " . $ua->client_elapsed_time . "\n";

DESCRIPTION

Top

This module is a subclass of WWW::Mechanize that times each stage of the HTTP request. These can then be used in monitoring systems.

CONSTRUCTOR

Top

new

The constructor is provided by WWW::Mechnize. See that module's documentation for details.

METHODS

Top

The vast majority of methods are provided by WWW::Mechanize. See that module's documentation for details. Additional methods provided by this module follow. The most useful method is client_response_receive_time, or how long it took to get the data from the webserver once the response was made (and gives an idea of how loaded the webserver was). All times are in seconds.

client_request_connect_time

The time it took to connect to the remote server.

client_request_transmit_time

The time it took to transmit the request.

client_response_server_time

Time it took to respond to the request.

client_response_receive_time

Time it took to get the data back.

client_total_time

Total time taken for each of the 4 stages above.

client_elapsed_time

Total time taken to make the WWW::Mechanize::get request, as perceived by the calling program.

get

Use this method to request a page:

  $ua->get($url);

THANKS

Top

Andy Lester for WWW::Mechanize. Simon Wistow for LWPx::TimedHTTP.

LICENCE AND COPYRIGHT

Top

AUTHOR

Top

Leon Brocard <acme@astray.com>.

SEE ALSO

Top

WWW::Mechanize.


WWW-Mechanize-Timed documentation Contained in the WWW-Mechanize-Timed distribution.

package WWW::Mechanize::Timed;
use strict;
use warnings FATAL => 'all';
use base qw( WWW::Mechanize );
use LWPx::TimedHTTP qw(:autoinstall);
use Time::HiRes;
our $VERSION = '0.44';

sub new {
    my $class = shift;
    my %args  = @_;
    my $self  = $class->SUPER::new(%args);
    $self->{client_elapsed_time} = 0;
    return $self;
}

sub get {
    my $self     = shift;
    my $start    = Time::HiRes::gettimeofday();
    my $response = $self->SUPER::get(@_);
    $self->{client_elapsed_time} = Time::HiRes::gettimeofday() - $start;
    return $response;
}

sub client_elapsed_time {
    my $self = shift;
    return $self->{client_elapsed_time};
}

sub client_request_connect_time {
    my $self = shift;
    return $self->response->header('Client-Request-Connect-Time');
}

sub client_request_transmit_time {
    my $self = shift;
    return $self->response->header('Client-Request-Transmit-Time');
}

sub client_response_server_time {
    my $self = shift;
    return $self->response->header('Client-Response-Server-Time');
}

sub client_response_receive_time {
    my $self = shift;
    return $self->response->header('Client-Response-Receive-Time');
}

sub client_total_time {
    my $self = shift;
    return $self->client_request_connect_time
        + $self->client_request_transmit_time
        + $self->client_response_server_time
        + $self->client_response_receive_time;
}

1;

__END__