| 1 | package MasonX::Profiler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $MasonX::Profiler::VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | MasonX::Profiler - Mason per-component profiler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | This document describes version 0.07 of MasonX::Profiler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | In the Mason handler: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | use MasonX::Profiler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | my $ah = HTML::Mason::ApacheHandler->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | preamble => 'my $p = MasonX::Profiler->new($m, $r);', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Note that B<CGIHandler> and B<Apache2Handler> works, too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | Alternatively, in F<httpd.conf>, before loading your C<PerlHandler>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | PerlModule MasonX::Profiler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | PerlSetVar MasonPreamble "my $p = MasonX::Profiler->new($m, $r);" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Note that if you are using virtual hosts, the two lines above must be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | inside the C<E<lt>VirtualHostE<gt>> block, not outside it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 INSTALLATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | MasonX::Profiler uses the standard perl module install process: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | cpansign -v # optional; see SIGNATURE for details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | perl Makefile.PL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | make # or 'nmake' on Win32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | make test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | make install | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | This module prints per-component profiling information to C<STDERR> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | (usually directed to the Apache error log). Its output looks like this: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =Mason= 127.0.0.1 - /NoAuth/webrt.css BEGINS {{{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =Mason= 127.0.0.1 - /NoAuth/webrt.css {{{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =Mason= 127.0.0.1 - /Elements/Callback {{{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | =Mason= 127.0.0.1 - /Elements/Callback }}} 0.0008 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =Mason= 127.0.0.1 - /NoAuth/webrt.css }}} 0.0072 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =Mason= 127.0.0.1 - /NoAuth/webrt.css }}} ENDS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Each row contains five whitespace-separated fields: C<=Mason=>, remote IP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | address, C<->, indented component name, and how many seconds did it take to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | process that component, including all subcomponents called by it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | The beginning and end of the initial request is represented by the special | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | time fields C<BEGINS> and C<ENDS>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my %Depth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($class, $p, $m, $r) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $_[1] = $class->new($m, $r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($class, $m, $r) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | start => Time::HiRes::time(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | uri => $r->uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | tag => $m->current_comp->path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ip => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | eval { $r->connection->get_remote_host( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Apache::REMOTE_NAME(), $r->per_dir_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ) } || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | eval { $r->get_remote_host } || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | eval { CGI->remote_host } || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | eval { $ENV{REMOTE_HOST} } || | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 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'}
}
} || '*'
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"}
}
}
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"}
}
}
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
}
}
eval {
do {
$r->connection->get_remote_host(Apache::REMOTE_NAME(), $r->per_dir_config)
}
} or eval {
do {
$r->get_remote_host
}
}
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"}
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | '*' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return if $self->{tag} eq '/l'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | print STDERR "=Mason= $self->{ip} - $self->{uri} BEGINS {{{\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | unless $Depth{$self->{ip}}{$self->{uri}}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $indent = ' ' x (4 * $Depth{$self->{ip}}{$self->{uri}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | printf STDERR "=Mason= $self->{ip} - $indent". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | "$self->{tag} {{{\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $indent = ' ' x (4 + 4 * --$Depth{$self->{ip}}{$self->{uri}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | printf STDERR "=Mason= $self->{ip} - $indent". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | "$self->{tag} }}} %.4f\n", (Time::HiRes::time() - $self->{start}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return if $Depth{$self->{ip}}{$self->{uri}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | print STDERR "=Mason= $self->{ip} - $self->{uri} }}} ENDS\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Best Practical Solutions, LLC <modules@bestpractical.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Autrijus Tang E<lt>autrijus@autrijus.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Copyright 2002, 2003, 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | See L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||