Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Here's how I get CPU times:
    package Stonehenge::Timeit;
    use strict;

    ## usage: PerlInitHandler Stonehenge::Timeit;

    use vars qw($VERSION);
    $VERSION = (qw$Revision: 1.1.1.1 $ )[-1];

    use Apache::Constants qw(OK DECLINED);
    use Apache::File;
    use Apache::Log;

    sub handler {
      ## use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;

      my $r = shift;
      return DECLINED unless $r->is_initial_req;
      my $log = $r->log;        # closure
      my $uri = $r->uri;        # closure

      my @times = (time, times);    # closure

      $r->register_cleanup
        (sub {
           $log->notice(sprintf "%s times: real %d user %.2f sys %.2f",
                $uri, (map { $_ - shift @times } time, times)[0,1,2]);
           return OK;
         });

      return DECLINED;
    }
    1;
    --
    • Randal L. Schwartz
    • Stonehenge