| 1 | ############################################################################ | ||
| 2 | # | ||
| 3 | # Win32::ASP::Profile - provides quick and dirty profiling for web performance | ||
| 4 | # testing in the Win32-ASP-DB system | ||
| 5 | # | ||
| 6 | # Author: Toby Everett | ||
| 7 | # Revision: 0.02 | ||
| 8 | # Last Change: | ||
| 9 | ############################################################################ | ||
| 10 | # Copyright 1999, 2000 Toby Everett. All rights reserved. | ||
| 11 | # | ||
| 12 | # This file is distributed under the Artistic License. See | ||
| 13 | # http://www.ActiveState.com/corporate/artistic_license.htm or | ||
| 14 | # the license that comes with your perl distribution. | ||
| 15 | # | ||
| 16 | # For comments, questions, bugs or general interest, feel free to | ||
| 17 | # contact Toby Everett at teverett@alascom.att.com | ||
| 18 | ############################################################################ | ||
| 19 | |||
| 20 | use Benchmark; | ||
| 21 | |||
| 22 | package Win32::ASP::Profile; | ||
| 23 | |||
| 24 | use strict; | ||
| 25 | |||
| 26 | =head1 NAME | ||
| 27 | |||
| 28 | Win32::ASP::Profile - provides quick and dirty profiling for web performance testing | ||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | use Win32::ASP::Profile; | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | C<Win32::ASP::Profile> outputs rudimentary profiling information at the end of each web page | ||
| 37 | through the use of C<BEGIN> and C<END>. The C<BEGIN> subroutine initializes some information when | ||
| 38 | the web page is first created and the C<END> subroutine computes the time it took for the web page | ||
| 39 | to be create and appends that to the end of the web page. | ||
| 40 | |||
| 41 | To use, simply include the line | ||
| 42 | |||
| 43 | use Win32::ASP::Profile; | ||
| 44 | |||
| 45 | on any web page you want to profile. If you are using a default C<*.INC> file, you can stick that | ||
| 46 | line in the include file and thus garner profiling information on all your ASP pages. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | sub BEGIN { | ||
| 51 | $Win32::ASP::Profile::start = Benchmark->new; | ||
| 52 | $Win32::ASP::Profile::start_tick = Win32::GetTickCount(); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub END { | ||
| 56 | my $end = Benchmark->new; | ||
| 57 | my $end_tick = Win32::GetTickCount(); | ||
| 58 | |||
| 59 | my $delta = Benchmark::timediff($end, $Win32::ASP::Profile::start); | ||
| 60 | my $deltastr = Benchmark::timestr($delta); | ||
| 61 | $deltastr =~ s/\s+\d+//; | ||
| 62 | $deltastr = sprintf("%0.2f", ($end_tick - $Win32::ASP::Profile::start_tick)/1000).$deltastr; | ||
| 63 | |||
| 64 | $main::Response->Write("<HR>$deltastr"); | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; |