Profile of Apache/LogFormat/Compiler.pm

← 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
Statements | Executed 2000116 statements in 4.58s

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
200002 | 1 | 1 | 1.29s | 1.45s | Apache::LogFormat::Compiler::::_safeApache::LogFormat::Compiler::_safe
200002 | 1 | 1 | 1.16s | 1.26s | Apache::LogFormat::Compiler::::_stringApache::LogFormat::Compiler::_string
100001 | 1 | 1 | 1.16s | 9.48s | Apache::LogFormat::Compiler::::log_lineApache::LogFormat::Compiler::log_line
400008 | 5 | 1 | 266ms | 266ms | Apache::LogFormat::Compiler::::CORE:substApache::LogFormat::Compiler::CORE:subst (opcode)
1 | 1 | 1 | 2.31ms | 3.91ms | Apache::LogFormat::Compiler::::BEGIN@7Apache::LogFormat::Compiler::BEGIN@7
1 | 1 | 1 | 281µs | 339µs | Apache::LogFormat::Compiler::::compileApache::LogFormat::Compiler::compile
2 | 1 | 1 | 18µs | 20µs | Apache::LogFormat::Compiler::::__ANON__[:75]Apache::LogFormat::Compiler::__ANON__[:75]
7 | 1 | 1 | 17µs | 17µs | Apache::LogFormat::Compiler::::__ANON__[:112]Apache::LogFormat::Compiler::__ANON__[:112]
10 | 1 | 1 | 15µs | 15µs | Apache::LogFormat::Compiler::::CORE:substcontApache::LogFormat::Compiler::CORE:substcont (opcode)
1 | 1 | 1 | 15µs | 15µs | Apache::LogFormat::Compiler::::BEGIN@5Apache::LogFormat::Compiler::BEGIN@5
1 | 1 | 1 | 12µs | 27µs | Apache::LogFormat::Compiler::::BEGIN@3Apache::LogFormat::Compiler::BEGIN@3
1 | 1 | 1 | 9µs | 72µs | Apache::LogFormat::Compiler::::BEGIN@8Apache::LogFormat::Compiler::BEGIN@8
1 | 1 | 1 | 9µs | 348µs | Apache::LogFormat::Compiler::::newApache::LogFormat::Compiler::new
1 | 1 | 1 | 8µs | 39µs | Apache::LogFormat::Compiler::::BEGIN@6Apache::LogFormat::Compiler::BEGIN@6
1 | 1 | 1 | 7µs | 11µs | Apache::LogFormat::Compiler::::BEGIN@4Apache::LogFormat::Compiler::BEGIN@4
0 | 0 | 0 | 0s | 0s | Apache::LogFormat::Compiler::::codeApache::LogFormat::Compiler::code
0 | 0 | 0 | 0s | 0s | Apache::LogFormat::Compiler::::code_refApache::LogFormat::Compiler::code_ref
0 | 0 | 0 | 0s | 0s | Apache::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
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Apache::LogFormat::Compiler;
2 |  |  |  |  |
3 | 2 | 37µs | 2 | 42µ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
4 | 2 | 21µs | 2 | 14µ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
5 | 2 | 42µs | 1 | 15µ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
6 | 2 | 22µs | 2 | 70µ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
7 | 2 | 552µs | 1 | 3.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 {
9 | 1 | 6µs | 1 | 63µs | ENVS => 0, # spent 63µs making 1 call to constant::import
10 |  |  |  |  | RES => 1,
11 |  |  |  |  | LENGTH => 2,
12 |  |  |  |  | REQTIME => 3,
13 |  |  |  |  | TIME => 4,
14 | 1 | 660µs | 1 | 72µs | }; # spent 72µs making 1 call to Apache::LogFormat::Compiler::BEGIN@8
15 |  |  |  |  |
16 | 1 | 500ns |  |  | our $VERSION = '0.32';
17 |  |  |  |  |
18 |  |  |  |  | # copy from Plack::Middleware::AccessLog
19 | 1 | 2µs |  |  | our %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 {
25 | 200002 | 77.7ms |  |  | my $string = shift;
26 | 200002 | 61.6ms |  |  | return unless defined $string;
27 | 200002 | 997ms | 200002 | 165ms | $string =~ s/([^[:print:]])/"\\x" . unpack("H*", $1)/eg; # spent 165ms making 200002 calls to Apache::LogFormat::Compiler::CORE:subst, avg 823ns/call
28 | 200002 | 845ms |  |  | 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 {
32 | 200002 | 90.0ms |  |  | my $string = shift;
33 | 200002 | 53.5ms |  |  | return '-' if ! defined $string;
34 | 200002 | 69.2ms |  |  | return '-' if ! length $string;
35 | 200002 | 784ms | 200002 | 101ms | $string =~ s/([^[:print:]])/"\\x" . unpack("H*", $1)/eg; # spent 101ms making 200002 calls to Apache::LogFormat::Compiler::CORE:subst, avg 505ns/call
36 | 200002 | 815ms |  |  | return $string;
37 |  |  |  |  | }
38 |  |  |  |  |
39 |  |  |  |  | sub 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 |  |  |  |  |
53 | 1 | 1µs |  |  | my $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 {
56 | 2 | 5µs |  |  | my($block, $type, $extra) = @_;
57 | 2 | 200ns |  |  | my $cb;
58 | 2 | 700ns |  |  | if ($type eq 'i') {
59 | 2 | 6µs | 2 | 2µs | $block =~ s/-/_/g; # spent 2µs making 2 calls to Apache::LogFormat::Compiler::CORE:subst, avg 850ns/call
60 | 2 | 1µs |  |  | $block = uc($block);
61 | 2 | 2µs |  |  | $block = "HTTP_${block}" unless $psgi_reserved->{$block};
62 | 2 | 2µ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 |  |  |  |  | }
73 | 2 | 6µs |  |  | return q|! . | . $cb . q|
74 |  |  |  |  | . q!|;
75 | 1 | 2µs |  |  | };
76 |  |  |  |  |
77 | 1 | 5µs |  |  | our %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 {
101 | 7 | 3µs |  |  | my ($char, $extra) = @_;
102 | 7 | 3µs |  |  | my $cb = $char_handler{$char};
103 | 7 | 700ns |  |  | if (!$cb && exists $extra->{$char}) {
104 |  |  |  |  | $cb = q!_string($extra_char_handlers->{'!.$char.q!'}->($_[ENVS],$_[RES],$_[LENGTH],$_[REQTIME]))!;
105 |  |  |  |  | }
106 | 7 | 500ns |  |  | unless ($cb) {
107 |  |  |  |  | Carp::croak "\%$char not supported.";
108 |  |  |  |  | return "-";
109 |  |  |  |  | }
110 | 7 | 17µs |  |  | q|! . | . $cb . q|
111 |  |  |  |  | . q!|;
112 | 1 | 2µ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 {
115 | 1 | 200ns |  |  | my $class = shift;
116 |  |  |  |  |
117 | 1 | 200ns |  |  | my $fmt = shift || "combined";
118 | 1 | 300ns |  |  | $fmt = $formats{$fmt} if exists $formats{$fmt};
119 |  |  |  |  |
120 | 1 | 400ns |  |  | my %opts = @_;
121 |  |  |  |  |
122 | 1 | 2µs | 1 | 339µs | my ($code_ref, $code) = compile($fmt, $opts{block_handlers} || {}, $opts{char_handlers} || {}); # spent 339µs making 1 call to Apache::LogFormat::Compiler::compile
123 | 1 | 4µ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 {
127 | 1 | 300ns |  |  | my $fmt = shift;
128 | 1 | 100ns |  |  | my $extra_block_handlers = shift;
129 | 1 | 100ns |  |  | my $extra_char_handlers = shift;
130 | 1 | 5µs | 1 | 600ns | $fmt =~ s/!/\\!/g; # spent 600ns making 1 call to Apache::LogFormat::Compiler::CORE:subst
131 | 10 | 50µs | 20 | 58µ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 |  |  |  |  |
138 | 1 | 2µs |  |  | my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
139 | 1 | 300ns |  |  | my $c = {};
140 | 1 | 2µ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 |  |  |  |  | }~;
151 | 1 | 227µ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.
152 | 1 | 100ns |  |  | die $@ . "\n===\n" . $fmt if $@;
153 | 1 | 6µ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 {
157 | 100001 | 36.4ms |  |  | my $self = shift;
158 | 100001 | 745ms | 100001 | 8.33s | $self->[0]->(@_) . "\n"; # spent 8.33s making 100001 calls to Apache::LogFormat::Compiler::__ANON__[(eval 593)[Apache/LogFormat/Compiler.pm:151]:21], avg 83µs/call
159 |  |  |  |  | }
160 |  |  |  |  |
161 |  |  |  |  | sub code {
162 |  |  |  |  | my $self = shift;
163 |  |  |  |  | $self->[1];
164 |  |  |  |  | }
165 |  |  |  |  |
166 |  |  |  |  | sub code_ref {
167 |  |  |  |  | my $self = shift;
168 |  |  |  |  | $self->[0];
169 |  |  |  |  | }
170 |  |  |  |  |
171 | 1 | 5µs |  |  | 1;
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