# Blosxom Plugin: rendertime # Author(s): Eric Davis # Updated to use Time::HiRes by Gustaf Erikson # Documentation: See the bottom of this file or type: perldoc rendertime package rendertime; # --- Configurable variables ----- # log render times to the web server error log (1 = yes, 0 = no) my $logToErrorLog = 0; # log render times to a file (1 = yes, 0 = no) my $logToFile = 1; # the location of the log file to write times to my $logFile = "$blosxom::plugin_state_dir/rendertime.dat"; # log the render time to the generated page (1 = yes, 0 = no) my $logToPage = 1; # the string to search for and replace with the time in the generated page my $replacement_string = "insert_rendertime_time_here"; # -------------------------------- use Time::HiRes qw(gettimeofday); my $startTime = undef; my $endTime = undef; sub start { $startTime = gettimeofday(); return 1; } sub last { return if not $logToPage; $endTime = gettimeofday(); $time = sprintf("%.4f", $endTime - $startTime); $blosxom::output =~ s/$replacement_string/$time/g; return 1; } sub end { $endTime = gettimeofday(); $time = $endTime - $startTime; if ($logToFile) { open (LOG, ">>$logFile") or die "cannot write to file: $!."; print LOG "$blosxom::url$ENV{'REQUEST_URI'} ($time)\n"; close(LOG); } warn "$blosxom::url$ENV{'REQUEST_URI'} ($time)\n" if ($logToErrorLog); return 1; } 1; __END__ =head1 NAME Blosxom Plugin: rendertime =head1 USAGE This plugin is used to figure out how long it is taking for Blosxom to render a page. Drop this file into your blosxom plugins directory and make sure it is the first plugin that will be run (i.e. rename to B<00rendertime> or something similar based on your plugin runtime priority naming scheme). Then for each request this plugin will oompute the render time and log that time to the configured location. The log times are in seconds and are of the form x.xxxx. The following configuration variables are available: B<$logToErrorLog>: log render times to the web server error log (1 = yes, 0 = no) B<$logToFile>: log render times to a file (1 = yes, 0 = no) B<$logFile>: the location of the log file to write render times to B<$logToPage>: log the render time to the generated page (1 = yes, 0 = no) B<$replacement_string>: the string to search for and replace with the render time in the generated page When the B<$logToPage> option is turned ON then a render time is computed in the B routine. The B routine is called by Blosxom before the page is sent to the client. This allows the render time to be injected into the outgoing page wherever the B<$replacement_string> is found. Therefore, this render time will not be completely accurate. Make note of whatever plugins run after this plugins in the B and B routines as these calls will not be part of the computed time. The B<$logToErrorLog> and B<$logToFile> options always compute the render time in the B routine. Therefore, these times are a bit more accurate. Also, for these two options the request URI is also logged as well. This plugin requires the B system call. =head1 VERSION 1.5 added ability to inject the render time within the page itself =head1 VERSION HISTORY 1.4 changed to run in the end routine and log entire the request URI including any query parameters 1.2 initial implementation =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!