← 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:09 2016

Filename/usr/local/share/perl/5.18.2/Plack/Runner.pm
StatementsExecuted 104 statements in 4.99ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.83ms2.00msPlack::Runner::::BEGIN@5Plack::Runner::BEGIN@5
111127µs1.87msPlack::Runner::::parse_optionsPlack::Runner::parse_options
33140µs16.8msPlack::Runner::::apply_middlewarePlack::Runner::apply_middleware
11129µs80µsPlack::Runner::::BEGIN@166Plack::Runner::BEGIN@166
11126µs16.8msPlack::Runner::::prepare_develPlack::Runner::prepare_devel
11124µs59µsPlack::Runner::::BEGIN@167Plack::Runner::BEGIN@167
11123µs23µsPlack::Runner::::CORE:printPlack::Runner::CORE:print (opcode)
31119µs516µsPlack::Runner::::__ANON__[:193]Plack::Runner::__ANON__[:193]
31118µs18µsPlack::Runner::::buildPlack::Runner::build
32218µs710µsPlack::Runner::::__ANON__[:24]Plack::Runner::__ANON__[:24]
11116µs40µsPlack::Runner::::__ANON__[:213]Plack::Runner::__ANON__[:213]
11116µs16µsPlack::Runner::::mangle_host_port_socketPlack::Runner::mangle_host_port_socket
11115µs624µsPlack::Runner::::loaderPlack::Runner::loader
11113µs13µsPlack::Runner::::newPlack::Runner::new
11112µs12µsPlack::Runner::::locate_appPlack::Runner::locate_app
11111µs23µsPlack::Runner::::BEGIN@2Plack::Runner::BEGIN@2
21110µs10µsPlack::Runner::::CORE:matchPlack::Runner::CORE:match (opcode)
1119µs9µsPlack::Runner::::setupPlack::Runner::setup
1118µs40µsPlack::Runner::::BEGIN@6Plack::Runner::BEGIN@6
1117µs24.7msPlack::Runner::::load_serverPlack::Runner::load_server
1116µs9µsPlack::Runner::::BEGIN@3Plack::Runner::BEGIN@3
1114µs4µsPlack::Runner::::BEGIN@4Plack::Runner::BEGIN@4
1113µs3µsPlack::Runner::::__ANON__[:160]Plack::Runner::__ANON__[:160]
0000s0sPlack::Runner::::__ANON__[:122]Plack::Runner::__ANON__[:122]
0000s0sPlack::Runner::::__ANON__[:172]Plack::Runner::__ANON__[:172]
0000s0sPlack::Runner::::__ANON__[:179]Plack::Runner::__ANON__[:179]
0000s0sPlack::Runner::::__ANON__[:23]Plack::Runner::__ANON__[:23]
0000s0sPlack::Runner::::__ANON__[:258]Plack::Runner::__ANON__[:258]
0000s0sPlack::Runner::::__ANON__[:270]Plack::Runner::__ANON__[:270]
0000s0sPlack::Runner::::__ANON__[:54]Plack::Runner::__ANON__[:54]
0000s0sPlack::Runner::::__ANON__[:55]Plack::Runner::__ANON__[:55]
0000s0sPlack::Runner::::runPlack::Runner::run
0000s0sPlack::Runner::::set_optionsPlack::Runner::set_options
0000s0sPlack::Runner::::version_cbPlack::Runner::version_cb
0000s0sPlack::Runner::::watchPlack::Runner::watch
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Plack::Runner;
2220µs235µ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
use strict;
# spent 23µs making 1 call to Plack::Runner::BEGIN@2 # spent 12µs making 1 call to strict::import
3218µs213µ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
use warnings;
# spent 9µs making 1 call to Plack::Runner::BEGIN@3 # spent 4µs making 1 call to warnings::import
4215µs14µ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
use Carp ();
# spent 4µs making 1 call to Plack::Runner::BEGIN@4
5278µs12.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
use Plack::Util;
# spent 2.00ms making 1 call to Plack::Runner::BEGIN@5
622.72ms272µ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
use Try::Tiny;
# 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
sub new {
91900ns my $class = shift;
10116µ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
sub build(&;$) {
2232µs my $block = shift;
2331µs my $app = shift || sub { };
24627µs6692µ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
return sub { $block->($app->()) };
# 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
sub parse_options {
281500ns my $self = shift;
29
3014µs local @ARGV = @_;
31
32 # From 'prove': Allow cuddling the paths with -I, -M and -e
33336µs210µs @ARGV = map { /^(-[IMe])(.+)/ ? ($1,$2) : $_ } @ARGV;
# spent 10µs making 2 calls to Plack::Runner::CORE:match, avg 5µs/call
34
3511µs my($host, $port, $socket, @listen);
36
3712µs require Getopt::Long;
38113µs1149µ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]) },
56134µs11.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
641400ns my(@options, @argv);
6512µ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
8118µs116µ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
8211µs push @options, daemonize => 1 if $self->{daemonize};
83
8412µs $self->{options} = \@options;
85126µs $self->{argv} = \@argv;
86}
87
88sub 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
sub mangle_host_port_socket {
9412µs my($self, $host, $port, $socket, @listen) = @_;
95
9613µ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
10511µs unless (@listen) {
1061900ns if ($socket) {
107 @listen = ($socket);
108 } else {
1091300ns $port ||= 5000;
11013µs @listen = ($host ? "$host:$port" : ":$port");
111 }
112 }
113
114110µs return host => $host, port => $port, listen => \@listen, socket => $socket;
115}
116
117sub 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
sub setup {
1261500ns my $self = shift;
127
12812µs if ($self->{help}) {
129 require Pod::Usage;
130 Pod::Usage::pod2usage(0);
131 }
132
1331700ns if ($self->{version}) {
134 $self->version_cb->();
135 exit;
136 }
137
13811µs if (@{$self->{includes}}) {
139 require lib;
140 lib->import(@{$self->{includes}});
141 }
142
1431900ns if ($self->{eval}) {
144 push @{$self->{modules}}, 'Plack::Builder';
145 }
146
14719µ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
sub locate_app {
15511µs my($self, @args) = @_;
156
15712µs my $psgi = $self->{app} || $args[0];
158
159115µs if (ref $psgi eq 'CODE') {
16015µ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
return sub { $psgi };
161 }
162
163 if ($self->{eval}) {
164 $self->loader->watch("lib");
165 return build {
166276µs2131µ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
no strict;
# spent 80µs making 1 call to Plack::Runner::BEGIN@166 # spent 51µs making 1 call to strict::unimport
16721.65ms294µ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
no warnings;
# 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
182sub 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
sub apply_middleware {
19033µs my($self, $app, $class, @args) = @_;
191
19236µs316.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
193645µs6516µ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
build { $mw_class->wrap($_[0], @args) } $app;
# 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
sub prepare_devel {
19711µs my($self, $app) = @_;
198
19912µs if ($self->{default_middleware}) {
20014µs11.88ms $app = $self->apply_middleware($app, 'Lint');
# spent 1.88ms making 1 call to Plack::Runner::apply_middleware
20112µs18.63ms $app = $self->apply_middleware($app, 'StackTrace');
# spent 8.63ms making 1 call to Plack::Runner::apply_middleware
20214µs16.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
push @{$self->{options}}, server_ready => sub {
2081500ns my($args) = @_;
2091700ns my $name = $args->{server_software} || ref($args); # $args is $server
2101800ns my $host = $args->{host} || 0;
2111400ns my $proto = $args->{proto} || 'http';
212141µs123µs print STDERR "$name: Accepting connections at $proto://$host:$args->{port}/\n";
# spent 23µs making 1 call to Plack::Runner::CORE:print
21316µs };
214
21513µ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
sub loader {
2191300ns my $self = shift;
22019µs2610µ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
sub load_server {
2241300ns my($self, $loader) = @_;
225
22611µs if ($self->{server}) {
227 return $loader->load($self->{server}, @{$self->{options}});
228 } else {
22916µs124.7ms return $loader->auto(@{$self->{options}});
# spent 24.7ms making 1 call to Plack::Loader::auto
230 }
231}
232
233sub run {
2341800ns my $self = shift;
235
23611µs unless (ref $self) {
237 $self = $self->new;
238 $self->parse_options(@_);
239 return $self->run;
240 }
241
24211µs unless ($self->{options}) {
243 $self->parse_options();
244 }
245
24612µs my @args = @_ ? @_ : @{$self->{argv}};
247
24813µs19µs $self->setup;
# spent 9µs making 1 call to Plack::Runner::setup
249
25013µs112µs my $app = $self->locate_app(@args);
# spent 12µs making 1 call to Plack::Runner::locate_app
251
2521800ns 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
26118µs $ENV{PLACK_ENV} ||= $self->{env} || 'development';
26215µs116.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
2661900ns 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
27312µs1624µs my $loader = $self->loader;
# spent 624µs making 1 call to Plack::Runner::loader
27412µs1543µs $loader->preload_app($app);
# spent 543µs making 1 call to Plack::Loader::preload_app
275
27612µs124.7ms my $server = $self->load_server($loader);
# spent 24.7ms making 1 call to Plack::Runner::load_server
27713µs $loader->run($server);
278}
279
28015µs1;
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
sub Plack::Runner::CORE:match; # opcode
# 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
sub Plack::Runner::CORE:print; # opcode