Filename | /usr/local/share/perl/5.18.2/Plack/Runner.pm |
Statements | Executed 104 statements in 4.99ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.83ms | 2.00ms | BEGIN@5 | Plack::Runner::
1 | 1 | 1 | 127µs | 1.87ms | parse_options | Plack::Runner::
3 | 3 | 1 | 40µs | 16.8ms | apply_middleware | Plack::Runner::
1 | 1 | 1 | 29µs | 80µs | BEGIN@166 | Plack::Runner::
1 | 1 | 1 | 26µs | 16.8ms | prepare_devel | Plack::Runner::
1 | 1 | 1 | 24µs | 59µs | BEGIN@167 | Plack::Runner::
1 | 1 | 1 | 23µs | 23µs | CORE:print (opcode) | Plack::Runner::
3 | 1 | 1 | 19µs | 516µs | __ANON__[:193] | Plack::Runner::
3 | 1 | 1 | 18µs | 18µs | build | Plack::Runner::
3 | 2 | 2 | 18µs | 710µs | __ANON__[:24] | Plack::Runner::
1 | 1 | 1 | 16µs | 40µs | __ANON__[:213] | Plack::Runner::
1 | 1 | 1 | 16µs | 16µs | mangle_host_port_socket | Plack::Runner::
1 | 1 | 1 | 15µs | 624µs | loader | Plack::Runner::
1 | 1 | 1 | 13µs | 13µs | new | Plack::Runner::
1 | 1 | 1 | 12µs | 12µs | locate_app | Plack::Runner::
1 | 1 | 1 | 11µs | 23µs | BEGIN@2 | Plack::Runner::
2 | 1 | 1 | 10µs | 10µs | CORE:match (opcode) | Plack::Runner::
1 | 1 | 1 | 9µs | 9µs | setup | Plack::Runner::
1 | 1 | 1 | 8µs | 40µs | BEGIN@6 | Plack::Runner::
1 | 1 | 1 | 7µs | 24.7ms | load_server | Plack::Runner::
1 | 1 | 1 | 6µs | 9µs | BEGIN@3 | Plack::Runner::
1 | 1 | 1 | 4µs | 4µs | BEGIN@4 | Plack::Runner::
1 | 1 | 1 | 3µs | 3µs | __ANON__[:160] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:122] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:172] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:179] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:23] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:258] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:270] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:54] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | __ANON__[:55] | Plack::Runner::
0 | 0 | 0 | 0s | 0s | run | Plack::Runner::
0 | 0 | 0 | 0s | 0s | set_options | Plack::Runner::
0 | 0 | 0 | 0s | 0s | version_cb | Plack::Runner::
0 | 0 | 0 | 0s | 0s | watch | Plack::Runner::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Plack::Runner; | ||||
2 | 2 | 20µs | 2 | 35µs | # spent 23µs (11+12) within Plack::Runner::BEGIN@2 which was called:
# once (11µs+12µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 2 # spent 23µs making 1 call to Plack::Runner::BEGIN@2
# spent 12µs making 1 call to strict::import |
3 | 2 | 18µs | 2 | 13µs | # spent 9µs (6+4) within Plack::Runner::BEGIN@3 which was called:
# once (6µs+4µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 3 # spent 9µs making 1 call to Plack::Runner::BEGIN@3
# spent 4µs making 1 call to warnings::import |
4 | 2 | 15µs | 1 | 4µs | # spent 4µs within Plack::Runner::BEGIN@4 which was called:
# once (4µs+0s) by PONAPI::CLI::RunServer::BEGIN@7 at line 4 # spent 4µs making 1 call to Plack::Runner::BEGIN@4 |
5 | 2 | 78µs | 1 | 2.00ms | # spent 2.00ms (1.83+173µs) within Plack::Runner::BEGIN@5 which was called:
# once (1.83ms+173µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 5 # spent 2.00ms making 1 call to Plack::Runner::BEGIN@5 |
6 | 2 | 2.72ms | 2 | 72µs | # spent 40µs (8+32) within Plack::Runner::BEGIN@6 which was called:
# once (8µs+32µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 6 # spent 40µs making 1 call to Plack::Runner::BEGIN@6
# spent 32µs making 1 call to Exporter::import |
7 | |||||
8 | # spent 13µs within Plack::Runner::new which was called:
# once (13µs+0s) by PONAPI::CLI::RunServer::run at line 26 of lib/PONAPI/CLI/RunServer.pm | ||||
9 | 1 | 900ns | my $class = shift; | ||
10 | 1 | 16µs | bless { | ||
11 | env => $ENV{PLACK_ENV}, | ||||
12 | loader => 'Plack::Loader', | ||||
13 | includes => [], | ||||
14 | modules => [], | ||||
15 | default_middleware => 1, | ||||
16 | @_, | ||||
17 | }, $class; | ||||
18 | } | ||||
19 | |||||
20 | # delay the build process for reloader | ||||
21 | # spent 18µs within Plack::Runner::build which was called 3 times, avg 6µs/call:
# 3 times (18µs+0s) by Plack::Runner::apply_middleware at line 193, avg 6µs/call | ||||
22 | 3 | 2µs | my $block = shift; | ||
23 | 3 | 1µs | my $app = shift || sub { }; | ||
24 | 6 | 27µs | 6 | 692µs | # spent 710µs (18+692) within Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:24] which was called 3 times, avg 237µs/call:
# 2 times (14µs+160µs) by Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:24] at line 24, avg 87µs/call
# once (4µs+532µs) by Plack::Loader::preload_app at line 55 of Plack/Loader.pm # spent 516µs making 3 calls to Plack::Runner::__ANON__[Plack/Runner.pm:193], avg 172µs/call
# spent 174µs making 2 calls to Plack::Runner::__ANON__[Plack/Runner.pm:24], avg 87µs/call
# spent 3µs making 1 call to Plack::Runner::__ANON__[Plack/Runner.pm:160] |
25 | } | ||||
26 | |||||
27 | # spent 1.87ms (127µs+1.74) within Plack::Runner::parse_options which was called:
# once (127µs+1.74ms) by PONAPI::CLI::RunServer::run at line 27 of lib/PONAPI/CLI/RunServer.pm | ||||
28 | 1 | 500ns | my $self = shift; | ||
29 | |||||
30 | 1 | 4µs | local @ARGV = @_; | ||
31 | |||||
32 | # From 'prove': Allow cuddling the paths with -I, -M and -e | ||||
33 | 3 | 36µs | 2 | 10µs | @ARGV = map { /^(-[IMe])(.+)/ ? ($1,$2) : $_ } @ARGV; # spent 10µs making 2 calls to Plack::Runner::CORE:match, avg 5µs/call |
34 | |||||
35 | 1 | 1µs | my($host, $port, $socket, @listen); | ||
36 | |||||
37 | 1 | 2µs | require Getopt::Long; | ||
38 | 1 | 13µs | 1 | 149µs | my $parser = Getopt::Long::Parser->new( # spent 149µs making 1 call to Getopt::Long::Parser::new |
39 | config => [ "no_auto_abbrev", "no_ignore_case", "pass_through" ], | ||||
40 | ); | ||||
41 | |||||
42 | $parser->getoptions( | ||||
43 | "a|app=s" => \$self->{app}, | ||||
44 | "o|host=s" => \$host, | ||||
45 | "p|port=i" => \$port, | ||||
46 | "s|server=s" => \$self->{server}, | ||||
47 | "S|socket=s" => \$socket, | ||||
48 | 'l|listen=s@' => \@listen, | ||||
49 | 'D|daemonize' => \$self->{daemonize}, | ||||
50 | "E|env=s" => \$self->{env}, | ||||
51 | "e=s" => \$self->{eval}, | ||||
52 | 'I=s@' => $self->{includes}, | ||||
53 | 'M=s@' => $self->{modules}, | ||||
54 | 'r|reload' => sub { $self->{loader} = "Restarter" }, | ||||
55 | 'R|Reload=s' => sub { $self->{loader} = "Restarter"; $self->loader->watch(split ",", $_[1]) }, | ||||
56 | 1 | 34µs | 1 | 1.57ms | 'L|loader=s' => \$self->{loader}, # spent 1.57ms making 1 call to Getopt::Long::Parser::getoptions |
57 | "access-log=s" => \$self->{access_log}, | ||||
58 | "path=s" => \$self->{path}, | ||||
59 | "h|help" => \$self->{help}, | ||||
60 | "v|version" => \$self->{version}, | ||||
61 | "default-middleware!" => \$self->{default_middleware}, | ||||
62 | ); | ||||
63 | |||||
64 | 1 | 400ns | my(@options, @argv); | ||
65 | 1 | 2µs | while (defined(my $arg = shift @ARGV)) { | ||
66 | if ($arg =~ s/^--?//) { | ||||
67 | my @v = split '=', $arg, 2; | ||||
68 | $v[0] =~ tr/-/_/; | ||||
69 | if (@v == 2) { | ||||
70 | push @options, @v; | ||||
71 | } elsif ($v[0] =~ s/^(disable|enable)_//) { | ||||
72 | push @options, $v[0], $1 eq 'enable'; | ||||
73 | } else { | ||||
74 | push @options, $v[0], shift @ARGV; | ||||
75 | } | ||||
76 | } else { | ||||
77 | push @argv, $arg; | ||||
78 | } | ||||
79 | } | ||||
80 | |||||
81 | 1 | 8µs | 1 | 16µs | push @options, $self->mangle_host_port_socket($host, $port, $socket, @listen); # spent 16µs making 1 call to Plack::Runner::mangle_host_port_socket |
82 | 1 | 1µs | push @options, daemonize => 1 if $self->{daemonize}; | ||
83 | |||||
84 | 1 | 2µs | $self->{options} = \@options; | ||
85 | 1 | 26µs | $self->{argv} = \@argv; | ||
86 | } | ||||
87 | |||||
88 | sub set_options { | ||||
89 | my $self = shift; | ||||
90 | push @{$self->{options}}, @_; | ||||
91 | } | ||||
92 | |||||
93 | # spent 16µs within Plack::Runner::mangle_host_port_socket which was called:
# once (16µs+0s) by Plack::Runner::parse_options at line 81 | ||||
94 | 1 | 2µs | my($self, $host, $port, $socket, @listen) = @_; | ||
95 | |||||
96 | 1 | 3µs | for my $listen (reverse @listen) { | ||
97 | if ($listen =~ /:\d+$/) { | ||||
98 | ($host, $port) = split /:/, $listen, 2; | ||||
99 | $host = undef if $host eq ''; | ||||
100 | } else { | ||||
101 | $socket ||= $listen; | ||||
102 | } | ||||
103 | } | ||||
104 | |||||
105 | 1 | 1µs | unless (@listen) { | ||
106 | 1 | 900ns | if ($socket) { | ||
107 | @listen = ($socket); | ||||
108 | } else { | ||||
109 | 1 | 300ns | $port ||= 5000; | ||
110 | 1 | 3µs | @listen = ($host ? "$host:$port" : ":$port"); | ||
111 | } | ||||
112 | } | ||||
113 | |||||
114 | 1 | 10µs | return host => $host, port => $port, listen => \@listen, socket => $socket; | ||
115 | } | ||||
116 | |||||
117 | sub version_cb { | ||||
118 | my $self = shift; | ||||
119 | $self->{version_cb} || sub { | ||||
120 | require Plack; | ||||
121 | print "Plack $Plack::VERSION\n"; | ||||
122 | }; | ||||
123 | } | ||||
124 | |||||
125 | # spent 9µs within Plack::Runner::setup which was called:
# once (9µs+0s) by Plack::Runner::run at line 248 | ||||
126 | 1 | 500ns | my $self = shift; | ||
127 | |||||
128 | 1 | 2µs | if ($self->{help}) { | ||
129 | require Pod::Usage; | ||||
130 | Pod::Usage::pod2usage(0); | ||||
131 | } | ||||
132 | |||||
133 | 1 | 700ns | if ($self->{version}) { | ||
134 | $self->version_cb->(); | ||||
135 | exit; | ||||
136 | } | ||||
137 | |||||
138 | 1 | 1µs | if (@{$self->{includes}}) { | ||
139 | require lib; | ||||
140 | lib->import(@{$self->{includes}}); | ||||
141 | } | ||||
142 | |||||
143 | 1 | 900ns | if ($self->{eval}) { | ||
144 | push @{$self->{modules}}, 'Plack::Builder'; | ||||
145 | } | ||||
146 | |||||
147 | 1 | 9µs | for (@{$self->{modules}}) { | ||
148 | my($module, @import) = split /[=,]/; | ||||
149 | eval "require $module" or die $@; | ||||
150 | $module->import(@import); | ||||
151 | } | ||||
152 | } | ||||
153 | |||||
154 | # spent 12µs within Plack::Runner::locate_app which was called:
# once (12µs+0s) by Plack::Runner::run at line 250 | ||||
155 | 1 | 1µs | my($self, @args) = @_; | ||
156 | |||||
157 | 1 | 2µs | my $psgi = $self->{app} || $args[0]; | ||
158 | |||||
159 | 1 | 15µs | if (ref $psgi eq 'CODE') { | ||
160 | 1 | 5µs | # spent 3µs within Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:160] which was called:
# once (3µs+0s) by Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:24] at line 24 | ||
161 | } | ||||
162 | |||||
163 | if ($self->{eval}) { | ||||
164 | $self->loader->watch("lib"); | ||||
165 | return build { | ||||
166 | 2 | 76µs | 2 | 131µs | # spent 80µs (29+51) within Plack::Runner::BEGIN@166 which was called:
# once (29µs+51µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 166 # spent 80µs making 1 call to Plack::Runner::BEGIN@166
# spent 51µs making 1 call to strict::unimport |
167 | 2 | 1.65ms | 2 | 94µs | # spent 59µs (24+35) within Plack::Runner::BEGIN@167 which was called:
# once (24µs+35µs) by PONAPI::CLI::RunServer::BEGIN@7 at line 167 # spent 59µs making 1 call to Plack::Runner::BEGIN@167
# spent 35µs making 1 call to warnings::unimport |
168 | my $eval = "builder { $self->{eval};"; | ||||
169 | $eval .= "Plack::Util::load_psgi(\$psgi);" if $psgi; | ||||
170 | $eval .= "}"; | ||||
171 | eval $eval or die $@; | ||||
172 | }; | ||||
173 | } | ||||
174 | |||||
175 | $psgi ||= "app.psgi"; | ||||
176 | |||||
177 | require File::Basename; | ||||
178 | $self->loader->watch( File::Basename::dirname($psgi) . "/lib", $psgi ); | ||||
179 | build { Plack::Util::load_psgi $psgi }; | ||||
180 | } | ||||
181 | |||||
182 | sub watch { | ||||
183 | my($self, @dir) = @_; | ||||
184 | |||||
185 | push @{$self->{watch}}, @dir | ||||
186 | if $self->{loader} eq 'Restarter'; | ||||
187 | } | ||||
188 | |||||
189 | # spent 16.8ms (40µs+16.7) within Plack::Runner::apply_middleware which was called 3 times, avg 5.59ms/call:
# once (11µs+8.62ms) by Plack::Runner::prepare_devel at line 201
# once (11µs+6.25ms) by Plack::Runner::prepare_devel at line 202
# once (18µs+1.86ms) by Plack::Runner::prepare_devel at line 200 | ||||
190 | 3 | 3µs | my($self, $app, $class, @args) = @_; | ||
191 | |||||
192 | 3 | 6µs | 3 | 16.7ms | my $mw_class = Plack::Util::load_class($class, 'Plack::Middleware'); # spent 16.7ms making 3 calls to Plack::Util::load_class, avg 5.57ms/call |
193 | 6 | 45µs | 6 | 516µs | # spent 516µs (19+497) within Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:193] which was called 3 times, avg 172µs/call:
# 3 times (19µs+497µs) by Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:24] at line 24, avg 172µs/call # spent 444µs making 2 calls to Plack::Middleware::wrap, avg 222µs/call
# spent 54µs making 1 call to Plack::Middleware::Lint::wrap
# spent 18µs making 3 calls to Plack::Runner::build, avg 6µs/call |
194 | } | ||||
195 | |||||
196 | # spent 16.8ms (26µs+16.8) within Plack::Runner::prepare_devel which was called:
# once (26µs+16.8ms) by Plack::Runner::run at line 262 | ||||
197 | 1 | 1µs | my($self, $app) = @_; | ||
198 | |||||
199 | 1 | 2µs | if ($self->{default_middleware}) { | ||
200 | 1 | 4µs | 1 | 1.88ms | $app = $self->apply_middleware($app, 'Lint'); # spent 1.88ms making 1 call to Plack::Runner::apply_middleware |
201 | 1 | 2µs | 1 | 8.63ms | $app = $self->apply_middleware($app, 'StackTrace'); # spent 8.63ms making 1 call to Plack::Runner::apply_middleware |
202 | 1 | 4µs | 1 | 6.26ms | if (!$ENV{GATEWAY_INTERFACE} and !$self->{access_log}) { # spent 6.26ms making 1 call to Plack::Runner::apply_middleware |
203 | $app = $self->apply_middleware($app, 'AccessLog'); | ||||
204 | } | ||||
205 | } | ||||
206 | |||||
207 | # spent 40µs (16+23) within Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:213] which was called:
# once (16µs+23µs) by HTTP::Server::PSGI::setup_listener at line 97 of HTTP/Server/PSGI.pm | ||||
208 | 1 | 500ns | my($args) = @_; | ||
209 | 1 | 700ns | my $name = $args->{server_software} || ref($args); # $args is $server | ||
210 | 1 | 800ns | my $host = $args->{host} || 0; | ||
211 | 1 | 400ns | my $proto = $args->{proto} || 'http'; | ||
212 | 1 | 41µs | 1 | 23µs | print STDERR "$name: Accepting connections at $proto://$host:$args->{port}/\n"; # spent 23µs making 1 call to Plack::Runner::CORE:print |
213 | 1 | 6µs | }; | ||
214 | |||||
215 | 1 | 3µs | $app; | ||
216 | } | ||||
217 | |||||
218 | # spent 624µs (15+610) within Plack::Runner::loader which was called:
# once (15µs+610µs) by Plack::Runner::run at line 273 | ||||
219 | 1 | 300ns | my $self = shift; | ||
220 | 1 | 9µs | 2 | 610µs | $self->{_loader} ||= Plack::Util::load_class($self->{loader}, 'Plack::Loader')->new; # spent 607µs making 1 call to Plack::Util::load_class
# spent 3µs making 1 call to Plack::Loader::new |
221 | } | ||||
222 | |||||
223 | # spent 24.7ms (7µs+24.7) within Plack::Runner::load_server which was called:
# once (7µs+24.7ms) by Plack::Runner::run at line 276 | ||||
224 | 1 | 300ns | my($self, $loader) = @_; | ||
225 | |||||
226 | 1 | 1µs | if ($self->{server}) { | ||
227 | return $loader->load($self->{server}, @{$self->{options}}); | ||||
228 | } else { | ||||
229 | 1 | 6µs | 1 | 24.7ms | return $loader->auto(@{$self->{options}}); # spent 24.7ms making 1 call to Plack::Loader::auto |
230 | } | ||||
231 | } | ||||
232 | |||||
233 | sub run { | ||||
234 | 1 | 800ns | my $self = shift; | ||
235 | |||||
236 | 1 | 1µs | unless (ref $self) { | ||
237 | $self = $self->new; | ||||
238 | $self->parse_options(@_); | ||||
239 | return $self->run; | ||||
240 | } | ||||
241 | |||||
242 | 1 | 1µs | unless ($self->{options}) { | ||
243 | $self->parse_options(); | ||||
244 | } | ||||
245 | |||||
246 | 1 | 2µs | my @args = @_ ? @_ : @{$self->{argv}}; | ||
247 | |||||
248 | 1 | 3µs | 1 | 9µs | $self->setup; # spent 9µs making 1 call to Plack::Runner::setup |
249 | |||||
250 | 1 | 3µs | 1 | 12µs | my $app = $self->locate_app(@args); # spent 12µs making 1 call to Plack::Runner::locate_app |
251 | |||||
252 | 1 | 800ns | if ($self->{path}) { | ||
253 | require Plack::App::URLMap; | ||||
254 | $app = build { | ||||
255 | my $urlmap = Plack::App::URLMap->new; | ||||
256 | $urlmap->mount($self->{path} => $_[0]); | ||||
257 | $urlmap->to_app; | ||||
258 | } $app; | ||||
259 | } | ||||
260 | |||||
261 | 1 | 8µs | $ENV{PLACK_ENV} ||= $self->{env} || 'development'; | ||
262 | 1 | 5µs | 1 | 16.8ms | if ($ENV{PLACK_ENV} eq 'development') { # spent 16.8ms making 1 call to Plack::Runner::prepare_devel |
263 | $app = $self->prepare_devel($app); | ||||
264 | } | ||||
265 | |||||
266 | 1 | 900ns | if ($self->{access_log}) { | ||
267 | open my $logfh, ">>", $self->{access_log} | ||||
268 | or die "open($self->{access_log}): $!"; | ||||
269 | $logfh->autoflush(1); | ||||
270 | $app = $self->apply_middleware($app, 'AccessLog', logger => sub { $logfh->print( @_ ) }); | ||||
271 | } | ||||
272 | |||||
273 | 1 | 2µs | 1 | 624µs | my $loader = $self->loader; # spent 624µs making 1 call to Plack::Runner::loader |
274 | 1 | 2µs | 1 | 543µs | $loader->preload_app($app); # spent 543µs making 1 call to Plack::Loader::preload_app |
275 | |||||
276 | 1 | 2µs | 1 | 24.7ms | my $server = $self->load_server($loader); # spent 24.7ms making 1 call to Plack::Runner::load_server |
277 | 1 | 3µs | $loader->run($server); | ||
278 | } | ||||
279 | |||||
280 | 1 | 5µs | 1; | ||
281 | |||||
282 | __END__ | ||||
# spent 10µs within Plack::Runner::CORE:match which was called 2 times, avg 5µs/call:
# 2 times (10µs+0s) by Plack::Runner::parse_options at line 33, avg 5µs/call | |||||
# spent 23µs within Plack::Runner::CORE:print which was called:
# once (23µs+0s) by Plack::Runner::__ANON__[/usr/local/share/perl/5.18.2/Plack/Runner.pm:213] at line 212 |