# Blosxom v3 Plugin: rendertime # Author(s): Eric Davis # $Id: RenderTime.pm,v 3.1 2004/05/28 16:35:56 edavis Exp $ # Documentation: See the bottom of this file or type: perldoc rendertime package Blosxom::Plugin::RenderTime; # --- Configurable variables ----- # do you want to log render times to a file my $logToFile = 1; my $logFile = "rendertime.dat"; # -------------------------------- # this code was taken directly from the perl faq require 'sys/syscall.ph'; my $TIMEVAL_T = "LL"; my $startTime = pack($TIMEVAL_T, ()); my $endTime = pack($TIMEVAL_T, ()); sub Start { syscall(&SYS_gettimeofday, $startTime, 0) != -1 or die "gettimeofday: $!"; return 1; } sub Stop { my $blosxom = shift; syscall(&SYS_gettimeofday, $endTime, 0) != -1 or die "gettimeofday: $!"; @start = unpack($TIMEVAL_T, $startTime); @end = unpack($TIMEVAL_T, $endTime); for ($end[1], $start[1]) { $_ /= 1_000_000 } $time = sprintf "%.4f", ($end[0] + $end[1]) - ($start[0] + $start[1]); if ($logToFile) { my $realLogFile = "$blosxom->{settings}->{state_dir}/$logFile"; open(LOG, "+>>$realLogFile") or die "cannot write to file: $!."; print LOG "$ENV{'REQUEST_URI'} ($time)\n"; close(LOG); } else { warn "$ENV{'REQUEST_URI'} ($time)\n"; } return 1; } 1; __END__ =head1 NAME Blosxom v3 Plugin: rendertime =head1 USAGE To run this plugin simply drop this file into your Blosxom plugin directory and add B<$Plugin::RenderTime::Start> somewhere near the beginning of your B file and B<$Plugin::RenderTime::Stop> somewhere near the end of you B file. Then for each request this plugin will print a line to the log file showing the time, in seconds (x.xxxx), it took to render the page. If B<$logToFile> is set to 0 then this plugin will print the render time to the web server error log. If you don't want the render time log file located in the plugin state directory then change B<$logFile> accordingly. This plugin requires the B system call. =head1 VERSION 3.1 ported for use with Blosxom 3 =head1 VERSION HISTORY 3.1 ported for use with Blosxom 3 =head1 AUTHORS Eric Davis http://www.foobargeek.com =head1 LICENSE This source is submitted to the public domain. Feel free to use and modify it. If you like, a comment in your modified source attributing credit for my original work would be appreciated. THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND. USE AT YOUR OWN RISK!