| File | /usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm |
| Statements Executed | 7239 |
| Statement Execution Time | 15.2s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 140 | 1 | 2 | 15.2s | 15.2s | LWP::Protocol::http::SocketMethods::CORE:sselect (opcode) |
| 41 | 1 | 1 | 10.8ms | 15.5s | LWP::Protocol::http::request |
| 140 | 2 | 1 | 3.25ms | 15.2s | LWP::Protocol::http::SocketMethods::can_read |
| 101 | 2 | 1 | 1.83ms | 15.2s | LWP::Protocol::http::SocketMethods::sysread |
| 1 | 1 | 1 | 1.39ms | 1.48ms | LWP::Protocol::http::BEGIN@216 |
| 101 | 1 | 2 | 1.25ms | 1.25ms | LWP::Protocol::http::SocketMethods::CORE:sysread (opcode) |
| 98 | 2 | 1 | 958µs | 87.2ms | LWP::Protocol::http::__ANON__[:394] |
| 123 | 1 | 1 | 843µs | 912µs | LWP::Protocol::http::__ANON__[:167] |
| 41 | 1 | 1 | 836µs | 184ms | LWP::Protocol::http::_new_socket |
| 41 | 1 | 1 | 777µs | 5.73ms | LWP::Protocol::http::_get_sock_info |
| 41 | 1 | 1 | 574µs | 1.75ms | LWP::Protocol::http::_fixup_header |
| 41 | 1 | 2 | 295µs | 295µs | LWP::Protocol::http::CORE:sselect (opcode) |
| 205 | 5 | 2 | 263µs | 263µs | LWP::Protocol::http::CORE:match (opcode) |
| 41 | 1 | 1 | 190µs | 190µs | LWP::Protocol::http::SocketMethods::increment_response_count |
| 81 | 2 | 1 | 185µs | 185µs | LWP::Protocol::http::socket_type |
| 287 | 3 | 2 | 97µs | 97µs | LWP::Protocol::http::CORE:subst (opcode) |
| 41 | 1 | 1 | 71µs | 71µs | LWP::Protocol::http::_check_sock |
| 1 | 1 | 1 | 15µs | 18µs | LWP::Protocol::http::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 35µs | LWP::Protocol::http::Socket::BEGIN@472 |
| 2 | 1 | 1 | 8µs | 8µs | LWP::Protocol::http::socket_class |
| 1 | 1 | 1 | 7µs | 39µs | LWP::Protocol::http::BEGIN@9 |
| 2 | 1 | 1 | 4µs | 4µs | LWP::Protocol::http::_extra_sock_opts |
| 0 | 0 | 0 | 0s | 0s | LWP::Protocol::http::SocketMethods::ping |
| 0 | 0 | 0 | 0s | 0s | LWP::Protocol::http::hlist_remove |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package LWP::Protocol::http; | ||||
| 2 | |||||
| 3 | 3 | 44µs | 2 | 21µs | # spent 18µs (15+3) within LWP::Protocol::http::BEGIN@3 which was called
# once (15µs+3µs) by LWP::Protocol::implementor at line 3 # spent 18µs making 1 call to LWP::Protocol::http::BEGIN@3
# spent 3µs making 1 call to strict::import |
| 4 | |||||
| 5 | 1 | 600ns | require HTTP::Response; | ||
| 6 | 1 | 300ns | require HTTP::Status; | ||
| 7 | 1 | 81µs | require Net::HTTP; | ||
| 8 | |||||
| 9 | 3 | 792µs | 2 | 72µs | # spent 39µs (7+32) within LWP::Protocol::http::BEGIN@9 which was called
# once (7µs+32µs) by LWP::Protocol::implementor at line 9 # spent 39µs making 1 call to LWP::Protocol::http::BEGIN@9
# spent 32µs making 1 call to vars::import |
| 10 | |||||
| 11 | 1 | 600ns | require LWP::Protocol; | ||
| 12 | 1 | 12µs | @ISA = qw(LWP::Protocol); | ||
| 13 | |||||
| 14 | 1 | 700ns | my $CRLF = "\015\012"; | ||
| 15 | |||||
| 16 | sub _new_socket | ||||
| 17 | # spent 184ms (836µs+183) within LWP::Protocol::http::_new_socket which was called 41 times, avg 4.48ms/call:
# 41 times (836µs+183ms) by LWP::Protocol::http::request at line 155, avg 4.48ms/call | ||||
| 18 | 41 | 64µs | my($self, $host, $port, $timeout) = @_; | ||
| 19 | 41 | 41µs | my $conn_cache = $self->{ua}{conn_cache}; | ||
| 20 | 41 | 21µs | if ($conn_cache) { | ||
| 21 | 41 | 242µs | 82 | 511µs | if (my $sock = $conn_cache->withdraw($self->socket_type, "$host:$port")) { # spent 447µs making 41 calls to LWP::ConnCache::withdraw, avg 11µs/call
# spent 64µs making 41 calls to LWP::Protocol::http::socket_type, avg 2µs/call |
| 22 | 39 | 275µs | 39 | 851µs | return $sock if $sock && !$sock->can_read(0); # spent 851µs making 39 calls to LWP::Protocol::http::SocketMethods::can_read, avg 22µs/call |
| 23 | # if the socket is readable, then either the peer has closed the | ||||
| 24 | # connection or there are some garbage bytes on it. In either | ||||
| 25 | # case we abandon it. | ||||
| 26 | $sock->close; | ||||
| 27 | } | ||||
| 28 | } | ||||
| 29 | |||||
| 30 | 2 | 7µs | local($^W) = 0; # IO::Socket::INET can be noisy | ||
| 31 | 2 | 34µs | 6 | 181ms | my $sock = $self->socket_class->new(PeerAddr => $host, # spent 181ms making 2 calls to Net::HTTP::new, avg 90.7ms/call
# spent 8µs making 2 calls to LWP::Protocol::http::socket_class, avg 4µs/call
# spent 4µs making 2 calls to LWP::Protocol::http::_extra_sock_opts, avg 2µs/call |
| 32 | PeerPort => $port, | ||||
| 33 | LocalAddr => $self->{ua}{local_address}, | ||||
| 34 | Proto => 'tcp', | ||||
| 35 | Timeout => $timeout, | ||||
| 36 | KeepAlive => !!$conn_cache, | ||||
| 37 | SendTE => 1, | ||||
| 38 | $self->_extra_sock_opts($host, $port), | ||||
| 39 | ); | ||||
| 40 | |||||
| 41 | 2 | 1µs | unless ($sock) { | ||
| 42 | # IO::Socket::INET leaves additional error messages in $@ | ||||
| 43 | $@ =~ s/^.*?: //; | ||||
| 44 | die "Can't connect to $host:$port ($@)"; | ||||
| 45 | } | ||||
| 46 | |||||
| 47 | # perl 5.005's IO::Socket does not have the blocking method. | ||||
| 48 | 4 | 11µs | 2 | 27µs | eval { $sock->blocking(0); }; # spent 27µs making 2 calls to IO::Socket::blocking, avg 13µs/call |
| 49 | |||||
| 50 | 2 | 17µs | $sock; | ||
| 51 | } | ||||
| 52 | |||||
| 53 | sub socket_type | ||||
| 54 | { | ||||
| 55 | 81 | 293µs | return "http"; | ||
| 56 | } | ||||
| 57 | |||||
| 58 | sub socket_class | ||||
| 59 | # spent 8µs within LWP::Protocol::http::socket_class which was called 2 times, avg 4µs/call:
# 2 times (8µs+0s) by LWP::Protocol::http::_new_socket at line 31, avg 4µs/call | ||||
| 60 | 2 | 900ns | my $self = shift; | ||
| 61 | 2 | 9µs | (ref($self) || $self) . "::Socket"; | ||
| 62 | } | ||||
| 63 | |||||
| 64 | sub _extra_sock_opts # to be overridden by subclass | ||||
| 65 | # spent 4µs within LWP::Protocol::http::_extra_sock_opts which was called 2 times, avg 2µs/call:
# 2 times (4µs+0s) by LWP::Protocol::http::_new_socket at line 31, avg 2µs/call | ||||
| 66 | 2 | 6µs | return @EXTRA_SOCK_OPTS; | ||
| 67 | } | ||||
| 68 | |||||
| 69 | sub _check_sock | ||||
| 70 | 41 | 105µs | # spent 71µs within LWP::Protocol::http::_check_sock which was called 41 times, avg 2µs/call:
# 41 times (71µs+0s) by LWP::Protocol::http::request at line 156, avg 2µs/call | ||
| 71 | #my($self, $req, $sock) = @_; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub _get_sock_info | ||||
| 75 | # spent 5.73ms (777µs+4.95) within LWP::Protocol::http::_get_sock_info which was called 41 times, avg 140µs/call:
# 41 times (777µs+4.95ms) by LWP::Protocol::http::request at line 367, avg 140µs/call | ||||
| 76 | 41 | 56µs | my($self, $res, $sock) = @_; | ||
| 77 | 41 | 603µs | 123 | 4.88ms | if (defined(my $peerhost = $sock->peerhost)) { # spent 2.07ms making 41 calls to IO::Socket::INET::peerhost, avg 51µs/call
# spent 2.03ms making 40 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 51µs/call
# spent 762µs making 41 calls to IO::Socket::INET::peerport, avg 19µs/call
# spent 11µs making 1 call to HTTP::Message::AUTOLOAD |
| 78 | $res->header("Client-Peer" => "$peerhost:" . $sock->peerport); | ||||
| 79 | } | ||||
| 80 | } | ||||
| 81 | |||||
| 82 | sub _fixup_header | ||||
| 83 | # spent 1.75ms (574µs+1.18) within LWP::Protocol::http::_fixup_header which was called 41 times, avg 43µs/call:
# 41 times (574µs+1.18ms) by LWP::Protocol::http::request at line 160, avg 43µs/call | ||||
| 84 | 41 | 57µs | my($self, $h, $url, $proxy) = @_; | ||
| 85 | |||||
| 86 | # Extract 'Host' header | ||||
| 87 | 41 | 93µs | 41 | 415µs | my $hhost = $url->authority; # spent 415µs making 41 calls to URI::_generic::authority, avg 10µs/call |
| 88 | 41 | 156µs | 41 | 28µs | if ($hhost =~ s/^([^\@]*)\@//) { # get rid of potential "user:pass@" # spent 28µs making 41 calls to LWP::Protocol::http::CORE:subst, avg 693ns/call |
| 89 | # add authorization header if we need them. HTTP URLs do | ||||
| 90 | # not really support specification of user and password, but | ||||
| 91 | # we allow it. | ||||
| 92 | if (defined($1) && not $h->header('Authorization')) { | ||||
| 93 | require URI::Escape; | ||||
| 94 | $h->authorization_basic(map URI::Escape::uri_unescape($_), | ||||
| 95 | split(":", $1, 2)); | ||||
| 96 | } | ||||
| 97 | } | ||||
| 98 | 41 | 80µs | 41 | 737µs | $h->init_header('Host' => $hhost); # spent 737µs making 41 calls to HTTP::Headers::init_header, avg 18µs/call |
| 99 | |||||
| 100 | 41 | 110µs | if ($proxy) { | ||
| 101 | # Check the proxy URI's userinfo() for proxy credentials | ||||
| 102 | # export http_proxy="http://proxyuser:proxypass@proxyhost:port" | ||||
| 103 | my $p_auth = $proxy->userinfo(); | ||||
| 104 | if(defined $p_auth) { | ||||
| 105 | require URI::Escape; | ||||
| 106 | $h->proxy_authorization_basic(map URI::Escape::uri_unescape($_), | ||||
| 107 | split(":", $p_auth, 2)) | ||||
| 108 | } | ||||
| 109 | } | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | sub hlist_remove { | ||||
| 113 | my($hlist, $k) = @_; | ||||
| 114 | $k = lc $k; | ||||
| 115 | for (my $i = @$hlist - 2; $i >= 0; $i -= 2) { | ||||
| 116 | next unless lc($hlist->[$i]) eq $k; | ||||
| 117 | splice(@$hlist, $i, 2); | ||||
| 118 | } | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | sub request | ||||
| 122 | # spent 15.5s (10.8ms+15.5) within LWP::Protocol::http::request which was called 41 times, avg 378ms/call:
# 41 times (10.8ms+15.5s) by LWP::UserAgent::send_request at line 178 of LWP/UserAgent.pm, avg 378ms/call | ||||
| 123 | 41 | 57µs | my($self, $request, $proxy, $arg, $size, $timeout) = @_; | ||
| 124 | |||||
| 125 | 41 | 17µs | $size ||= 4096; | ||
| 126 | |||||
| 127 | # check method | ||||
| 128 | 41 | 71µs | 41 | 230µs | my $method = $request->method; # spent 230µs making 41 calls to HTTP::Request::method, avg 6µs/call |
| 129 | 41 | 221µs | 41 | 94µs | unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token # spent 94µs making 41 calls to LWP::Protocol::http::CORE:match, avg 2µs/call |
| 130 | return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST, | ||||
| 131 | 'Library does not allow method ' . | ||||
| 132 | "$method for 'http:' URLs"; | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | 41 | 77µs | 41 | 96µs | my $url = $request->uri; # spent 96µs making 41 calls to HTTP::Request::uri, avg 2µs/call |
| 136 | 41 | 27µs | my($host, $port, $fullpath); | ||
| 137 | |||||
| 138 | # Check if we're proxy'ing | ||||
| 139 | 41 | 35µs | if (defined $proxy) { | ||
| 140 | # $proxy is an URL to an HTTP server which will proxy this request | ||||
| 141 | $host = $proxy->host; | ||||
| 142 | $port = $proxy->port; | ||||
| 143 | $fullpath = $method eq "CONNECT" ? | ||||
| 144 | ($url->host . ":" . $url->port) : | ||||
| 145 | $url->as_string; | ||||
| 146 | } | ||||
| 147 | else { | ||||
| 148 | 41 | 90µs | 41 | 980µs | $host = $url->host; # spent 980µs making 41 calls to URI::_server::host, avg 24µs/call |
| 149 | 41 | 120µs | 41 | 1.07ms | $port = $url->port; # spent 1.07ms making 41 calls to URI::_server::port, avg 26µs/call |
| 150 | 41 | 125µs | 41 | 382µs | $fullpath = $url->path_query; # spent 382µs making 41 calls to URI::_generic::path_query, avg 9µs/call |
| 151 | 41 | 162µs | 41 | 51µs | $fullpath = "/$fullpath" unless $fullpath =~ m,^/,; # spent 51µs making 41 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 152 | } | ||||
| 153 | |||||
| 154 | # connect to remote site | ||||
| 155 | 41 | 153µs | 41 | 184ms | my $socket = $self->_new_socket($host, $port, $timeout); # spent 184ms making 41 calls to LWP::Protocol::http::_new_socket, avg 4.48ms/call |
| 156 | 41 | 108µs | 41 | 71µs | $self->_check_sock($request, $socket); # spent 71µs making 41 calls to LWP::Protocol::http::_check_sock, avg 2µs/call |
| 157 | |||||
| 158 | 41 | 10µs | my @h; | ||
| 159 | 41 | 2.31ms | 82 | 2.14ms | my $request_headers = $request->headers->clone; # spent 2.05ms making 41 calls to Storable::dclone, avg 50µs/call
# spent 94µs making 41 calls to HTTP::Message::headers, avg 2µs/call |
| 160 | 41 | 138µs | 41 | 1.75ms | $self->_fixup_header($request_headers, $url, $proxy); # spent 1.75ms making 41 calls to LWP::Protocol::http::_fixup_header, avg 43µs/call |
| 161 | |||||
| 162 | # spent 912µs (843+69) within LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] which was called 123 times, avg 7µs/call:
# 123 times (843µs+69µs) by HTTP::Headers::scan at line 231 of HTTP/Headers.pm, avg 7µs/call | ||||
| 163 | 123 | 105µs | my($k, $v) = @_; | ||
| 164 | 123 | 273µs | 123 | 36µs | $k =~ s/^://; # spent 36µs making 123 calls to LWP::Protocol::http::CORE:subst, avg 293ns/call |
| 165 | 123 | 231µs | 123 | 33µs | $v =~ s/\n/ /g; # spent 33µs making 123 calls to LWP::Protocol::http::CORE:subst, avg 267ns/call |
| 166 | 123 | 364µs | push(@h, $k, $v); | ||
| 167 | 41 | 386µs | 41 | 2.49ms | }); # spent 2.49ms making 41 calls to HTTP::Headers::scan, avg 61µs/call |
| 168 | |||||
| 169 | 41 | 132µs | 41 | 333µs | my $content_ref = $request->content_ref; # spent 333µs making 41 calls to HTTP::Message::content_ref, avg 8µs/call |
| 170 | 41 | 21µs | $content_ref = $$content_ref if ref($$content_ref); | ||
| 171 | 41 | 12µs | my $chunked; | ||
| 172 | 41 | 7µs | my $has_content; | ||
| 173 | |||||
| 174 | 41 | 49µs | if (ref($content_ref) eq 'CODE') { | ||
| 175 | my $clen = $request_headers->header('Content-Length'); | ||||
| 176 | $has_content++ if $clen; | ||||
| 177 | unless (defined $clen) { | ||||
| 178 | push(@h, "Transfer-Encoding" => "chunked"); | ||||
| 179 | $has_content++; | ||||
| 180 | $chunked++; | ||||
| 181 | } | ||||
| 182 | } | ||||
| 183 | else { | ||||
| 184 | # Set (or override) Content-Length header | ||||
| 185 | 41 | 87µs | 41 | 622µs | my $clen = $request_headers->header('Content-Length'); # spent 622µs making 41 calls to HTTP::Headers::header, avg 15µs/call |
| 186 | 41 | 56µs | if (defined($$content_ref) && length($$content_ref)) { | ||
| 187 | 41 | 16µs | $has_content = length($$content_ref); | ||
| 188 | 41 | 40µs | if (!defined($clen) || $clen ne $has_content) { | ||
| 189 | 41 | 13µs | if (defined $clen) { | ||
| 190 | warn "Content-Length header value was wrong, fixed"; | ||||
| 191 | hlist_remove(\@h, 'Content-Length'); | ||||
| 192 | } | ||||
| 193 | 41 | 40µs | push(@h, 'Content-Length' => $has_content); | ||
| 194 | } | ||||
| 195 | } | ||||
| 196 | elsif ($clen) { | ||||
| 197 | warn "Content-Length set when there is no content, fixed"; | ||||
| 198 | hlist_remove(\@h, 'Content-Length'); | ||||
| 199 | } | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | 41 | 20µs | my $write_wait = 0; | ||
| 203 | 41 | 172µs | 82 | 532µs | $write_wait = 2 # spent 520µs making 41 calls to HTTP::Headers::header, avg 13µs/call
# spent 11µs making 41 calls to LWP::Protocol::http::CORE:match, avg 280ns/call |
| 204 | if ($request_headers->header("Expect") || "") =~ /100-continue/; | ||||
| 205 | |||||
| 206 | 41 | 155µs | 41 | 31.9ms | my $req_buf = $socket->format_request($method, $fullpath, @h); # spent 31.9ms making 41 calls to Net::HTTP::Methods::format_request, avg 778µs/call |
| 207 | #print "------\n$req_buf\n------\n"; | ||||
| 208 | |||||
| 209 | 41 | 34µs | if (!$has_content || $write_wait || $has_content > 8*1024) { | ||
| 210 | WRITE: | ||||
| 211 | { | ||||
| 212 | # Since this just writes out the header block it should almost | ||||
| 213 | # always succeed to send the whole buffer in a single write call. | ||||
| 214 | my $n = $socket->syswrite($req_buf, length($req_buf)); | ||||
| 215 | unless (defined $n) { | ||||
| 216 | 3 | 1.23ms | 1 | 1.48ms | # spent 1.48ms (1.39+94µs) within LWP::Protocol::http::BEGIN@216 which was called
# once (1.39ms+94µs) by LWP::Protocol::implementor at line 216 # spent 1.48ms making 1 call to LWP::Protocol::http::BEGIN@216 |
| 217 | if ($!{EAGAIN}) { | ||||
| 218 | select(undef, undef, undef, 0.1); | ||||
| 219 | redo WRITE; | ||||
| 220 | } | ||||
| 221 | die "write failed: $!"; | ||||
| 222 | } | ||||
| 223 | if ($n) { | ||||
| 224 | substr($req_buf, 0, $n, ""); | ||||
| 225 | } | ||||
| 226 | else { | ||||
| 227 | select(undef, undef, undef, 0.5); | ||||
| 228 | } | ||||
| 229 | redo WRITE if length $req_buf; | ||||
| 230 | } | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | 41 | 35µs | my($code, $mess, @junk); | ||
| 234 | 41 | 13µs | my $drop_connection; | ||
| 235 | |||||
| 236 | 41 | 29µs | if ($has_content) { | ||
| 237 | 41 | 9µs | my $eof; | ||
| 238 | 41 | 12µs | my $wbuf; | ||
| 239 | 41 | 25µs | my $woffset = 0; | ||
| 240 | 41 | 52µs | if (ref($content_ref) eq 'CODE') { | ||
| 241 | my $buf = &$content_ref(); | ||||
| 242 | $buf = "" unless defined($buf); | ||||
| 243 | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||
| 244 | if $chunked; | ||||
| 245 | substr($buf, 0, 0) = $req_buf if $req_buf; | ||||
| 246 | $wbuf = \$buf; | ||||
| 247 | } | ||||
| 248 | else { | ||||
| 249 | 41 | 31µs | if ($req_buf) { | ||
| 250 | 41 | 71µs | my $buf = $req_buf . $$content_ref; | ||
| 251 | 41 | 23µs | $wbuf = \$buf; | ||
| 252 | } | ||||
| 253 | else { | ||||
| 254 | $wbuf = $content_ref; | ||||
| 255 | } | ||||
| 256 | 41 | 10µs | $eof = 1; | ||
| 257 | } | ||||
| 258 | |||||
| 259 | 41 | 35µs | my $fbits = ''; | ||
| 260 | 41 | 75µs | vec($fbits, fileno($socket), 1) = 1; | ||
| 261 | |||||
| 262 | WRITE: | ||||
| 263 | 41 | 75µs | while ($woffset < length($$wbuf)) { | ||
| 264 | |||||
| 265 | 41 | 13µs | my $sel_timeout = $timeout; | ||
| 266 | 41 | 15µs | if ($write_wait) { | ||
| 267 | $sel_timeout = $write_wait if $write_wait < $sel_timeout; | ||||
| 268 | } | ||||
| 269 | 41 | 8µs | my $time_before; | ||
| 270 | 41 | 38µs | $time_before = time if $sel_timeout; | ||
| 271 | |||||
| 272 | 41 | 17µs | my $rbits = $fbits; | ||
| 273 | 41 | 15µs | my $wbits = $write_wait ? undef : $fbits; | ||
| 274 | 41 | 14µs | my $sel_timeout_before = $sel_timeout; | ||
| 275 | 41 | 469µs | 41 | 295µs | SELECT: # spent 295µs making 41 calls to LWP::Protocol::http::CORE:sselect, avg 7µs/call |
| 276 | { | ||||
| 277 | 41 | 19µs | my $nfound = select($rbits, $wbits, undef, $sel_timeout); | ||
| 278 | 41 | 33µs | if ($nfound < 0) { | ||
| 279 | if ($!{EINTR} || $!{EAGAIN}) { | ||||
| 280 | if ($time_before) { | ||||
| 281 | $sel_timeout = $sel_timeout_before - (time - $time_before); | ||||
| 282 | $sel_timeout = 0 if $sel_timeout < 0; | ||||
| 283 | } | ||||
| 284 | redo SELECT; | ||||
| 285 | } | ||||
| 286 | die "select failed: $!"; | ||||
| 287 | } | ||||
| 288 | } | ||||
| 289 | |||||
| 290 | 41 | 21µs | if ($write_wait) { | ||
| 291 | $write_wait -= time - $time_before; | ||||
| 292 | $write_wait = 0 if $write_wait < 0; | ||||
| 293 | } | ||||
| 294 | |||||
| 295 | 41 | 154µs | 41 | 55µs | if (defined($rbits) && $rbits =~ /[^\0]/) { # spent 55µs making 41 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 296 | # readable | ||||
| 297 | my $buf = $socket->_rbuf; | ||||
| 298 | my $n = $socket->sysread($buf, 1024, length($buf)); | ||||
| 299 | unless (defined $n) { | ||||
| 300 | die "read failed: $!" unless $!{EINTR} || $!{EAGAIN}; | ||||
| 301 | # if we get here the rest of the block will do nothing | ||||
| 302 | # and we will retry the read on the next round | ||||
| 303 | } | ||||
| 304 | elsif ($n == 0) { | ||||
| 305 | # the server closed the connection before we finished | ||||
| 306 | # writing all the request content. No need to write any more. | ||||
| 307 | $drop_connection++; | ||||
| 308 | last WRITE; | ||||
| 309 | } | ||||
| 310 | $socket->_rbuf($buf); | ||||
| 311 | if (!$code && $buf =~ /\015?\012\015?\012/) { | ||||
| 312 | # a whole response header is present, so we can read it without blocking | ||||
| 313 | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, | ||||
| 314 | junk_out => \@junk, | ||||
| 315 | ); | ||||
| 316 | if ($code eq "100") { | ||||
| 317 | $write_wait = 0; | ||||
| 318 | undef($code); | ||||
| 319 | } | ||||
| 320 | else { | ||||
| 321 | $drop_connection++; | ||||
| 322 | last WRITE; | ||||
| 323 | # XXX should perhaps try to abort write in a nice way too | ||||
| 324 | } | ||||
| 325 | } | ||||
| 326 | } | ||||
| 327 | 41 | 193µs | 41 | 51µs | if (defined($wbits) && $wbits =~ /[^\0]/) { # spent 51µs making 41 calls to LWP::Protocol::http::CORE:match, avg 1µs/call |
| 328 | 41 | 233µs | 41 | 2.89ms | my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset); # spent 2.89ms making 41 calls to IO::Handle::syswrite, avg 70µs/call |
| 329 | 41 | 59µs | unless (defined $n) { | ||
| 330 | die "write failed: $!" unless $!{EINTR} || $!{EAGAIN}; | ||||
| 331 | $n = 0; # will retry write on the next round | ||||
| 332 | } | ||||
| 333 | elsif ($n == 0) { | ||||
| 334 | die "write failed: no bytes written"; | ||||
| 335 | } | ||||
| 336 | 41 | 28µs | $woffset += $n; | ||
| 337 | |||||
| 338 | 41 | 24µs | if (!$eof && $woffset >= length($$wbuf)) { | ||
| 339 | # need to refill buffer from $content_ref code | ||||
| 340 | my $buf = &$content_ref(); | ||||
| 341 | $buf = "" unless defined($buf); | ||||
| 342 | $eof++ unless length($buf); | ||||
| 343 | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||
| 344 | if $chunked; | ||||
| 345 | $wbuf = \$buf; | ||||
| 346 | $woffset = 0; | ||||
| 347 | } | ||||
| 348 | } | ||||
| 349 | } # WRITE | ||||
| 350 | } | ||||
| 351 | |||||
| 352 | 41 | 744µs | 41 | 15.1s | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) # spent 15.1s making 41 calls to Net::HTTP::Methods::read_response_headers, avg 368ms/call |
| 353 | unless $code; | ||||
| 354 | 41 | 33µs | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||
| 355 | if $code eq "100"; | ||||
| 356 | |||||
| 357 | 41 | 311µs | 41 | 3.56ms | my $response = HTTP::Response->new($code, $mess); # spent 3.56ms making 41 calls to HTTP::Response::new, avg 87µs/call |
| 358 | 41 | 185µs | 41 | 245µs | my $peer_http_version = $socket->peer_http_version; # spent 245µs making 41 calls to Net::HTTP::Methods::__ANON__[Net/HTTP/Methods.pm:104], avg 6µs/call |
| 359 | 41 | 169µs | 41 | 429µs | $response->protocol("HTTP/$peer_http_version"); # spent 429µs making 41 calls to HTTP::Message::protocol, avg 10µs/call |
| 360 | { | ||||
| 361 | 82 | 69µs | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | ||
| 362 | 41 | 192µs | 41 | 3.49ms | $response->push_header(@h); # spent 3.46ms making 40 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 87µs/call
# spent 22µs making 1 call to HTTP::Message::AUTOLOAD |
| 363 | } | ||||
| 364 | 41 | 34µs | $response->push_header("Client-Junk" => \@junk) if @junk; | ||
| 365 | |||||
| 366 | 41 | 153µs | 41 | 424µs | $response->request($request); # spent 424µs making 41 calls to HTTP::Response::request, avg 10µs/call |
| 367 | 41 | 194µs | 41 | 5.73ms | $self->_get_sock_info($response, $socket); # spent 5.73ms making 41 calls to LWP::Protocol::http::_get_sock_info, avg 140µs/call |
| 368 | |||||
| 369 | 41 | 32µs | if ($method eq "CONNECT") { | ||
| 370 | $response->{client_socket} = $socket; # so it can be picked up | ||||
| 371 | return $response; | ||||
| 372 | } | ||||
| 373 | |||||
| 374 | 41 | 422µs | 81 | 2.27ms | if (my @te = $response->remove_header('Transfer-Encoding')) { # spent 2.26ms making 80 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 28µs/call
# spent 10µs making 1 call to HTTP::Message::AUTOLOAD |
| 375 | $response->push_header('Client-Transfer-Encoding', \@te); | ||||
| 376 | } | ||||
| 377 | 41 | 229µs | 82 | 1.20ms | $response->push_header('Client-Response-Num', scalar $socket->increment_response_count); # spent 1.01ms making 41 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 25µs/call
# spent 190µs making 41 calls to LWP::Protocol::http::SocketMethods::increment_response_count, avg 5µs/call |
| 378 | |||||
| 379 | 41 | 19µs | my $complete; | ||
| 380 | # spent 87.2ms (958µs+86.2) within LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:394] which was called 98 times, avg 890µs/call:
# 57 times (452µs+82.7ms) by LWP::Protocol::collect at line 158 of LWP/Protocol.pm, avg 1.46ms/call
# 41 times (505µs+3.52ms) by LWP::Protocol::collect at line 148 of LWP/Protocol.pm, avg 98µs/call | ||||
| 381 | 98 | 59µs | my $buf = ""; #prevent use of uninitialized value in SSLeay.xs | ||
| 382 | 98 | 37µs | my $n; | ||
| 383 | 98 | 280µs | 98 | 86.2ms | READ: # spent 86.2ms making 98 calls to Net::HTTP::Methods::read_entity_body, avg 880µs/call |
| 384 | { | ||||
| 385 | 98 | 43µs | $n = $socket->read_entity_body($buf, $size); | ||
| 386 | 98 | 30µs | unless (defined $n) { | ||
| 387 | redo READ if $!{EINTR} || $!{EAGAIN}; | ||||
| 388 | die "read failed: $!"; | ||||
| 389 | } | ||||
| 390 | 98 | 57µs | redo READ if $n == -1; | ||
| 391 | } | ||||
| 392 | 98 | 42µs | $complete++ if !$n; | ||
| 393 | 98 | 327µs | return \$buf; | ||
| 394 | 41 | 704µs | 41 | 112ms | } ); # spent 112ms making 41 calls to LWP::Protocol::collect, avg 2.73ms/call |
| 395 | 41 | 19µs | $drop_connection++ unless $complete; | ||
| 396 | |||||
| 397 | 41 | 265µs | 41 | 198µs | @h = $socket->get_trailers; # spent 198µs making 41 calls to Net::HTTP::Methods::get_trailers, avg 5µs/call |
| 398 | 41 | 32µs | if (@h) { | ||
| 399 | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | ||||
| 400 | $response->push_header(@h); | ||||
| 401 | } | ||||
| 402 | |||||
| 403 | # keep-alive support | ||||
| 404 | 41 | 40µs | unless ($drop_connection) { | ||
| 405 | 41 | 77µs | if (my $conn_cache = $self->{ua}{conn_cache}) { | ||
| 406 | 41 | 217µs | 41 | 1.28ms | my %connection = map { (lc($_) => 1) } # spent 1.28ms making 41 calls to HTTP::Message::__ANON__[HTTP/Message.pm:622], avg 31µs/call |
| 407 | split(/\s*,\s*/, ($response->header("Connection") || "")); | ||||
| 408 | 41 | 392µs | 80 | 1.07ms | if (($peer_http_version eq "1.1" && !$connection{close}) || # spent 948µs making 40 calls to LWP::ConnCache::deposit, avg 24µs/call
# spent 121µs making 40 calls to LWP::Protocol::http::socket_type, avg 3µs/call |
| 409 | $connection{"keep-alive"}) | ||||
| 410 | { | ||||
| 411 | $conn_cache->deposit($self->socket_type, "$host:$port", $socket); | ||||
| 412 | } | ||||
| 413 | } | ||||
| 414 | } | ||||
| 415 | |||||
| 416 | 41 | 517µs | $response; | ||
| 417 | } | ||||
| 418 | |||||
| 419 | |||||
| 420 | #----------------------------------------------------------- | ||||
| 421 | package LWP::Protocol::http::SocketMethods; | ||||
| 422 | |||||
| 423 | # spent 15.2s (1.83ms+15.2) within LWP::Protocol::http::SocketMethods::sysread which was called 101 times, avg 150ms/call:
# 84 times (1.65ms+15.2s) by Net::HTTP::Methods::my_readline at line 256 of Net/HTTP/Methods.pm, avg 181ms/call
# 17 times (177µs+543µs) by Net::HTTP::Methods::my_read at line 236 of Net/HTTP/Methods.pm, avg 42µs/call | ||||
| 424 | 101 | 41µs | my $self = shift; | ||
| 425 | 101 | 190µs | if (my $timeout = ${*$self}{io_socket_timeout}) { | ||
| 426 | 101 | 239µs | 101 | 15.2s | die "read timeout" unless $self->can_read($timeout); # spent 15.2s making 101 calls to LWP::Protocol::http::SocketMethods::can_read, avg 150ms/call |
| 427 | } | ||||
| 428 | else { | ||||
| 429 | # since we have made the socket non-blocking we | ||||
| 430 | # use select to wait for some data to arrive | ||||
| 431 | $self->can_read(undef) || die "Assert"; | ||||
| 432 | } | ||||
| 433 | 101 | 2.39ms | 101 | 1.25ms | sysread($self, $_[0], $_[1], $_[2] || 0); # spent 1.25ms making 101 calls to LWP::Protocol::http::SocketMethods::CORE:sysread, avg 12µs/call |
| 434 | } | ||||
| 435 | |||||
| 436 | # spent 15.2s (3.25ms+15.2) within LWP::Protocol::http::SocketMethods::can_read which was called 140 times, avg 108ms/call:
# 101 times (2.75ms+15.2s) by LWP::Protocol::http::SocketMethods::sysread at line 426, avg 150ms/call
# 39 times (504µs+347µs) by LWP::Protocol::http::_new_socket at line 22, avg 22µs/call | ||||
| 437 | 140 | 105µs | my($self, $timeout) = @_; | ||
| 438 | 140 | 79µs | my $fbits = ''; | ||
| 439 | 140 | 329µs | vec($fbits, fileno($self), 1) = 1; | ||
| 440 | 140 | 12µs | SELECT: | ||
| 441 | { | ||||
| 442 | 140 | 27µs | my $before; | ||
| 443 | 140 | 114µs | $before = time if $timeout; | ||
| 444 | 140 | 15.2s | 140 | 15.2s | my $nfound = select($fbits, undef, undef, $timeout); # spent 15.2s making 140 calls to LWP::Protocol::http::SocketMethods::CORE:sselect, avg 108ms/call |
| 445 | 140 | 131µs | if ($nfound < 0) { | ||
| 446 | if ($!{EINTR} || $!{EAGAIN}) { | ||||
| 447 | # don't really think EAGAIN can happen here | ||||
| 448 | if ($timeout) { | ||||
| 449 | $timeout -= time - $before; | ||||
| 450 | $timeout = 0 if $timeout < 0; | ||||
| 451 | } | ||||
| 452 | redo SELECT; | ||||
| 453 | } | ||||
| 454 | die "select failed: $!"; | ||||
| 455 | } | ||||
| 456 | 140 | 1.27ms | return $nfound > 0; | ||
| 457 | } | ||||
| 458 | } | ||||
| 459 | |||||
| 460 | sub ping { | ||||
| 461 | my $self = shift; | ||||
| 462 | !$self->can_read(0); | ||||
| 463 | } | ||||
| 464 | |||||
| 465 | # spent 190µs within LWP::Protocol::http::SocketMethods::increment_response_count which was called 41 times, avg 5µs/call:
# 41 times (190µs+0s) by LWP::Protocol::http::request at line 377, avg 5µs/call | ||||
| 466 | 41 | 30µs | my $self = shift; | ||
| 467 | 41 | 191µs | return ++${*$self}{'myhttp_response_count'}; | ||
| 468 | } | ||||
| 469 | |||||
| 470 | #----------------------------------------------------------- | ||||
| 471 | package LWP::Protocol::http::Socket; | ||||
| 472 | 3 | 46µs | 2 | 60µs | # spent 35µs (9+26) within LWP::Protocol::http::Socket::BEGIN@472 which was called
# once (9µs+26µs) by LWP::Protocol::implementor at line 472 # spent 35µs making 1 call to LWP::Protocol::http::Socket::BEGIN@472
# spent 26µs making 1 call to vars::import |
| 473 | 1 | 15µs | @ISA = qw(LWP::Protocol::http::SocketMethods Net::HTTP); | ||
| 474 | |||||
| 475 | 1 | 9µs | 1; | ||
# spent 263µs within LWP::Protocol::http::CORE:match which was called 205 times, avg 1µs/call:
# 41 times (94µs+0s) by LWP::Protocol::http::request at line 129 of LWP/Protocol/http.pm, avg 2µs/call
# 41 times (55µs+0s) by LWP::Protocol::http::request at line 295 of LWP/Protocol/http.pm, avg 1µs/call
# 41 times (51µs+0s) by LWP::Protocol::http::request at line 327 of LWP/Protocol/http.pm, avg 1µs/call
# 41 times (51µs+0s) by LWP::Protocol::http::request at line 151 of LWP/Protocol/http.pm, avg 1µs/call
# 41 times (11µs+0s) by LWP::Protocol::http::request at line 203 of LWP/Protocol/http.pm, avg 280ns/call | |||||
# spent 295µs within LWP::Protocol::http::CORE:sselect which was called 41 times, avg 7µs/call:
# 41 times (295µs+0s) by LWP::Protocol::http::request at line 275 of LWP/Protocol/http.pm, avg 7µs/call | |||||
# spent 97µs within LWP::Protocol::http::CORE:subst which was called 287 times, avg 339ns/call:
# 123 times (36µs+0s) by LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] at line 164 of LWP/Protocol/http.pm, avg 293ns/call
# 123 times (33µs+0s) by LWP::Protocol::http::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol/http.pm:167] at line 165 of LWP/Protocol/http.pm, avg 267ns/call
# 41 times (28µs+0s) by LWP::Protocol::http::_fixup_header at line 88 of LWP/Protocol/http.pm, avg 693ns/call | |||||
# spent 15.2s within LWP::Protocol::http::SocketMethods::CORE:sselect which was called 140 times, avg 108ms/call:
# 140 times (15.2s+0s) by LWP::Protocol::http::SocketMethods::can_read at line 444 of LWP/Protocol/http.pm, avg 108ms/call | |||||
# spent 1.25ms within LWP::Protocol::http::SocketMethods::CORE:sysread which was called 101 times, avg 12µs/call:
# 101 times (1.25ms+0s) by LWP::Protocol::http::SocketMethods::sysread at line 433 of LWP/Protocol/http.pm, avg 12µs/call |