1# $Id: /mirror/gungho/lib/Gungho/Plugin/RequestTimer.pm 3779 2007-10-23T15:39:50.115570Z lestrrat $ 2# 3# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> 4# All rights reserved. 5 6package Gungho::Plugin::RequestTimer; 7use strict; 8use warnings; 9use base qw(Gungho::Plugin); 10 11__PACKAGE__->mk_accessors($_) for qw(verbose); 12 13BEGIN 14{ 15 warn "Gungho::Plugin::RequestTimer has been deprecated, use Gungho::Plugin::RequestLog"; 16 eval { Time::HiRes->require }; 17 if (! $@) { 18 Time::HiRes->import(qw(time)); 19 } 20} 21 22sub setup 23{ 24 my ($self, $c) = @_; 25 26 $self->verbose( 27 exists $self->config->{verbose} ? $self->config->{verbose} : 1 28 ); 29 30 $c->register_hook( 31 'engine.send_request' => sub { $self->log_start(@_) }, 32 'engine.handle_response' => sub { $self->log_stop(@_) }, 33 ); 34} 35 36sub log_start 37{ 38 my ($self, $c, $args) = @_; 39 40 my $request = $args->{request}; 41 $request->notes('send_request_time' => time()); 42} 43 44sub log_stop 45{ 46 my ($self, $c, $args) = @_; 47 48 my $request = $args->{request}; 49 50 $request->notes('handle_response_time' => time()); 51 $request->notes('total_request_time' => $request->notes('handle_response_time') - $request->notes('send_request_time') ); 52 53 if ($self->verbose) { 54 $c->log->info("RequestTimer: logging end for request " . $request->uri . " = " . $request->notes('total_request_time') . " seconds"); 55 } 56} 57 581; 59 60__END__ 61 62=head1 NAME 63 64Gungho::Plugin::RequestTimer - Keep Track Of Time To Finish Request 65 66=head1 SYNOPSIS 67 68 plugins: 69 - 70 module: RequestTimer 71 config: 72 verbose: 0 # optional 73 74=head1 DESCRIPTION 75 76NOTICE This module has been deprecated. Please use RequestLog instead. 77 78Gungho::Plugin::RequestTimer allows you to keep track of the time it took to 79finish fetching a particular request. The time when the request started, 80the time when the request was handed to handle_response(), and the total 81time between the latter two points are stored under the request object's 82notes() slot. 83 84 $request->notes('send_request_time'); 85 $request->notes('handle_response_time'); 86 $request->notes('total_request_time'); 87 88Note that these values may not correspond exactly to when the acutal HTTP 89transaction started/finished, but rather, it's just a hook to show when 90these particular events happened in Gungho's life cycle. 91 92If you have Time::HiRes in your system, Time::HiRes::time() is used over 93regular time() as the store time values. 94 95=head1 METHODS 96 97=head2 setup() 98 99Sets up the plugin. 100 101=head2 log_start() 102 103Starts logging 104 105=head2 log_stop() 106 107Ends logging 108 109=head1 AUTHOR 110 111Copyright (c) 2007 Daisuke Maki E<lt>daisuke@endeworks.jpE<gt> 112 113All rights reserved. 114 115=head1 LICENSE 116 117This program is free software; you can redistribute it and/or modify it 118under the same terms as Perl itself. 119 120See http://www.perl.com/perl/misc/Artistic.html 121 122=cut