blib/lib/MasonX/Profiler.pm

filter: Statementstmt 32.1% 9 / 28 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 40.0% 2 / 5 Podpod 0.0% 0 / 2 totaltotal 18.3% 11 / 60 CC 9 SCAR 38.2
CC
9
Cov
19%
new
72.0
DESTROY
6.0
init
2.0
CRAP 45.5
↑ Summary
1 # $File: //member/autrijus/MasonX-Profiler/lib/MasonX/Profiler.pm $ $Author: autrijus $
2 # $Revision: #9 $ $Change: 10936 $ $DateTime: 2004/06/22 14:43:01 $
3  
4 package MasonX::Profiler;
5 1 $MasonX::Profiler::VERSION = '0.06';
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 MasonX::Profiler - Mason per-component profiler
13  
14 =head1 VERSION
15  
16 This document describes version 0.06 of MasonX::Profiler, released
17 June 22, 2004.
18  
19 =head1 SYNOPSIS
20  
21 In the Mason handler:
22  
23 use MasonX::Profiler;
24 my $ah = HTML::Mason::ApacheHandler->new(
25 preamble => 'my $p = MasonX::Profiler->new($m, $r);',
26 # ...
27 );
28  
29 Note that B<CGIHandler> and B<Apache2Handler> works, too.
30  
31 Alternatively, in F<httpd.conf>, before loading your C<PerlHandler>:
32  
33 PerlModule MasonX::Profiler
34 PerlSetVar MasonPreamble "my $p = MasonX::Profiler->new($m, $r);"
35  
36 Note that if you are using virtual hosts, the two lines above must be
37 inside the C<E<lt>VirtualHostE<gt>> block, not outside it.
38  
39 =head1 DESCRIPTION
40  
41 This module prints per-component profiling information to C<STDERR>
42 (usually directed to the Apache error log). Its output looks like this:
43  
44 =Mason= 127.0.0.1 - /NoAuth/webrt.css BEGINS {{{
45 =Mason= 127.0.0.1 - /NoAuth/webrt.css {{{
46 =Mason= 127.0.0.1 - /Elements/Callback {{{
47 =Mason= 127.0.0.1 - /Elements/Callback }}} 0.0008
48 =Mason= 127.0.0.1 - /NoAuth/webrt.css }}} 0.0072
49 =Mason= 127.0.0.1 - /NoAuth/webrt.css }}} ENDS
50  
51 Each row contains five whitespace-separated fields: C<=Mason=>, remote IP
52 address, C<->, indented component name, and how many seconds did it take to
53 process that component, including all subcomponents called by it.
54  
55 The beginning and end of the initial request is represented by the special
56 time fields C<BEGINS> and C<ENDS>.
57  
58 =cut
59  
60 1 my %Depth;
61  
62 sub init {
63 0 ▶ my ($class, $p, $m, $r) = @_;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
64 0 $_[1] = $class->new($m, $r);
65 }
66  
67 sub new {
68 0 ▶ my ($class, $m, $r) = @_;
Subroutine new: not called CC=8 SCAR=42.8
Pod undocumented
69  
70 my $self = {
71 start => Time::HiRes::time(),
72 uri => $r->uri,
73 tag => $m->current_comp->path,
74 ip => (
75 0 eval { $r->connection->get_remote_host(
76 Apache::REMOTE_NAME(), $r->per_dir_config,
77 ) } ||
78 0 eval { $r->get_remote_host } ||
79 0 eval { CGI->remote_host } ||
80 0 eval { $ENV{REMOTE_HOST} } ||
81 0 ▶ eval { $ENV{REMOTE_ADDR} } ||
Condition0%0/14
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } || eval { do { $r->get_remote_host } } || eval { do { 'CGI'->remote_host } } || eval { do { $ENV{'REMOTE_HOST'} } } || eval { do { $ENV{'REMOTE_ADDR'} } } || '*'
l!l
00
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } or eval { do { $r->get_remote_host } } or eval { do { "CGI"->remote_host } } or eval { do { $ENV{"REMOTE_HOST"} } } or eval { do { $ENV{"REMOTE_ADDR"} } }
l!l&&r!l&&!r
000
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } or eval { do { $r->get_remote_host } } or eval { do { "CGI"->remote_host } } or eval { do { $ENV{"REMOTE_HOST"} } }
l!l&&r!l&&!r
000
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } or eval { do { $r->get_remote_host } } or eval { do { "CGI"->remote_host } }
l!l&&r!l&&!r
000
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } or eval { do { $r->get_remote_host } }
l!l&&r!l&&!r
000
MC/DC0%0/5
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } || eval { do { $r->get_remote_host } } || eval { do { 'CGI'->remote_host } } || eval { do { $ENV{'REMOTE_HOST'} } } || eval { do { $ENV{'REMOTE_ADDR'} } } || '*'
eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } } eval { do { $r->get_remote_host } } eval { do { "CGI"->remote_host } } eval { do { $ENV{"REMOTE_HOST"} } } eval { do { $ENV{"REMOTE_ADDR"} } }
Truth table0%0/6
A or B or C or D or E
A= eval { do { $r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config) } }B= eval { do { $r->get_remote_host } }C= eval { do { "CGI"->remote_host } }D= eval { do { $ENV{"REMOTE_HOST"} } }E= eval { do { $ENV{"REMOTE_ADDR"} } }
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
82 '*'
83 ),
84 };
85  
86 0 ▶ return if $self->{tag} eq '/l';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tag"} eq "/l" 0 0 0
87  
88 print STDERR "=Mason= $self->{ip} - $self->{uri} BEGINS {{{\n"
89 0 ▶ unless $Depth{$self->{ip}}{$self->{uri}}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $Depth{$self->{"ip"}}{$self->{"uri"}}++ 0 0 0
90  
91 0 my $indent = ' ' x (4 * $Depth{$self->{ip}}{$self->{uri}});
92 0 printf STDERR "=Mason= $self->{ip} - $indent".
93 "$self->{tag} {{{\n";
94  
95 0 bless($self, $class);
96 }
97  
98 sub DESTROY {
99 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=2 SCAR=17.9
100 0 my $indent = ' ' x (4 + 4 * --$Depth{$self->{ip}}{$self->{uri}});
101  
102 printf STDERR "=Mason= $self->{ip} - $indent".
103 0 "$self->{tag} }}} %.4f\n", (Time::HiRes::time() - $self->{start});
104  
105 0 ▶ return if $Depth{$self->{ip}}{$self->{uri}};
Branch: 1 branch
BranchTrueFalseTotal
if $Depth{$self->{"ip"}}{$self->{"uri"}} 0 0 0
106 0 print STDERR "=Mason= $self->{ip} - $self->{uri} }}} ENDS\n";
107 }
108  
109 1 1;
110  
111 =head1 AUTHORS
112  
113 Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>
114  
115 =head1 COPYRIGHT
116  
117 Copyright 2002, 2003, 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.
118  
119 This program is free software; you can redistribute it and/or
120 modify it under the same terms as Perl itself.
121  
122 See L<http://www.perl.com/perl/misc/Artistic.html>
123  
124 =cut
↑ Summary