← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm
StatementsExecuted 2000116 statements in 4.58s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
200002111.29s1.45sApache::LogFormat::Compiler::::_safeApache::LogFormat::Compiler::_safe
200002111.16s1.26sApache::LogFormat::Compiler::::_stringApache::LogFormat::Compiler::_string
100001111.16s9.48sApache::LogFormat::Compiler::::log_lineApache::LogFormat::Compiler::log_line
40000851266ms266msApache::LogFormat::Compiler::::CORE:substApache::LogFormat::Compiler::CORE:subst (opcode)
1112.31ms3.91msApache::LogFormat::Compiler::::BEGIN@7Apache::LogFormat::Compiler::BEGIN@7
111281µs339µsApache::LogFormat::Compiler::::compileApache::LogFormat::Compiler::compile
21118µs20µsApache::LogFormat::Compiler::::__ANON__[:75]Apache::LogFormat::Compiler::__ANON__[:75]
71117µs17µsApache::LogFormat::Compiler::::__ANON__[:112]Apache::LogFormat::Compiler::__ANON__[:112]
101115µs15µsApache::LogFormat::Compiler::::CORE:substcontApache::LogFormat::Compiler::CORE:substcont (opcode)
11115µs15µsApache::LogFormat::Compiler::::BEGIN@5Apache::LogFormat::Compiler::BEGIN@5
11112µs27µsApache::LogFormat::Compiler::::BEGIN@3Apache::LogFormat::Compiler::BEGIN@3
1119µs72µsApache::LogFormat::Compiler::::BEGIN@8Apache::LogFormat::Compiler::BEGIN@8
1119µs348µsApache::LogFormat::Compiler::::newApache::LogFormat::Compiler::new
1118µs39µsApache::LogFormat::Compiler::::BEGIN@6Apache::LogFormat::Compiler::BEGIN@6
1117µs11µsApache::LogFormat::Compiler::::BEGIN@4Apache::LogFormat::Compiler::BEGIN@4
0000s0sApache::LogFormat::Compiler::::codeApache::LogFormat::Compiler::code
0000s0sApache::LogFormat::Compiler::::code_refApache::LogFormat::Compiler::code_ref
0000s0sApache::LogFormat::Compiler::::header_getApache::LogFormat::Compiler::header_get
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Apache::LogFormat::Compiler;
2
3237µs242µs
# spent 27µs (12+15) within Apache::LogFormat::Compiler::BEGIN@3 which was called: # once (12µs+15µs) by Plack::Middleware::AccessLog::BEGIN@6 at line 3
use strict;
# spent 27µs making 1 call to Apache::LogFormat::Compiler::BEGIN@3 # spent 15µs making 1 call to strict::import
4221µs214µs
# spent 11µs (7+3) within Apache::LogFormat::Compiler::BEGIN@4 which was called: # once (7µs+3µs) by Plack::Middleware::AccessLog::BEGIN@6 at line 4
use warnings;
# spent 11µs making 1 call to Apache::LogFormat::Compiler::BEGIN@4 # spent 4µs making 1 call to warnings::import
5242µs115µs
# spent 15µs within Apache::LogFormat::Compiler::BEGIN@5 which was called: # once (15µs+0s) by Plack::Middleware::AccessLog::BEGIN@6 at line 5
use 5.008001;
# spent 15µs making 1 call to Apache::LogFormat::Compiler::BEGIN@5
6222µs270µs
# spent 39µs (8+31) within Apache::LogFormat::Compiler::BEGIN@6 which was called: # once (8µs+31µs) by Plack::Middleware::AccessLog::BEGIN@6 at line 6
use Carp;
# spent 39µs making 1 call to Apache::LogFormat::Compiler::BEGIN@6 # spent 31µs making 1 call to Exporter::import
72552µs13.91ms
# spent 3.91ms (2.31+1.60) within Apache::LogFormat::Compiler::BEGIN@7 which was called: # once (2.31ms+1.60ms) by Plack::Middleware::AccessLog::BEGIN@6 at line 7
use POSIX::strftime::Compiler qw//;
# spent 3.91ms making 1 call to Apache::LogFormat::Compiler::BEGIN@7
8
# spent 72µs (9+63) within Apache::LogFormat::Compiler::BEGIN@8 which was called: # once (9µs+63µs) by Plack::Middleware::AccessLog::BEGIN@6 at line 14
use constant {
916µs163µs ENVS => 0,
# spent 63µs making 1 call to constant::import
10 RES => 1,
11 LENGTH => 2,
12 REQTIME => 3,
13 TIME => 4,
141660µs172µs};
# spent 72µs making 1 call to Apache::LogFormat::Compiler::BEGIN@8
15
161500nsour $VERSION = '0.32';
17
18# copy from Plack::Middleware::AccessLog
1912µsour %formats = (
20 common => '%h %l %u %t "%r" %>s %b',
21 combined => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"',
22);
23
24
# spent 1.45s (1.29+165ms) within Apache::LogFormat::Compiler::_safe which was called 200002 times, avg 7µs/call: # 200002 times (1.29s+165ms) by Apache::LogFormat::Compiler::__ANON__[(eval 593)[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:151]:21] at line 10 of (eval 593)[Apache/LogFormat/Compiler.pm:151], avg 7µs/call
sub _safe {
2520000277.7ms my $string = shift;
2620000261.6ms return unless defined $string;
27200002997ms200002165ms $string =~ s/([^[:print:]])/"\\x" . unpack("H*", $1)/eg;
# spent 165ms making 200002 calls to Apache::LogFormat::Compiler::CORE:subst, avg 823ns/call
28200002845ms return $string;
29}
30
31
# spent 1.26s (1.16+101ms) within Apache::LogFormat::Compiler::_string which was called 200002 times, avg 6µs/call: # 200002 times (1.16s+101ms) by Apache::LogFormat::Compiler::__ANON__[(eval 593)[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:151]:21] at line 10 of (eval 593)[Apache/LogFormat/Compiler.pm:151], avg 6µs/call
sub _string {
3220000290.0ms my $string = shift;
3320000253.5ms return '-' if ! defined $string;
3420000269.2ms return '-' if ! length $string;
35200002784ms200002101ms $string =~ s/([^[:print:]])/"\\x" . unpack("H*", $1)/eg;
# spent 101ms making 200002 calls to Apache::LogFormat::Compiler::CORE:subst, avg 505ns/call
36200002815ms return $string;
37}
38
39sub header_get {
40 my ($headers, $key) = @_;
41 $key = lc $key;
42 my @headers = @$headers; # copy
43 my $value;
44 while (my($hdr, $val) = splice @headers, 0, 2) {
45 if ( lc $hdr eq $key ) {
46 $value = $val;
47 last;
48 }
49 }
50 return $value;
51}
52
5311µsmy $psgi_reserved = { CONTENT_LENGTH => 1, CONTENT_TYPE => 1 };
54
55
# spent 20µs (18+2) within Apache::LogFormat::Compiler::__ANON__[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:75] which was called 2 times, avg 10µs/call: # 2 times (18µs+2µs) by Apache::LogFormat::Compiler::compile at line 131, avg 10µs/call
my $block_handler = sub {
5625µs my($block, $type, $extra) = @_;
572200ns my $cb;
582700ns if ($type eq 'i') {
5926µs22µs $block =~ s/-/_/g;
# spent 2µs making 2 calls to Apache::LogFormat::Compiler::CORE:subst, avg 850ns/call
6021µs $block = uc($block);
6122µs $block = "HTTP_${block}" unless $psgi_reserved->{$block};
6222µs $cb = q!_string($_[ENVS]->{'!.$block.q!'})!;
63 } elsif ($type eq 'o') {
64 $cb = q!_string(header_get($_[RES]->[1],'!.$block.q!'))!;
65 } elsif ($type eq 't') {
66 $cb = q!"[" . POSIX::strftime::Compiler::strftime('!.$block.q!', @lt) . "]"!;
67 } elsif (exists $extra->{$type}) {
68 $cb = q!_string($extra_block_handlers->{'!.$type.q!'}->('!.$block.q!',$_[ENVS],$_[RES],$_[LENGTH],$_[REQTIME]))!;
69 } else {
70 Carp::croak("{$block}$type not supported");
71 $cb = "-";
72 }
7326µs return q|! . | . $cb . q|
74 . q!|;
7512µs};
76
7715µsour %char_handler = (
78 '%' => q!'%'!,
79 h => q!($_[ENVS]->{REMOTE_ADDR} || '-')!,
80 l => q!'-'!,
81 u => q!($_[ENVS]->{REMOTE_USER} || '-')!,
82 t => q!'[' . $t . ']'!,
83 r => q!_safe($_[ENVS]->{REQUEST_METHOD}) . " " . _safe($_[ENVS]->{REQUEST_URI}) .
84 " " . $_[ENVS]->{SERVER_PROTOCOL}!,
85 s => q!$_[RES]->[0]!,
86 b => q!(defined $_[LENGTH] ? $_[LENGTH] : '-')!,
87 T => q!(defined $_[REQTIME] ? int($_[REQTIME]*1_000_000) : '-')!,
88 D => q!(defined $_[REQTIME] ? $_[REQTIME] : '-')!,
89 v => q!($_[ENVS]->{SERVER_NAME} || '-')!,
90 V => q!($_[ENVS]->{HTTP_HOST} || $_[ENVS]->{SERVER_NAME} || '-')!,
91 p => q!$_[ENVS]->{SERVER_PORT}!,
92 P => q!$$!,
93 m => q!_safe($_[ENVS]->{REQUEST_METHOD})!,
94 U => q!_safe($_[ENVS]->{PATH_INFO})!,
95 q => q!(($_[ENVS]->{QUERY_STRING} ne '') ? '?' . _safe($_[ENVS]->{QUERY_STRING}) : '' )!,
96 H => q!$_[ENVS]->{SERVER_PROTOCOL}!,
97
98);
99
100
# spent 17µs within Apache::LogFormat::Compiler::__ANON__[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:112] which was called 7 times, avg 2µs/call: # 7 times (17µs+0s) by Apache::LogFormat::Compiler::compile at line 131, avg 2µs/call
my $char_handler = sub {
10173µs my ($char, $extra) = @_;
10273µs my $cb = $char_handler{$char};
1037700ns if (!$cb && exists $extra->{$char}) {
104 $cb = q!_string($extra_char_handlers->{'!.$char.q!'}->($_[ENVS],$_[RES],$_[LENGTH],$_[REQTIME]))!;
105 }
1067500ns unless ($cb) {
107 Carp::croak "\%$char not supported.";
108 return "-";
109 }
110717µs q|! . | . $cb . q|
111 . q!|;
11212µs};
113
114
# spent 348µs (9+339) within Apache::LogFormat::Compiler::new which was called: # once (9µs+339µs) by Plack::Middleware::AccessLog::prepare_app at line 17 of Plack/Middleware/AccessLog.pm
sub new {
1151200ns my $class = shift;
116
1171200ns my $fmt = shift || "combined";
1181300ns $fmt = $formats{$fmt} if exists $formats{$fmt};
119
1201400ns my %opts = @_;
121
12212µs1339µs my ($code_ref, $code) = compile($fmt, $opts{block_handlers} || {}, $opts{char_handlers} || {});
# spent 339µs making 1 call to Apache::LogFormat::Compiler::compile
12314µs bless [$code_ref, $code], $class;
124}
125
126
# spent 339µs (281+59) within Apache::LogFormat::Compiler::compile which was called: # once (281µs+59µs) by Apache::LogFormat::Compiler::new at line 122
sub compile {
1271300ns my $fmt = shift;
1281100ns my $extra_block_handlers = shift;
1291100ns my $extra_char_handlers = shift;
13015µs1600ns $fmt =~ s/!/\\!/g;
# spent 600ns making 1 call to Apache::LogFormat::Compiler::CORE:subst
1311050µs2058µs $fmt =~ s!
# spent 20µs making 2 calls to Apache::LogFormat::Compiler::__ANON__[Apache/LogFormat/Compiler.pm:75], avg 10µs/call # spent 17µs making 7 calls to Apache::LogFormat::Compiler::__ANON__[Apache/LogFormat/Compiler.pm:112], avg 2µs/call # spent 15µs making 10 calls to Apache::LogFormat::Compiler::CORE:substcont, avg 2µs/call # spent 5µs making 1 call to Apache::LogFormat::Compiler::CORE:subst
132 (?:
133 \%\{(.+?)\}([a-zA-Z]) |
134 \%(?:[<>])?([a-zA-Z\%])
135 )
136 ! $1 ? $block_handler->($1, $2, $extra_block_handlers) : $char_handler->($3, $extra_char_handlers) !egx;
137
13812µs my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
1391300ns my $c = {};
14012µs $fmt = q~sub {
141 $_[TIME] = time() if ! defined $_[TIME];
142 my @lt = localtime($_[TIME]);
143 if ( ! exists $c->{tz_cache} || ! exists $c->{isdst_cache} || $lt[8] != $c->{isdst_cache} ) {
144 $c->{tz_cache} = POSIX::strftime::Compiler::strftime('%z',@lt);
145 $c->{isdst_cache} = $lt[8];
146 }
147 my $t = sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $lt[3], $abbr[$lt[4]], $lt[5]+1900,
148 $lt[2], $lt[1], $lt[0], $c->{tz_cache};
149 q!~ . $fmt . q~!
150 }~;
1511227µs my $code_ref = eval $fmt; ## no critic
# spent 5.14s executing statements in string eval
# includes 5.62s spent executing 100001 calls to 1 sub defined therein.
1521100ns die $@ . "\n===\n" . $fmt if $@;
15316µs wantarray ? ($code_ref, $fmt) : $code_ref;
154}
155
156
# spent 9.48s (1.16+8.33) within Apache::LogFormat::Compiler::log_line which was called 100001 times, avg 95µs/call: # 100001 times (1.16s+8.33s) by Plack::Middleware::AccessLog::log_line at line 54 of Plack/Middleware/AccessLog.pm, avg 95µs/call
sub log_line {
15710000136.4ms my $self = shift;
158100001745ms1000018.33s $self->[0]->(@_) . "\n";
159}
160
161sub code {
162 my $self = shift;
163 $self->[1];
164}
165
166sub code_ref {
167 my $self = shift;
168 $self->[0];
169}
170
17115µs1;
172__END__
 
# spent 266ms within Apache::LogFormat::Compiler::CORE:subst which was called 400008 times, avg 664ns/call: # 200002 times (165ms+0s) by Apache::LogFormat::Compiler::_safe at line 27, avg 823ns/call # 200002 times (101ms+0s) by Apache::LogFormat::Compiler::_string at line 35, avg 505ns/call # 2 times (2µs+0s) by Apache::LogFormat::Compiler::__ANON__[/usr/local/share/perl/5.18.2/Apache/LogFormat/Compiler.pm:75] at line 59, avg 850ns/call # once (5µs+0s) by Apache::LogFormat::Compiler::compile at line 131 # once (600ns+0s) by Apache::LogFormat::Compiler::compile at line 130
sub Apache::LogFormat::Compiler::CORE:subst; # opcode
# spent 15µs within Apache::LogFormat::Compiler::CORE:substcont which was called 10 times, avg 2µs/call: # 10 times (15µs+0s) by Apache::LogFormat::Compiler::compile at line 131, avg 2µs/call
sub Apache::LogFormat::Compiler::CORE:substcont; # opcode