← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:08 2016

Filename/usr/lib/perl/5.18/IO/Socket/INET.pm
StatementsExecuted 163 statements in 2.34ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
21198µs690µsIO::Socket::INET::::configureIO::Socket::INET::configure
42166µs91µsIO::Socket::INET::::_sock_infoIO::Socket::INET::_sock_info
22222µs908µsIO::Socket::INET::::newIO::Socket::INET::new
11118µs893µsIO::Socket::INET::::BEGIN@12IO::Socket::INET::BEGIN@12
21118µs33µsIO::Socket::INET::::_get_addrIO::Socket::INET::_get_addr
21116µs394µsIO::Socket::INET::::connectIO::Socket::INET::connect
11116µs30µsIO::Socket::INET::::BEGIN@9IO::Socket::INET::BEGIN@9
83112µs12µsIO::Socket::INET::::CORE:matchIO::Socket::INET::CORE:match (opcode)
21110µs10µsIO::Socket::INET::::_get_proto_numberIO::Socket::INET::_get_proto_number
11110µs24µsIO::Socket::INET::::BEGIN@14IO::Socket::INET::BEGIN@14
1119µs2.52msIO::Socket::INET::::BEGIN@11IO::Socket::INET::BEGIN@11
1119µs45µsIO::Socket::INET::::BEGIN@13IO::Socket::INET::BEGIN@13
1118µs26µsIO::Socket::INET::::BEGIN@15IO::Socket::INET::BEGIN@15
4214µs4µsIO::Socket::INET::::CORE:substIO::Socket::INET::CORE:subst (opcode)
1113µs3µsIO::Socket::INET::::_get_proto_nameIO::Socket::INET::_get_proto_name
0000s0sIO::Socket::INET::::_cache_protoIO::Socket::INET::_cache_proto
0000s0sIO::Socket::INET::::_errorIO::Socket::INET::_error
0000s0sIO::Socket::INET::::bindIO::Socket::INET::bind
0000s0sIO::Socket::INET::::peeraddrIO::Socket::INET::peeraddr
0000s0sIO::Socket::INET::::peerhostIO::Socket::INET::peerhost
0000s0sIO::Socket::INET::::peerportIO::Socket::INET::peerport
0000s0sIO::Socket::INET::::sockaddrIO::Socket::INET::sockaddr
0000s0sIO::Socket::INET::::sockhostIO::Socket::INET::sockhost
0000s0sIO::Socket::INET::::sockportIO::Socket::INET::sockport
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# IO::Socket::INET.pm
2#
3# Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4# This program is free software; you can redistribute it and/or
5# modify it under the same terms as Perl itself.
6
7package IO::Socket::INET;
8
9245µs245µs
# spent 30µs (16+15) within IO::Socket::INET::BEGIN@9 which was called: # once (16µs+15µs) by main::BEGIN@7 at line 9
use strict;
# spent 30µs making 1 call to IO::Socket::INET::BEGIN@9 # spent 15µs making 1 call to strict::import
101400nsour(@ISA, $VERSION);
11239µs25.03ms
# spent 2.52ms (9µs+2.51) within IO::Socket::INET::BEGIN@11 which was called: # once (9µs+2.51ms) by main::BEGIN@7 at line 11
use IO::Socket;
# spent 2.52ms making 1 call to IO::Socket::INET::BEGIN@11 # spent 2.51ms making 1 call to IO::Socket::import
12232µs21.77ms
# spent 893µs (18+874) within IO::Socket::INET::BEGIN@12 which was called: # once (18µs+874µs) by main::BEGIN@7 at line 12
use Socket;
# spent 893µs making 1 call to IO::Socket::INET::BEGIN@12 # spent 874µs making 1 call to Exporter::import
13229µs281µs
# spent 45µs (9+36) within IO::Socket::INET::BEGIN@13 which was called: # once (9µs+36µs) by main::BEGIN@7 at line 13
use Carp;
# spent 45µs making 1 call to IO::Socket::INET::BEGIN@13 # spent 36µs making 1 call to Exporter::import
14227µs238µs
# spent 24µs (10+14) within IO::Socket::INET::BEGIN@14 which was called: # once (10µs+14µs) by main::BEGIN@7 at line 14
use Exporter;
# spent 24µs making 1 call to IO::Socket::INET::BEGIN@14 # spent 14µs making 1 call to Exporter::import
1521.87ms243µs
# spent 26µs (8+17) within IO::Socket::INET::BEGIN@15 which was called: # once (8µs+17µs) by main::BEGIN@7 at line 15
use Errno;
# spent 26µs making 1 call to IO::Socket::INET::BEGIN@15 # spent 17µs making 1 call to Exporter::import
16
1719µs@ISA = qw(IO::Socket);
181400ns$VERSION = "1.33";
19
201600nsmy $EINVAL = exists(&Errno::EINVAL) ? Errno::EINVAL() : 1;
21
2215µs13µsIO::Socket::INET->register_domain( AF_INET );
# spent 3µs making 1 call to IO::Socket::register_domain
23
2412µsmy %socket_type = ( tcp => SOCK_STREAM,
25 udp => SOCK_DGRAM,
26 icmp => SOCK_RAW
27 );
281200nsmy %proto_number;
2911µs$proto_number{tcp} = Socket::IPPROTO_TCP() if defined &Socket::IPPROTO_TCP;
301300ns$proto_number{udp} = Socket::IPPROTO_UDP() if defined &Socket::IPPROTO_UDP;
311200ns$proto_number{icmp} = Socket::IPPROTO_ICMP() if defined &Socket::IPPROTO_ICMP;
3213µsmy %proto_name = reverse %proto_number;
33
34
# spent 908µs (22+885) within IO::Socket::INET::new which was called 2 times, avg 454µs/call: # once (10µs+600µs) by HTTP::Tiny::Handle::connect at line 1041 of /opt/flows/lib/lib/perl5/HTTP/Tiny.pm # once (12µs+285µs) by main::RUNTIME at line 39 of flows_to_es.pl
sub new {
3522µs my $class = shift;
3621µs unshift(@_, "PeerAddr") if @_ == 1;
37218µs2885µs return $class->SUPER::new(@_);
# spent 885µs making 2 calls to IO::Socket::new, avg 443µs/call
38}
39
40sub _cache_proto {
41 my @proto = @_;
42 for (map lc($_), $proto[0], split(' ', $proto[1])) {
43 $proto_number{$_} = $proto[2];
44 }
45 $proto_name{$proto[2]} = $proto[0];
46}
47
48
# spent 10µs within IO::Socket::INET::_get_proto_number which was called 2 times, avg 5µs/call: # 2 times (10µs+0s) by IO::Socket::INET::_sock_info at line 81, avg 5µs/call
sub _get_proto_number {
4923µs my $name = lc(shift);
502600ns return undef unless defined $name;
5128µs return $proto_number{$name} if exists $proto_number{$name};
52
53 my @proto = getprotobyname($name);
54 return undef unless @proto;
55 _cache_proto(@proto);
56
57 return $proto[2];
58}
59
60
# spent 3µs within IO::Socket::INET::_get_proto_name which was called: # once (3µs+0s) by IO::Socket::INET::configure at line 167
sub _get_proto_name {
611500ns my $num = shift;
621300ns return undef unless defined $num;
6314µs return $proto_name{$num} if exists $proto_name{$num};
64
65 my @proto = getprotobynumber($num);
66 return undef unless @proto;
67 _cache_proto(@proto);
68
69 return $proto[0];
70}
71
72
# spent 91µs (66+26) within IO::Socket::INET::_sock_info which was called 4 times, avg 23µs/call: # 2 times (35µs+11µs) by IO::Socket::INET::configure at line 159, avg 23µs/call # 2 times (30µs+15µs) by IO::Socket::INET::configure at line 144, avg 23µs/call
sub _sock_info {
7344µs my($addr,$port,$proto) = @_;
7441µs my $origport = $port;
7542µs my @serv = ();
76
77410µs22µs $port = $1
# spent 2µs making 2 calls to IO::Socket::INET::CORE:subst, avg 1µs/call
78 if(defined $addr && $addr =~ s,:([\w\(\)/]+)$,,);
79
80419µs46µs if(defined $proto && $proto =~ /\D/) {
# spent 6µs making 4 calls to IO::Socket::INET::CORE:match, avg 1µs/call
8125µs210µs my $num = _get_proto_number($proto);
# spent 10µs making 2 calls to IO::Socket::INET::_get_proto_number, avg 5µs/call
822600ns unless (defined $num) {
83 $@ = "Bad protocol '$proto'";
84 return;
85 }
8621µs $proto = $num;
87 }
88
8941µs if(defined $port) {
9026µs22µs my $defport = ($port =~ s,\((\d+)\)$,,) ? $1 : undef;
# spent 2µs making 2 calls to IO::Socket::INET::CORE:subst, avg 800ns/call
91212µs25µs my $pnum = ($port =~ m,^(\d+)$,)[0];
# spent 5µs making 2 calls to IO::Socket::INET::CORE:match, avg 2µs/call
92
9325µs2900ns @serv = getservbyname($port, _get_proto_name($proto) || "")
# spent 900ns making 2 calls to IO::Socket::INET::CORE:match, avg 450ns/call
94 if ($port =~ m,\D,);
95
9622µs $port = $serv[2] || $defport || $pnum;
972400ns unless (defined $port) {
98 $@ = "Bad service '$origport'";
99 return;
100 }
101
10222µs $proto = _get_proto_number($serv[3]) if @serv && !$proto;
103 }
104
105413µs return ($addr || undef,
106 $port || undef,
107 $proto || undef
108 );
109}
110
111sub _error {
112 my $sock = shift;
113 my $err = shift;
114 {
115 local($!);
116 my $title = ref($sock).": ";
117 $@ = join("", $_[0] =~ /^$title/ ? "" : $title, @_);
118 $sock->close()
119 if(defined fileno($sock));
120 }
121 $! = $err;
122 return undef;
123}
124
125
# spent 33µs (18+16) within IO::Socket::INET::_get_addr which was called 2 times, avg 17µs/call: # 2 times (18µs+16µs) by IO::Socket::INET::configure at line 172, avg 17µs/call
sub _get_addr {
12622µs my($sock,$addr_str, $multi) = @_;
1272400ns my @addr;
12821µs if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) {
129 (undef, undef, undef, undef, @addr) = gethostbyname($addr_str);
130 } else {
131224µs216µs my $h = inet_aton($addr_str);
# spent 16µs making 2 calls to Socket::inet_aton, avg 8µs/call
13222µs push(@addr, $h) if defined $h;
133 }
13426µs @addr;
135}
136
137
# spent 690µs (98+592) within IO::Socket::INET::configure which was called 2 times, avg 345µs/call: # 2 times (98µs+592µs) by IO::Socket::new at line 48 of IO/Socket.pm, avg 345µs/call
sub configure {
13821µs my($sock,$arg) = @_;
1392600ns my($lport,$rport,$laddr,$raddr,$proto,$type);
140
14122µs $arg->{LocalAddr} = $arg->{LocalHost}
142 if exists $arg->{LocalHost} && !exists $arg->{LocalAddr};
143
144211µs245µs ($laddr,$lport,$proto) = _sock_info($arg->{LocalAddr},
# spent 45µs making 2 calls to IO::Socket::INET::_sock_info, avg 23µs/call
145 $arg->{LocalPort},
146 $arg->{Proto})
147 or return _error($sock, $!, $@);
148
14922µs $laddr = defined $laddr ? inet_aton($laddr)
150 : INADDR_ANY;
151
1522500ns return _error($sock, $EINVAL, "Bad hostname '",$arg->{LocalAddr},"'")
153 unless(defined $laddr);
154
15522µs $arg->{PeerAddr} = $arg->{PeerHost}
156 if exists $arg->{PeerHost} && !exists $arg->{PeerAddr};
157
15822µs unless(exists $arg->{Listen}) {
15926µs246µs ($raddr,$rport,$proto) = _sock_info($arg->{PeerAddr},
# spent 46µs making 2 calls to IO::Socket::INET::_sock_info, avg 23µs/call
160 $arg->{PeerPort},
161 $proto)
162 or return _error($sock, $!, $@);
163 }
164
1652500ns $proto ||= _get_proto_number('tcp');
166
16724µs13µs $type = $arg->{Type} || $socket_type{lc _get_proto_name($proto)};
# spent 3µs making 1 call to IO::Socket::INET::_get_proto_name
168
1692900ns my @raddr = ();
170
17121µs if(defined $raddr) {
17227µs233µs @raddr = $sock->_get_addr($raddr, $arg->{MultiHomed});
# spent 33µs making 2 calls to IO::Socket::INET::_get_addr, avg 17µs/call
1732900ns return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'")
174 unless @raddr;
175 }
176
1772600ns while(1) {
178
179211µs264µs $sock->socket(AF_INET, $type, $proto) or
# spent 64µs making 2 calls to IO::Socket::socket, avg 32µs/call
180 return _error($sock, $!, "$!");
181
18222µs if (defined $arg->{Blocking}) {
183 defined $sock->blocking($arg->{Blocking})
184 or return _error($sock, $!, "$!");
185 }
186
18722µs if ($arg->{Reuse} || $arg->{ReuseAddr}) {
188 $sock->sockopt(SO_REUSEADDR,1) or
189 return _error($sock, $!, "$!");
190 }
191
1922900ns if ($arg->{ReusePort}) {
193 $sock->sockopt(SO_REUSEPORT,1) or
194 return _error($sock, $!, "$!");
195 }
196
19721µs if ($arg->{Broadcast}) {
198 $sock->sockopt(SO_BROADCAST,1) or
199 return _error($sock, $!, "$!");
200 }
201
20223µs if($lport || ($laddr ne INADDR_ANY) || exists $arg->{Listen}) {
203 $sock->bind($lport || 0, $laddr) or
204 return _error($sock, $!, "$!");
205 }
206
2072900ns if(exists $arg->{Listen}) {
208 $sock->listen($arg->{Listen} || 5) or
209 return _error($sock, $!, "$!");
210 last;
211 }
212
213 # don't try to connect unless we're given a PeerAddr
21421µs last unless exists($arg->{PeerAddr});
215
21621µs $raddr = shift @raddr;
217
2182400ns return _error($sock, $EINVAL, 'Cannot determine remote port')
219 unless($rport || $type == SOCK_DGRAM || $type == SOCK_RAW);
220
221 last
2222700ns unless($type == SOCK_STREAM || defined $raddr);
223
2242400ns return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'")
225 unless defined $raddr;
226
227# my $timeout = ${*$sock}{'io_socket_timeout'};
228# my $before = time() if $timeout;
229
23022µs undef $@;
231224µs4400µs if ($sock->connect(pack_sockaddr_in($rport, $raddr))) {
# spent 394µs making 2 calls to IO::Socket::INET::connect, avg 197µs/call # spent 6µs making 2 calls to Socket::pack_sockaddr_in, avg 3µs/call
232# ${*$sock}{'io_socket_timeout'} = $timeout;
233 return $sock;
234 }
235
236 return _error($sock, $!, $@ || "Timeout")
237 unless @raddr;
238
239# if ($timeout) {
240# my $new_timeout = $timeout - (time() - $before);
241# return _error($sock,
242# (exists(&Errno::ETIMEDOUT) ? Errno::ETIMEDOUT() : $EINVAL),
243# "Timeout") if $new_timeout <= 0;
244# ${*$sock}{'io_socket_timeout'} = $new_timeout;
245# }
246
247 }
248
249 $sock;
250}
251
252
# spent 394µs (16+378) within IO::Socket::INET::connect which was called 2 times, avg 197µs/call: # 2 times (16µs+378µs) by IO::Socket::INET::configure at line 231, avg 197µs/call
sub connect {
25321µs @_ == 2 || @_ == 3 or
254 croak 'usage: $sock->connect(NAME) or $sock->connect(PORT, ADDR)';
2552900ns my $sock = shift;
256214µs2378µs return $sock->SUPER::connect(@_ == 1 ? shift : pack_sockaddr_in(@_));
# spent 378µs making 2 calls to IO::Socket::connect, avg 189µs/call
257}
258
259sub bind {
260 @_ == 2 || @_ == 3 or
261 croak 'usage: $sock->bind(NAME) or $sock->bind(PORT, ADDR)';
262 my $sock = shift;
263 return $sock->SUPER::bind(@_ == 1 ? shift : pack_sockaddr_in(@_))
264}
265
266sub sockaddr {
267 @_ == 1 or croak 'usage: $sock->sockaddr()';
268 my($sock) = @_;
269 my $name = $sock->sockname;
270 $name ? (sockaddr_in($name))[1] : undef;
271}
272
273sub sockport {
274 @_ == 1 or croak 'usage: $sock->sockport()';
275 my($sock) = @_;
276 my $name = $sock->sockname;
277 $name ? (sockaddr_in($name))[0] : undef;
278}
279
280sub sockhost {
281 @_ == 1 or croak 'usage: $sock->sockhost()';
282 my($sock) = @_;
283 my $addr = $sock->sockaddr;
284 $addr ? inet_ntoa($addr) : undef;
285}
286
287sub peeraddr {
288 @_ == 1 or croak 'usage: $sock->peeraddr()';
289 my($sock) = @_;
290 my $name = $sock->peername;
291 $name ? (sockaddr_in($name))[1] : undef;
292}
293
294sub peerport {
295 @_ == 1 or croak 'usage: $sock->peerport()';
296 my($sock) = @_;
297 my $name = $sock->peername;
298 $name ? (sockaddr_in($name))[0] : undef;
299}
300
301sub peerhost {
302 @_ == 1 or croak 'usage: $sock->peerhost()';
303 my($sock) = @_;
304 my $addr = $sock->peeraddr;
305 $addr ? inet_ntoa($addr) : undef;
306}
307
308110µs1;
309
310__END__
 
# spent 12µs within IO::Socket::INET::CORE:match which was called 8 times, avg 1µs/call: # 4 times (6µs+0s) by IO::Socket::INET::_sock_info at line 80, avg 1µs/call # 2 times (5µs+0s) by IO::Socket::INET::_sock_info at line 91, avg 2µs/call # 2 times (900ns+0s) by IO::Socket::INET::_sock_info at line 93, avg 450ns/call
sub IO::Socket::INET::CORE:match; # opcode
# spent 4µs within IO::Socket::INET::CORE:subst which was called 4 times, avg 1µs/call: # 2 times (2µs+0s) by IO::Socket::INET::_sock_info at line 77, avg 1µs/call # 2 times (2µs+0s) by IO::Socket::INET::_sock_info at line 90, avg 800ns/call
sub IO::Socket::INET::CORE:subst; # opcode