| Filename | /usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm |
| Statements | Executed 10200165 statements in 50.7s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 300003 | 2 | 1 | 10.8s | 32.0s | HTTP::Server::PSGI::do_timeout |
| 100001 | 1 | 1 | 6.01s | 1011s | HTTP::Server::PSGI::handle_connection |
| 100001 | 1 | 1 | 5.51s | 38.6s | HTTP::Server::PSGI::_handle_response |
| 200002 | 2 | 1 | 3.50s | 26.4s | HTTP::Server::PSGI::write_all |
| 200002 | 1 | 1 | 2.22s | 20.6s | HTTP::Server::PSGI::write_timeout |
| 200002 | 1 | 1 | 1.30s | 9.88s | HTTP::Server::PSGI::__ANON__[:276] |
| 100001 | 1 | 1 | 1.28s | 14.9s | HTTP::Server::PSGI::read_timeout |
| 200002 | 1 | 1 | 1.22s | 1.22s | HTTP::Server::PSGI::CORE:match (opcode) |
| 200002 | 1 | 1 | 1.12s | 2.34s | HTTP::Server::PSGI::_encode |
| 100001 | 1 | 1 | 901ms | 903ms | HTTP::Server::PSGI::CORE:open (opcode) |
| 100001 | 1 | 1 | 726ms | 11.2s | HTTP::Server::PSGI::__ANON__[:224] |
| 100001 | 1 | 1 | 715ms | 9.26s | HTTP::Server::PSGI::__ANON__[:270] |
| 300003 | 1 | 1 | 625ms | 625ms | HTTP::Server::PSGI::__ANON__[:205] |
| 1 | 1 | 1 | 2.29ms | 2.63ms | HTTP::Server::PSGI::BEGIN@10 |
| 1 | 1 | 1 | 1.57ms | 14.3ms | HTTP::Server::PSGI::BEGIN@8 |
| 1 | 1 | 1 | 1.02ms | 1.12ms | HTTP::Server::PSGI::BEGIN@9 |
| 1 | 1 | 1 | 519µs | 966µs | HTTP::Server::PSGI::BEGIN@19 |
| 1 | 1 | 1 | 229µs | 297µs | HTTP::Server::PSGI::BEGIN@14 |
| 1 | 1 | 1 | 190µs | 935µs | HTTP::Server::PSGI::BEGIN@7 |
| 1 | 1 | 1 | 123µs | 162µs | HTTP::Server::PSGI::BEGIN@6 |
| 1 | 1 | 1 | 24µs | 333µs | HTTP::Server::PSGI::setup_listener |
| 1 | 1 | 1 | 15µs | 55µs | HTTP::Server::PSGI::BEGIN@11 |
| 1 | 1 | 1 | 9µs | 65µs | HTTP::Server::PSGI::BEGIN@22 |
| 1 | 1 | 1 | 9µs | 18µs | HTTP::Server::PSGI::BEGIN@2 |
| 1 | 1 | 1 | 8µs | 418µs | HTTP::Server::PSGI::BEGIN@16 |
| 1 | 1 | 1 | 8µs | 47µs | HTTP::Server::PSGI::BEGIN@31 |
| 1 | 1 | 1 | 8µs | 1.25ms | HTTP::Server::PSGI::BEGIN@15 |
| 1 | 1 | 1 | 7µs | 7µs | HTTP::Server::PSGI::new |
| 1 | 1 | 1 | 7µs | 32µs | HTTP::Server::PSGI::BEGIN@18 |
| 1 | 1 | 1 | 6µs | 10µs | HTTP::Server::PSGI::BEGIN@3 |
| 1 | 1 | 1 | 6µs | 28µs | HTTP::Server::PSGI::BEGIN@32 |
| 1 | 1 | 1 | 5µs | 5µs | HTTP::Server::PSGI::BEGIN@12 |
| 1 | 1 | 1 | 5µs | 5µs | HTTP::Server::PSGI::BEGIN@13 |
| 1 | 1 | 1 | 4µs | 4µs | HTTP::Server::PSGI::BEGIN@5 |
| 1 | 1 | 1 | 2µs | 2µs | HTTP::Server::PSGI::prepare_socket_class |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::__ANON__[:186] |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::__ANON__[:239] |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::__ANON__[:240] |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::__ANON__[:247] |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::__ANON__[:42] |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::accept_loop |
| 0 | 0 | 0 | 0s | 0s | HTTP::Server::PSGI::run |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package HTTP::Server::PSGI; | ||||
| 2 | 2 | 19µs | 2 | 26µs | # spent 18µs (9+9) within HTTP::Server::PSGI::BEGIN@2 which was called:
# once (9µs+9µs) by parent::import at line 2 # spent 18µs making 1 call to HTTP::Server::PSGI::BEGIN@2
# spent 9µs making 1 call to strict::import |
| 3 | 2 | 21µs | 2 | 13µs | # spent 10µs (6+3) within HTTP::Server::PSGI::BEGIN@3 which was called:
# once (6µs+3µs) by parent::import at line 3 # spent 10µs making 1 call to HTTP::Server::PSGI::BEGIN@3
# spent 3µs making 1 call to warnings::import |
| 4 | |||||
| 5 | 2 | 18µs | 1 | 4µs | # spent 4µs within HTTP::Server::PSGI::BEGIN@5 which was called:
# once (4µs+0s) by parent::import at line 5 # spent 4µs making 1 call to HTTP::Server::PSGI::BEGIN@5 |
| 6 | 2 | 89µs | 1 | 162µs | # spent 162µs (123+39) within HTTP::Server::PSGI::BEGIN@6 which was called:
# once (123µs+39µs) by parent::import at line 6 # spent 162µs making 1 call to HTTP::Server::PSGI::BEGIN@6 |
| 7 | 2 | 91µs | 2 | 966µs | # spent 935µs (190+745) within HTTP::Server::PSGI::BEGIN@7 which was called:
# once (190µs+745µs) by parent::import at line 7 # spent 935µs making 1 call to HTTP::Server::PSGI::BEGIN@7
# spent 31µs making 1 call to Exporter::import |
| 8 | 2 | 120µs | 2 | 14.8ms | # spent 14.3ms (1.57+12.7) within HTTP::Server::PSGI::BEGIN@8 which was called:
# once (1.57ms+12.7ms) by parent::import at line 8 # spent 14.3ms making 1 call to HTTP::Server::PSGI::BEGIN@8
# spent 518µs making 1 call to IO::Socket::import |
| 9 | 2 | 149µs | 2 | 1.15ms | # spent 1.12ms (1.02+98µs) within HTTP::Server::PSGI::BEGIN@9 which was called:
# once (1.02ms+98µs) by parent::import at line 9 # spent 1.12ms making 1 call to HTTP::Server::PSGI::BEGIN@9
# spent 29µs making 1 call to Exporter::import |
| 10 | 2 | 109µs | 2 | 2.81ms | # spent 2.63ms (2.29+341µs) within HTTP::Server::PSGI::BEGIN@10 which was called:
# once (2.29ms+341µs) by parent::import at line 10 # spent 2.63ms making 1 call to HTTP::Server::PSGI::BEGIN@10
# spent 185µs making 1 call to Exporter::import |
| 11 | 2 | 25µs | 2 | 64µs | # spent 55µs (15+41) within HTTP::Server::PSGI::BEGIN@11 which was called:
# once (15µs+41µs) by parent::import at line 11 # spent 55µs making 1 call to HTTP::Server::PSGI::BEGIN@11
# spent 8µs making 1 call to List::Util::import |
| 12 | 2 | 28µs | 1 | 5µs | # spent 5µs within HTTP::Server::PSGI::BEGIN@12 which was called:
# once (5µs+0s) by parent::import at line 12 # spent 5µs making 1 call to HTTP::Server::PSGI::BEGIN@12 |
| 13 | 2 | 28µs | 1 | 5µs | # spent 5µs within HTTP::Server::PSGI::BEGIN@13 which was called:
# once (5µs+0s) by parent::import at line 13 # spent 5µs making 1 call to HTTP::Server::PSGI::BEGIN@13 |
| 14 | 2 | 109µs | 1 | 297µs | # spent 297µs (229+68) within HTTP::Server::PSGI::BEGIN@14 which was called:
# once (229µs+68µs) by parent::import at line 14 # spent 297µs making 1 call to HTTP::Server::PSGI::BEGIN@14 |
| 15 | 2 | 29µs | 2 | 2.48ms | # spent 1.25ms (8µs+1.24) within HTTP::Server::PSGI::BEGIN@15 which was called:
# once (8µs+1.24ms) by parent::import at line 15 # spent 1.25ms making 1 call to HTTP::Server::PSGI::BEGIN@15
# spent 1.24ms making 1 call to POSIX::import |
| 16 | 2 | 24µs | 2 | 828µs | # spent 418µs (8+410) within HTTP::Server::PSGI::BEGIN@16 which was called:
# once (8µs+410µs) by parent::import at line 16 # spent 418µs making 1 call to HTTP::Server::PSGI::BEGIN@16
# spent 410µs making 1 call to Exporter::import |
| 17 | |||||
| 18 | 2 | 22µs | 2 | 56µs | # spent 32µs (7+25) within HTTP::Server::PSGI::BEGIN@18 which was called:
# once (7µs+25µs) by parent::import at line 18 # spent 32µs making 1 call to HTTP::Server::PSGI::BEGIN@18
# spent 25µs making 1 call to Exporter::import |
| 19 | 2 | 145µs | 2 | 1.14ms | # spent 966µs (519+447) within HTTP::Server::PSGI::BEGIN@19 which was called:
# once (519µs+447µs) by parent::import at line 19 # spent 966µs making 1 call to HTTP::Server::PSGI::BEGIN@19
# spent 178µs making 1 call to Time::HiRes::import |
| 20 | |||||
| 21 | 1 | 200ns | my $alarm_interval; | ||
| 22 | # spent 65µs (9+56) within HTTP::Server::PSGI::BEGIN@22 which was called:
# once (9µs+56µs) by parent::import at line 29 | ||||
| 23 | 1 | 4µs | if ($^O eq 'MSWin32') { | ||
| 24 | $alarm_interval = 1; | ||||
| 25 | } else { | ||||
| 26 | 1 | 1µs | 1 | 56µs | Time::HiRes->import('alarm'); # spent 56µs making 1 call to Time::HiRes::import |
| 27 | 1 | 300ns | $alarm_interval = 0.1; | ||
| 28 | } | ||||
| 29 | 1 | 21µs | 1 | 65µs | } # spent 65µs making 1 call to HTTP::Server::PSGI::BEGIN@22 |
| 30 | |||||
| 31 | 2 | 27µs | 2 | 86µs | # spent 47µs (8+39) within HTTP::Server::PSGI::BEGIN@31 which was called:
# once (8µs+39µs) by parent::import at line 31 # spent 47µs making 1 call to HTTP::Server::PSGI::BEGIN@31
# spent 39µs making 1 call to constant::import |
| 32 | 2 | 1.27ms | 2 | 51µs | # spent 28µs (6+23) within HTTP::Server::PSGI::BEGIN@32 which was called:
# once (6µs+23µs) by parent::import at line 32 # spent 28µs making 1 call to HTTP::Server::PSGI::BEGIN@32
# spent 23µs making 1 call to constant::import |
| 33 | |||||
| 34 | # spent 7µs within HTTP::Server::PSGI::new which was called:
# once (7µs+0s) by Plack::Handler::HTTP::Server::PSGI::_server at line 19 of Plack/Handler/HTTP/Server/PSGI.pm | ||||
| 35 | 1 | 1µs | my($class, %args) = @_; | ||
| 36 | |||||
| 37 | my $self = bless { | ||||
| 38 | host => $args{host} || 0, | ||||
| 39 | port => $args{port} || 8080, | ||||
| 40 | timeout => $args{timeout} || 300, | ||||
| 41 | server_software => $args{server_software} || $class, | ||||
| 42 | server_ready => $args{server_ready} || sub {}, | ||||
| 43 | 1 | 4µs | ssl => $args{ssl}, | ||
| 44 | ipv6 => $args{ipv6}, | ||||
| 45 | ssl_key_file => $args{ssl_key_file}, | ||||
| 46 | ssl_cert_file => $args{ssl_cert_file}, | ||||
| 47 | }, $class; | ||||
| 48 | |||||
| 49 | 1 | 4µs | $self; | ||
| 50 | } | ||||
| 51 | |||||
| 52 | sub run { | ||||
| 53 | 1 | 300ns | my($self, $app) = @_; | ||
| 54 | 1 | 3µs | 1 | 333µs | $self->setup_listener(); # spent 333µs making 1 call to HTTP::Server::PSGI::setup_listener |
| 55 | 1 | 2µs | $self->accept_loop($app); | ||
| 56 | } | ||||
| 57 | |||||
| 58 | # spent 2µs within HTTP::Server::PSGI::prepare_socket_class which was called:
# once (2µs+0s) by HTTP::Server::PSGI::setup_listener at line 93 | ||||
| 59 | 1 | 200ns | my($self, $args) = @_; | ||
| 60 | |||||
| 61 | 1 | 300ns | if ($self->{ssl} && $self->{ipv6}) { | ||
| 62 | Carp::croak("SSL and IPv6 are not supported at the same time (yet). Choose one."); | ||||
| 63 | } | ||||
| 64 | |||||
| 65 | 1 | 300ns | if ($self->{ssl}) { | ||
| 66 | eval { require IO::Socket::SSL; 1 } | ||||
| 67 | or Carp::croak("SSL suport requires IO::Socket::SSL"); | ||||
| 68 | $args->{SSL_key_file} = $self->{ssl_key_file}; | ||||
| 69 | $args->{SSL_cert_file} = $self->{ssl_cert_file}; | ||||
| 70 | return "IO::Socket::SSL"; | ||||
| 71 | } elsif ($self->{ipv6}) { | ||||
| 72 | eval { require IO::Socket::IP; 1 } | ||||
| 73 | or Carp::croak("IPv6 support requires IO::Socket::IP"); | ||||
| 74 | $self->{host} ||= '::'; | ||||
| 75 | $args->{LocalAddr} ||= '::'; | ||||
| 76 | return "IO::Socket::IP"; | ||||
| 77 | } | ||||
| 78 | |||||
| 79 | 1 | 4µs | return "IO::Socket::INET"; | ||
| 80 | } | ||||
| 81 | |||||
| 82 | # spent 333µs (24+310) within HTTP::Server::PSGI::setup_listener which was called:
# once (24µs+310µs) by HTTP::Server::PSGI::run at line 54 | ||||
| 83 | 1 | 200ns | my $self = shift; | ||
| 84 | |||||
| 85 | 1 | 3µs | my %args = ( | ||
| 86 | Listen => SOMAXCONN, | ||||
| 87 | LocalPort => $self->{port}, | ||||
| 88 | LocalAddr => $self->{host}, | ||||
| 89 | Proto => 'tcp', | ||||
| 90 | ReuseAddr => 1, | ||||
| 91 | ); | ||||
| 92 | |||||
| 93 | 1 | 1µs | 1 | 2µs | my $class = $self->prepare_socket_class(\%args); # spent 2µs making 1 call to HTTP::Server::PSGI::prepare_socket_class |
| 94 | 1 | 4µs | 1 | 268µs | $self->{listen_sock} ||= $class->new(%args) # spent 268µs making 1 call to IO::Socket::INET::new |
| 95 | or die "failed to listen to port $self->{port}: $!"; | ||||
| 96 | |||||
| 97 | 1 | 12µs | 1 | 40µs | $self->{server_ready}->({ %$self, proto => $self->{ssl} ? 'https' : 'http' }); # spent 40µs making 1 call to Plack::Runner::__ANON__[Plack/Runner.pm:213] |
| 98 | } | ||||
| 99 | |||||
| 100 | sub accept_loop { | ||||
| 101 | 1 | 500ns | my($self, $app) = @_; | ||
| 102 | |||||
| 103 | 1 | 8µs | 1 | 47µs | $app = Plack::Middleware::ContentLength->wrap($app); # spent 47µs making 1 call to Plack::Middleware::wrap |
| 104 | |||||
| 105 | 1 | 200ns | while (1) { | ||
| 106 | 100002 | 663ms | local $SIG{PIPE} = 'IGNORE'; | ||
| 107 | 100002 | 2.69s | 200002 | 19.4s | if (my $conn = $self->{listen_sock}->accept) { # spent 17.4s making 100001 calls to IO::Socket::accept, avg 174µs/call
# spent 1.94s making 100001 calls to Hash::MultiValue::DESTROY, avg 19µs/call |
| 108 | 100001 | 462ms | 100001 | 1.32s | $conn->setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) # spent 1.32s making 100001 calls to IO::Socket::setsockopt, avg 13µs/call |
| 109 | or die "setsockopt(TCP_NODELAY) failed:$!"; | ||||
| 110 | 100001 | 2.67s | 200002 | 7.86s | my $env = { # spent 5.70s making 100001 calls to IO::Socket::INET::peerhost, avg 57µs/call
# spent 2.16s making 100001 calls to IO::Socket::INET::peerport, avg 22µs/call |
| 111 | SERVER_PORT => $self->{port}, | ||||
| 112 | SERVER_NAME => $self->{host}, | ||||
| 113 | SCRIPT_NAME => '', | ||||
| 114 | REMOTE_ADDR => $conn->peerhost, | ||||
| 115 | REMOTE_PORT => $conn->peerport || 0, | ||||
| 116 | 'psgi.version' => [ 1, 1 ], | ||||
| 117 | 'psgi.errors' => *STDERR, | ||||
| 118 | 'psgi.url_scheme' => $self->{ssl} ? 'https' : 'http', | ||||
| 119 | 'psgi.run_once' => Plack::Util::FALSE, | ||||
| 120 | 'psgi.multithread' => Plack::Util::FALSE, | ||||
| 121 | 'psgi.multiprocess' => Plack::Util::FALSE, | ||||
| 122 | 'psgi.streaming' => Plack::Util::TRUE, | ||||
| 123 | 'psgi.nonblocking' => Plack::Util::FALSE, | ||||
| 124 | 'psgix.harakiri' => Plack::Util::TRUE, | ||||
| 125 | 'psgix.input.buffered' => Plack::Util::TRUE, | ||||
| 126 | 'psgix.io' => $conn, | ||||
| 127 | }; | ||||
| 128 | |||||
| 129 | 100001 | 303ms | 100001 | 1011s | $self->handle_connection($env, $conn, $app); # spent 1011s making 100001 calls to HTTP::Server::PSGI::handle_connection, avg 10.1ms/call |
| 130 | 100001 | 499ms | 100001 | 5.14s | $conn->close; # spent 5.14s making 100001 calls to IO::Socket::close, avg 51µs/call |
| 131 | 100001 | 3.32s | last if $env->{'psgix.harakiri.commit'}; | ||
| 132 | } | ||||
| 133 | } | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | # spent 1011s (6.01+1005) within HTTP::Server::PSGI::handle_connection which was called 100001 times, avg 10.1ms/call:
# 100001 times (6.01s+1005s) by HTTP::Server::PSGI::accept_loop at line 129, avg 10.1ms/call | ||||
| 137 | 100001 | 75.8ms | my($self, $env, $conn, $app) = @_; | ||
| 138 | |||||
| 139 | 100001 | 73.8ms | my $buf = ''; | ||
| 140 | 100001 | 312ms | my $res = [ 400, [ 'Content-Type' => 'text/plain' ], [ 'Bad Request' ] ]; | ||
| 141 | |||||
| 142 | 100001 | 37.4ms | while (1) { | ||
| 143 | 100001 | 690ms | 100001 | 14.9s | my $rlen = $self->read_timeout( # spent 14.9s making 100001 calls to HTTP::Server::PSGI::read_timeout, avg 149µs/call |
| 144 | $conn, \$buf, MAX_REQUEST_SIZE - length($buf), length($buf), | ||||
| 145 | $self->{timeout}, | ||||
| 146 | ) or return; | ||||
| 147 | 100001 | 2.18s | 100001 | 1.57s | my $reqlen = parse_http_request($buf, $env); # spent 1.57s making 100001 calls to HTTP::Parser::XS::parse_http_request, avg 16µs/call |
| 148 | 100001 | 96.2ms | if ($reqlen >= 0) { | ||
| 149 | 100001 | 122ms | $buf = substr $buf, $reqlen; | ||
| 150 | 100001 | 170ms | if (my $cl = $env->{CONTENT_LENGTH}) { | ||
| 151 | my $buffer = Stream::Buffered->new($cl); | ||||
| 152 | while ($cl > 0) { | ||||
| 153 | my $chunk; | ||||
| 154 | if (length $buf) { | ||||
| 155 | $chunk = $buf; | ||||
| 156 | $buf = ''; | ||||
| 157 | } else { | ||||
| 158 | $self->read_timeout($conn, \$chunk, $cl, 0, $self->{timeout}) | ||||
| 159 | or return; | ||||
| 160 | } | ||||
| 161 | $buffer->print($chunk); | ||||
| 162 | $cl -= length $chunk; | ||||
| 163 | } | ||||
| 164 | $env->{'psgi.input'} = $buffer->rewind; | ||||
| 165 | } else { | ||||
| 166 | 100003 | 1.87s | 100002 | 903ms | open my $input, "<", \$buf; # spent 903ms making 100001 calls to HTTP::Server::PSGI::CORE:open, avg 9µs/call
# spent 572µs making 1 call to PerlIO::import |
| 167 | 100001 | 250ms | $env->{'psgi.input'} = $input; | ||
| 168 | } | ||||
| 169 | |||||
| 170 | 100001 | 856ms | 100001 | 950s | $res = Plack::Util::run_app $app, $env; # spent 950s making 100001 calls to Plack::Util::run_app, avg 9.50ms/call |
| 171 | 100001 | 231ms | last; | ||
| 172 | } | ||||
| 173 | if ($reqlen == -2) { | ||||
| 174 | # request is incomplete, do nothing | ||||
| 175 | } elsif ($reqlen == -1) { | ||||
| 176 | # error, close conn | ||||
| 177 | last; | ||||
| 178 | } | ||||
| 179 | } | ||||
| 180 | |||||
| 181 | 100001 | 454ms | 100001 | 38.6s | if (ref $res eq 'ARRAY') { # spent 38.6s making 100001 calls to HTTP::Server::PSGI::_handle_response, avg 386µs/call |
| 182 | $self->_handle_response($res, $conn); | ||||
| 183 | } elsif (ref $res eq 'CODE') { | ||||
| 184 | $res->(sub { | ||||
| 185 | $self->_handle_response($_[0], $conn); | ||||
| 186 | }); | ||||
| 187 | } else { | ||||
| 188 | die "Bad response $res"; | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | 100001 | 808ms | return; | ||
| 192 | } | ||||
| 193 | |||||
| 194 | # spent 38.6s (5.51+33.1) within HTTP::Server::PSGI::_handle_response which was called 100001 times, avg 386µs/call:
# 100001 times (5.51s+33.1s) by HTTP::Server::PSGI::handle_connection at line 181, avg 386µs/call | ||||
| 195 | 100001 | 60.5ms | my($self, $res, $conn) = @_; | ||
| 196 | |||||
| 197 | my @lines = ( | ||||
| 198 | 100001 | 777ms | 100001 | 1.14s | "Date: @{[HTTP::Date::time2str()]}\015\012", # spent 1.14s making 100001 calls to HTTP::Date::time2str, avg 11µs/call |
| 199 | "Server: $self->{server_software}\015\012", | ||||
| 200 | ); | ||||
| 201 | |||||
| 202 | # spent 625ms within HTTP::Server::PSGI::__ANON__[/usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm:205] which was called 300003 times, avg 2µs/call:
# 300003 times (625ms+0s) by Plack::Util::header_iter at line 169 of Plack/Util.pm, avg 2µs/call | ||||
| 203 | 300003 | 152ms | my ($k, $v) = @_; | ||
| 204 | 300003 | 1.75s | push @lines, "$k: $v\015\012"; | ||
| 205 | 100001 | 689ms | 100001 | 2.98s | }); # spent 2.98s making 100001 calls to Plack::Util::header_iter, avg 30µs/call |
| 206 | |||||
| 207 | 100001 | 571ms | 100001 | 321ms | unshift @lines, "HTTP/1.0 $res->[0] @{[ HTTP::Status::status_message($res->[0]) ]}\015\012"; # spent 321ms making 100001 calls to HTTP::Status::status_message, avg 3µs/call |
| 208 | 100001 | 72.3ms | push @lines, "\015\012"; | ||
| 209 | |||||
| 210 | 100001 | 384ms | 100001 | 16.0s | $self->write_all($conn, join('', @lines), $self->{timeout}) # spent 16.0s making 100001 calls to HTTP::Server::PSGI::write_all, avg 160µs/call |
| 211 | or return; | ||||
| 212 | |||||
| 213 | 100001 | 724ms | if (defined $res->[2]) { | ||
| 214 | 100001 | 32.2ms | my $err; | ||
| 215 | 100001 | 24.3ms | my $done; | ||
| 216 | { | ||||
| 217 | 200002 | 104ms | local $@; | ||
| 218 | 100001 | 116ms | eval { | ||
| 219 | Plack::Util::foreach( | ||||
| 220 | $res->[2], | ||||
| 221 | # spent 11.2s (726ms+10.5) within HTTP::Server::PSGI::__ANON__[/usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm:224] which was called 100001 times, avg 112µs/call:
# 100001 times (726ms+10.5s) by Plack::Util::foreach at line 94 of Plack/Util.pm, avg 112µs/call | ||||
| 222 | 100001 | 944ms | 100001 | 10.5s | $self->write_all($conn, $_[0], $self->{timeout}) # spent 10.5s making 100001 calls to HTTP::Server::PSGI::write_all, avg 105µs/call |
| 223 | or die "failed to send all data\n"; | ||||
| 224 | }, | ||||
| 225 | 100001 | 918ms | 100001 | 12.7s | ); # spent 12.7s making 100001 calls to Plack::Util::foreach, avg 127µs/call |
| 226 | 100001 | 70.0ms | $done = 1; | ||
| 227 | }; | ||||
| 228 | 100001 | 75.6ms | $err = $@; | ||
| 229 | }; | ||||
| 230 | 100001 | 51.1ms | unless ($done) { | ||
| 231 | if ($err =~ /^failed to send all data\n/) { | ||||
| 232 | return; | ||||
| 233 | } else { | ||||
| 234 | die $err; | ||||
| 235 | } | ||||
| 236 | } | ||||
| 237 | } else { | ||||
| 238 | return Plack::Util::inline_object | ||||
| 239 | write => sub { $self->write_all($conn, $_[0], $self->{timeout}) }, | ||||
| 240 | close => sub { }; | ||||
| 241 | } | ||||
| 242 | } | ||||
| 243 | |||||
| 244 | # returns 1 if socket is ready, undef on timeout | ||||
| 245 | sub do_timeout { | ||||
| 246 | 300003 | 145ms | my ($self, $cb, $timeout) = @_; | ||
| 247 | 300003 | 2.38s | local $SIG{ALRM} = sub {}; | ||
| 248 | 300003 | 2.04s | 300003 | 544ms | my $wait_until = time + $timeout; # spent 544ms making 300003 calls to Time::HiRes::time, avg 2µs/call |
| 249 | 300003 | 2.05s | 300003 | 924ms | alarm($timeout); # spent 924ms making 300003 calls to Time::HiRes::alarm, avg 3µs/call |
| 250 | 300003 | 54.1ms | my $ret; | ||
| 251 | 300003 | 58.8ms | while (1) { | ||
| 252 | 300003 | 568ms | 300003 | 19.1s | if ($ret = $cb->()) { # spent 9.88s making 200002 calls to HTTP::Server::PSGI::__ANON__[HTTP/Server/PSGI.pm:276], avg 49µs/call
# spent 9.26s making 100001 calls to HTTP::Server::PSGI::__ANON__[HTTP/Server/PSGI.pm:270], avg 93µs/call |
| 253 | 300003 | 240ms | last; | ||
| 254 | } elsif (! (! defined($ret) && $! == EINTR)) { | ||||
| 255 | undef $ret; | ||||
| 256 | last; | ||||
| 257 | } | ||||
| 258 | # got EINTR | ||||
| 259 | my $left = $wait_until - time; | ||||
| 260 | last if $left <= 0; | ||||
| 261 | alarm($left + $alarm_interval); | ||||
| 262 | } | ||||
| 263 | 300003 | 1.79s | 300003 | 600ms | alarm(0); # spent 600ms making 300003 calls to Time::HiRes::alarm, avg 2µs/call |
| 264 | 300003 | 3.02s | $ret; | ||
| 265 | } | ||||
| 266 | |||||
| 267 | # returns (positive) number of bytes read, or undef if the socket is to be closed | ||||
| 268 | # spent 14.9s (1.28+13.6) within HTTP::Server::PSGI::read_timeout which was called 100001 times, avg 149µs/call:
# 100001 times (1.28s+13.6s) by HTTP::Server::PSGI::handle_connection at line 143, avg 149µs/call | ||||
| 269 | 100001 | 101ms | my ($self, $sock, $buf, $len, $off, $timeout) = @_; | ||
| 270 | 200002 | 2.14s | 200002 | 22.2s | # spent 9.26s (715ms+8.55) within HTTP::Server::PSGI::__ANON__[/usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm:270] which was called 100001 times, avg 93µs/call:
# 100001 times (715ms+8.55s) by HTTP::Server::PSGI::do_timeout at line 252, avg 93µs/call # spent 13.6s making 100001 calls to HTTP::Server::PSGI::do_timeout, avg 136µs/call
# spent 8.55s making 100001 calls to IO::Handle::sysread, avg 85µs/call |
| 271 | } | ||||
| 272 | |||||
| 273 | # returns (positive) number of bytes written, or undef if the socket is to be closed | ||||
| 274 | # spent 20.6s (2.22+18.4) within HTTP::Server::PSGI::write_timeout which was called 200002 times, avg 103µs/call:
# 200002 times (2.22s+18.4s) by HTTP::Server::PSGI::write_all at line 286, avg 103µs/call | ||||
| 275 | 200002 | 395ms | my ($self, $sock, $buf, $len, $off, $timeout) = @_; | ||
| 276 | 400004 | 3.56s | 400004 | 27.0s | # spent 9.88s (1.30+8.58) within HTTP::Server::PSGI::__ANON__[/usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm:276] which was called 200002 times, avg 49µs/call:
# 200002 times (1.30s+8.58s) by HTTP::Server::PSGI::do_timeout at line 252, avg 49µs/call # spent 18.4s making 200002 calls to HTTP::Server::PSGI::do_timeout, avg 92µs/call
# spent 8.58s making 200002 calls to IO::Handle::syswrite, avg 43µs/call |
| 277 | } | ||||
| 278 | |||||
| 279 | # writes all data in buf and returns number of bytes written or undef if failed | ||||
| 280 | # spent 26.4s (3.50+22.9) within HTTP::Server::PSGI::write_all which was called 200002 times, avg 132µs/call:
# 100001 times (1.95s+14.0s) by HTTP::Server::PSGI::_handle_response at line 210, avg 160µs/call
# 100001 times (1.55s+8.94s) by HTTP::Server::PSGI::__ANON__[/usr/local/share/perl/5.18.2/HTTP/Server/PSGI.pm:224] at line 222, avg 105µs/call | ||||
| 281 | 200002 | 170ms | my ($self, $sock, $buf, $timeout) = @_; | ||
| 282 | 200002 | 72.7ms | return 0 unless defined $buf; | ||
| 283 | 200002 | 274ms | 200002 | 2.34s | _encode($buf); # spent 2.34s making 200002 calls to HTTP::Server::PSGI::_encode, avg 12µs/call |
| 284 | 200002 | 70.0ms | my $off = 0; | ||
| 285 | 200002 | 481ms | while (my $len = length($buf) - $off) { | ||
| 286 | 200002 | 743ms | 200002 | 20.6s | my $ret = $self->write_timeout($sock, $buf, $len, $off, $timeout) # spent 20.6s making 200002 calls to HTTP::Server::PSGI::write_timeout, avg 103µs/call |
| 287 | or return; | ||||
| 288 | 200002 | 133ms | $off += $ret; | ||
| 289 | } | ||||
| 290 | 200002 | 1.12s | return length $buf; | ||
| 291 | } | ||||
| 292 | |||||
| 293 | # syswrite() will crash when given wide characters | ||||
| 294 | # spent 2.34s (1.12+1.22) within HTTP::Server::PSGI::_encode which was called 200002 times, avg 12µs/call:
# 200002 times (1.12s+1.22s) by HTTP::Server::PSGI::write_all at line 283, avg 12µs/call | ||||
| 295 | 200002 | 2.77s | 200002 | 1.22s | if ($_[0] =~ /[^\x00-\xff]/) { # spent 1.22s making 200002 calls to HTTP::Server::PSGI::CORE:match, avg 6µs/call |
| 296 | Carp::carp("Wide character outside byte range in response. Encoding data as UTF-8"); | ||||
| 297 | utf8::encode($_[0]); | ||||
| 298 | } | ||||
| 299 | } | ||||
| 300 | |||||
| 301 | 1 | 3µs | 1; | ||
| 302 | |||||
| 303 | __END__ | ||||
# spent 1.22s within HTTP::Server::PSGI::CORE:match which was called 200002 times, avg 6µs/call:
# 200002 times (1.22s+0s) by HTTP::Server::PSGI::_encode at line 295, avg 6µs/call | |||||
# spent 903ms (901+1.09) within HTTP::Server::PSGI::CORE:open which was called 100001 times, avg 9µs/call:
# 100001 times (901ms+1.09ms) by HTTP::Server::PSGI::handle_connection at line 166, avg 9µs/call |