← 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.pm
StatementsExecuted 106 statements in 3.12ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.68ms3.88msIO::Socket::::BEGIN@12IO::Socket::BEGIN@12
1112.63ms7.73msIO::Socket::::BEGIN@11IO::Socket::BEGIN@11
111733µs943µsIO::Socket::::BEGIN@17IO::Socket::BEGIN@17
321103µs103µsIO::Socket::::CORE:connectIO::Socket::CORE:connect (opcode)
21170µs378µsIO::Socket::::connectIO::Socket::connect
21147µs885µsIO::Socket::::newIO::Socket::new
44446µs4.59msIO::Socket::::importIO::Socket::import
21142µs42µsIO::Socket::::CORE:socketIO::Socket::CORE:socket (opcode)
21122µs64µsIO::Socket::::socketIO::Socket::socket
22119µs29µsIO::Socket::::blockingIO::Socket::blocking
1119µs24µsIO::Socket::::BEGIN@16IO::Socket::BEGIN@16
1119µs9µsIO::Socket::::timeoutIO::Socket::timeout
1119µs45µsIO::Socket::::BEGIN@13IO::Socket::BEGIN@13
1118µs13µsIO::Socket::::setsockoptIO::Socket::setsockopt
1117µs19µsIO::Socket::::BEGIN@14IO::Socket::BEGIN@14
2226µs6µsIO::Socket::::register_domainIO::Socket::register_domain
1115µs5µsIO::Socket::::CORE:ssockoptIO::Socket::CORE:ssockopt (opcode)
0000s0sIO::Socket::::acceptIO::Socket::accept
0000s0sIO::Socket::::atmarkIO::Socket::atmark
0000s0sIO::Socket::::bindIO::Socket::bind
0000s0sIO::Socket::::closeIO::Socket::close
0000s0sIO::Socket::::configureIO::Socket::configure
0000s0sIO::Socket::::connectedIO::Socket::connected
0000s0sIO::Socket::::getsockoptIO::Socket::getsockopt
0000s0sIO::Socket::::listenIO::Socket::listen
0000s0sIO::Socket::::peernameIO::Socket::peername
0000s0sIO::Socket::::protocolIO::Socket::protocol
0000s0sIO::Socket::::recvIO::Socket::recv
0000s0sIO::Socket::::sendIO::Socket::send
0000s0sIO::Socket::::shutdownIO::Socket::shutdown
0000s0sIO::Socket::::sockdomainIO::Socket::sockdomain
0000s0sIO::Socket::::socketpairIO::Socket::socketpair
0000s0sIO::Socket::::socknameIO::Socket::sockname
0000s0sIO::Socket::::sockoptIO::Socket::sockopt
0000s0sIO::Socket::::socktypeIO::Socket::socktype
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.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;
8
9110µsrequire 5.006;
10
112118µs27.75ms
# spent 7.73ms (2.63+5.10) within IO::Socket::BEGIN@11 which was called: # once (2.63ms+5.10ms) by main::BEGIN@7 at line 11
use IO::Handle;
# spent 7.73ms making 1 call to IO::Socket::BEGIN@11 # spent 21µs making 1 call to Exporter::import
123148µs34.53ms
# spent 3.88ms (2.68+1.20) within IO::Socket::BEGIN@12 which was called: # once (2.68ms+1.20ms) by main::BEGIN@7 at line 12
use Socket 1.3;
# spent 3.88ms making 1 call to IO::Socket::BEGIN@12 # spent 637µs making 1 call to Exporter::import # spent 11µs making 1 call to UNIVERSAL::VERSION
13228µs280µs
# spent 45µs (9+36) within IO::Socket::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::BEGIN@13 # spent 36µs making 1 call to Exporter::import
14244µs231µs
# spent 19µs (7+12) within IO::Socket::BEGIN@14 which was called: # once (7µs+12µs) by main::BEGIN@7 at line 14
use strict;
# spent 19µs making 1 call to IO::Socket::BEGIN@14 # spent 12µs making 1 call to strict::import
151500nsour(@ISA, $VERSION, @EXPORT_OK);
16227µs239µs
# spent 24µs (9+15) within IO::Socket::BEGIN@16 which was called: # once (9µs+15µs) by main::BEGIN@7 at line 16
use Exporter;
# spent 24µs making 1 call to IO::Socket::BEGIN@16 # spent 15µs making 1 call to Exporter::import
1722.17ms2962µs
# spent 943µs (733+210) within IO::Socket::BEGIN@17 which was called: # once (733µs+210µs) by main::BEGIN@7 at line 17
use Errno;
# spent 943µs making 1 call to IO::Socket::BEGIN@17 # spent 20µs making 1 call to Exporter::import
18
19# legacy
20
21190µsrequire IO::Socket::INET;
22184µsrequire IO::Socket::UNIX if ($^O ne 'epoc' && $^O ne 'symbian');
23
24115µs@ISA = qw(IO::Handle);
25
261500ns$VERSION = "1.36";
27
281500ns@EXPORT_OK = qw(sockatmark);
29
30
# spent 4.59ms (46µs+4.55) within IO::Socket::import which was called 4 times, avg 1.15ms/call: # once (12µs+2.50ms) by IO::Socket::INET::BEGIN@11 at line 11 of IO/Socket/INET.pm # once (8µs+758µs) by IO::Socket::UNIX::BEGIN@11 at line 11 of IO/Socket/UNIX.pm # once (8µs+709µs) by main::BEGIN@7 at line 7 of flows_to_es.pl # once (19µs+582µs) by HTTP::Tiny::Handle::BEGIN@982 at line 982 of /opt/flows/lib/lib/perl5/HTTP/Tiny.pm
sub import {
3142µs my $pkg = shift;
32417µs if (@_ && $_[0] eq 'sockatmark') { # not very extensible but for now, fast
33 Exporter::export_to_level('IO::Socket', 1, $pkg, 'sockatmark');
34 } else {
3543µs my $callpkg = caller;
3649µs41.80ms Exporter::export 'Socket', $callpkg, @_;
# spent 1.80ms making 4 calls to Exporter::export, avg 451µs/call
37 }
38}
39
40
# spent 885µs (47+838) within IO::Socket::new which was called 2 times, avg 443µs/call: # 2 times (47µs+838µs) by IO::Socket::INET::new at line 37 of IO/Socket/INET.pm, avg 443µs/call
sub new {
4128µs my($class,%arg) = @_;
4228µs236µs my $sock = $class->SUPER::new();
# spent 36µs making 2 calls to IO::Handle::new, avg 18µs/call
43
44216µs4124µs $sock->autoflush(1);
# spent 112µs making 2 calls to IO::Handle::autoflush, avg 56µs/call # spent 12µs making 2 calls to SelectSaver::DESTROY, avg 6µs/call
45
4625µs ${*$sock}{'io_socket_timeout'} = delete $arg{Timeout};
47
48213µs2690µs return scalar(%arg) ? $sock->configure(\%arg)
# spent 690µs making 2 calls to IO::Socket::INET::configure, avg 345µs/call
49 : $sock;
50}
51
521200nsmy @domain2pkg;
53
54
# spent 6µs within IO::Socket::register_domain which was called 2 times, avg 3µs/call: # once (3µs+0s) by main::BEGIN@7 at line 22 of IO/Socket/INET.pm # once (3µs+0s) by main::BEGIN@7 at line 18 of IO/Socket/UNIX.pm
sub register_domain {
5521µs my($p,$d) = @_;
56213µs $domain2pkg[$d] = $p;
57}
58
59sub configure {
60 my($sock,$arg) = @_;
61 my $domain = delete $arg->{Domain};
62
63 croak 'IO::Socket: Cannot configure a generic socket'
64 unless defined $domain;
65
66 croak "IO::Socket: Unsupported socket domain"
67 unless defined $domain2pkg[$domain];
68
69 croak "IO::Socket: Cannot configure socket in domain '$domain'"
70 unless ref($sock) eq "IO::Socket";
71
72 bless($sock, $domain2pkg[$domain]);
73 $sock->configure($arg);
74}
75
76
# spent 64µs (22+42) within IO::Socket::socket which was called 2 times, avg 32µs/call: # 2 times (22µs+42µs) by IO::Socket::INET::configure at line 179 of IO/Socket/INET.pm, avg 32µs/call
sub socket {
7721µs @_ == 4 or croak 'usage: $sock->socket(DOMAIN, TYPE, PROTOCOL)';
7821µs my($sock,$domain,$type,$protocol) = @_;
79
80252µs242µs socket($sock,$domain,$type,$protocol) or
# spent 42µs making 2 calls to IO::Socket::CORE:socket, avg 21µs/call
81 return undef;
82
8322µs ${*$sock}{'io_socket_domain'} = $domain;
8422µs ${*$sock}{'io_socket_type'} = $type;
8522µs ${*$sock}{'io_socket_proto'} = $protocol;
86
8726µs $sock;
88}
89
90sub socketpair {
91 @_ == 4 || croak 'usage: IO::Socket->socketpair(DOMAIN, TYPE, PROTOCOL)';
92 my($class,$domain,$type,$protocol) = @_;
93 my $sock1 = $class->new();
94 my $sock2 = $class->new();
95
96 socketpair($sock1,$sock2,$domain,$type,$protocol) or
97 return ();
98
99 ${*$sock1}{'io_socket_type'} = ${*$sock2}{'io_socket_type'} = $type;
100 ${*$sock1}{'io_socket_proto'} = ${*$sock2}{'io_socket_proto'} = $protocol;
101
102 ($sock1,$sock2);
103}
104
105
# spent 378µs (70+308) within IO::Socket::connect which was called 2 times, avg 189µs/call: # 2 times (70µs+308µs) by IO::Socket::INET::connect at line 256 of IO/Socket/INET.pm, avg 189µs/call
sub connect {
10621µs @_ == 2 or croak 'usage: $sock->connect(NAME)';
1072600ns my $sock = shift;
10822µs my $addr = shift;
10922µs my $timeout = ${*$sock}{'io_socket_timeout'};
1102300ns my $err;
1112200ns my $blocking;
112
11326µs121µs $blocking = $sock->blocking(0) if $timeout;
# spent 21µs making 1 call to IO::Socket::blocking
1142111µs2101µs if (!connect($sock, $addr)) {
# spent 101µs making 2 calls to IO::Socket::CORE:connect, avg 50µs/call
115110µs192µs if (defined $timeout && ($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
# spent 92µs making 1 call to Errno::FETCH
1161800ns require IO::Select;
117
11814µs143µs my $sel = new IO::Select $sock;
# spent 43µs making 1 call to IO::Select::new
119
12011µs undef $!;
12112µs142µs my($r,$w,$e) = IO::Select::select(undef,$sel,$sel,$timeout);
# spent 42µs making 1 call to IO::Select::select
122112µs12µs if(@$e[0]) {
# spent 2µs making 1 call to IO::Socket::CORE:connect
123 # Windows return from select after the timeout in case of
124 # WSAECONNREFUSED(10061) if exception set is not used.
125 # This behavior is different from Linux.
126 # Using the exception
127 # set we now emulate the behavior in Linux
128 # - Karthik Rajagopalan
129 $err = $sock->getsockopt(SOL_SOCKET,SO_ERROR);
130 $@ = "connect: $err";
131 }
132 elsif(!@$w[0]) {
133 $err = $! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
134 $@ = "connect: timeout";
135 }
136 elsif (!connect($sock,$addr) &&
137 not ($!{EISCONN} || ($! == 10022 && $^O eq 'MSWin32'))
138 ) {
139 # Some systems refuse to re-connect() to
140 # an already open socket and set errno to EISCONN.
141 # Windows sets errno to WSAEINVAL (10022)
142 $err = $!;
143 $@ = "connect: $!";
144 }
145 }
146 elsif ($blocking || !($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
147 $err = $!;
148 $@ = "connect: $!";
149 }
150 }
151
15222µs18µs $sock->blocking(1) if $blocking;
# spent 8µs making 1 call to IO::Socket::blocking
153
1542600ns $! = $err if $err;
155
15626µs $err ? undef : $sock;
157}
158
159# Enable/disable blocking IO on sockets.
160# Without args return the current status of blocking,
161# with args change the mode as appropriate, returning the
162# old setting, or in case of error during the mode change
163# undef.
164
165
# spent 29µs (19+10) within IO::Socket::blocking which was called 2 times, avg 14µs/call: # once (13µs+8µs) by IO::Socket::connect at line 113 # once (6µs+2µs) by IO::Socket::connect at line 152
sub blocking {
1662800ns my $sock = shift;
167
168232µs210µs return $sock->SUPER::blocking(@_)
# spent 10µs making 2 calls to IO::Handle::blocking, avg 5µs/call
169 if $^O ne 'MSWin32' && $^O ne 'VMS';
170
171 # Windows handles blocking differently
172 #
173 # http://groups.google.co.uk/group/perl.perl5.porters/browse_thread/thread/b4e2b1d88280ddff/630b667a66e3509f?#630b667a66e3509f
174 # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/ioctlsocket_2.asp
175 #
176 # 0x8004667e is FIONBIO
177 #
178 # which is used to set blocking behaviour.
179
180 # NOTE:
181 # This is a little confusing, the perl keyword for this is
182 # 'blocking' but the OS level behaviour is 'non-blocking', probably
183 # because sockets are blocking by default.
184 # Therefore internally we have to reverse the semantics.
185
186 my $orig= !${*$sock}{io_sock_nonblocking};
187
188 return $orig unless @_;
189
190 my $block = shift;
191
192 if ( !$block != !$orig ) {
193 ${*$sock}{io_sock_nonblocking} = $block ? 0 : 1;
194 ioctl($sock, 0x8004667e, pack("L!",${*$sock}{io_sock_nonblocking}))
195 or return undef;
196 }
197
198 return $orig;
199}
200
201sub close {
202 @_ == 1 or croak 'usage: $sock->close()';
203 my $sock = shift;
204 ${*$sock}{'io_socket_peername'} = undef;
205 $sock->SUPER::close();
206}
207
208sub bind {
209 @_ == 2 or croak 'usage: $sock->bind(NAME)';
210 my $sock = shift;
211 my $addr = shift;
212
213 return bind($sock, $addr) ? $sock
214 : undef;
215}
216
217sub listen {
218 @_ >= 1 && @_ <= 2 or croak 'usage: $sock->listen([QUEUE])';
219 my($sock,$queue) = @_;
220 $queue = 5
221 unless $queue && $queue > 0;
222
223 return listen($sock, $queue) ? $sock
224 : undef;
225}
226
227sub accept {
228 @_ == 1 || @_ == 2 or croak 'usage $sock->accept([PKG])';
229 my $sock = shift;
230 my $pkg = shift || $sock;
231 my $timeout = ${*$sock}{'io_socket_timeout'};
232 my $new = $pkg->new(Timeout => $timeout);
233 my $peer = undef;
234
235 if(defined $timeout) {
236 require IO::Select;
237
238 my $sel = new IO::Select $sock;
239
240 unless ($sel->can_read($timeout)) {
241 $@ = 'accept: timeout';
242 $! = (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
243 return;
244 }
245 }
246
247 $peer = accept($new,$sock)
248 or return;
249
250 ${*$new}{$_} = ${*$sock}{$_} for qw( io_socket_domain io_socket_type io_socket_proto );
251
252 return wantarray ? ($new, $peer)
253 : $new;
254}
255
256sub sockname {
257 @_ == 1 or croak 'usage: $sock->sockname()';
258 getsockname($_[0]);
259}
260
261sub peername {
262 @_ == 1 or croak 'usage: $sock->peername()';
263 my($sock) = @_;
264 ${*$sock}{'io_socket_peername'} ||= getpeername($sock);
265}
266
267sub connected {
268 @_ == 1 or croak 'usage: $sock->connected()';
269 my($sock) = @_;
270 getpeername($sock);
271}
272
273sub send {
274 @_ >= 2 && @_ <= 4 or croak 'usage: $sock->send(BUF, [FLAGS, [TO]])';
275 my $sock = $_[0];
276 my $flags = $_[2] || 0;
277 my $peer = $_[3] || $sock->peername;
278
279 croak 'send: Cannot determine peer address'
280 unless(defined $peer);
281
282 my $r = defined(getpeername($sock))
283 ? send($sock, $_[1], $flags)
284 : send($sock, $_[1], $flags, $peer);
285
286 # remember who we send to, if it was successful
287 ${*$sock}{'io_socket_peername'} = $peer
288 if(@_ == 4 && defined $r);
289
290 $r;
291}
292
293sub recv {
294 @_ == 3 || @_ == 4 or croak 'usage: $sock->recv(BUF, LEN [, FLAGS])';
295 my $sock = $_[0];
296 my $len = $_[2];
297 my $flags = $_[3] || 0;
298
299 # remember who we recv'd from
300 ${*$sock}{'io_socket_peername'} = recv($sock, $_[1]='', $len, $flags);
301}
302
303sub shutdown {
304 @_ == 2 or croak 'usage: $sock->shutdown(HOW)';
305 my($sock, $how) = @_;
306 ${*$sock}{'io_socket_peername'} = undef;
307 shutdown($sock, $how);
308}
309
310
# spent 13µs (8+5) within IO::Socket::setsockopt which was called: # once (8µs+5µs) by HTTP::Tiny::Handle::connect at line 1055 of /opt/flows/lib/lib/perl5/HTTP/Tiny.pm
sub setsockopt {
3111700ns @_ == 4 or croak '$sock->setsockopt(LEVEL, OPTNAME, OPTVAL)';
312114µs15µs setsockopt($_[0],$_[1],$_[2],$_[3]);
# spent 5µs making 1 call to IO::Socket::CORE:ssockopt
313}
314
3151200ns14µsmy $intsize = length(pack("i",0));
# spent 4µs making 1 call to main::CORE:pack
316
317sub getsockopt {
318 @_ == 3 or croak '$sock->getsockopt(LEVEL, OPTNAME)';
319 my $r = getsockopt($_[0],$_[1],$_[2]);
320 # Just a guess
321 $r = unpack("i", $r)
322 if(defined $r && length($r) == $intsize);
323 $r;
324}
325
326sub sockopt {
327 my $sock = shift;
328 @_ == 1 ? $sock->getsockopt(SOL_SOCKET,@_)
329 : $sock->setsockopt(SOL_SOCKET,@_);
330}
331
332sub atmark {
333 @_ == 1 or croak 'usage: $sock->atmark()';
334 my($sock) = @_;
335 sockatmark($sock);
336}
337
338
# spent 9µs within IO::Socket::timeout which was called: # once (9µs+0s) by HTTP::Tiny::Handle::timeout at line 1024 of /opt/flows/lib/lib/perl5/HTTP/Tiny.pm
sub timeout {
33912µs @_ == 1 || @_ == 2 or croak 'usage: $sock->timeout([VALUE])';
3401900ns my($sock,$val) = @_;
34112µs my $r = ${*$sock}{'io_socket_timeout'};
342
34313µs ${*$sock}{'io_socket_timeout'} = defined $val ? 0 + $val : $val
344 if(@_ == 2);
345
34615µs $r;
347}
348
349sub sockdomain {
350 @_ == 1 or croak 'usage: $sock->sockdomain()';
351 my $sock = shift;
352 if (!defined(${*$sock}{'io_socket_domain'})) {
353 my $addr = $sock->sockname();
354 ${*$sock}{'io_socket_domain'} = sockaddr_family($addr)
355 if (defined($addr));
356 }
357 ${*$sock}{'io_socket_domain'};
358}
359
360sub socktype {
361 @_ == 1 or croak 'usage: $sock->socktype()';
362 my $sock = shift;
363 ${*$sock}{'io_socket_type'} = $sock->sockopt(Socket::SO_TYPE)
364 if (!defined(${*$sock}{'io_socket_type'}) && defined(eval{Socket::SO_TYPE}));
365 ${*$sock}{'io_socket_type'}
366}
367
368sub protocol {
369 @_ == 1 or croak 'usage: $sock->protocol()';
370 my($sock) = @_;
371 ${*$sock}{'io_socket_proto'} = $sock->sockopt(Socket::SO_PROTOCOL)
372 if (!defined(${*$sock}{'io_socket_proto'}) && defined(eval{Socket::SO_PROTOCOL}));
373 ${*$sock}{'io_socket_proto'};
374}
375
37616µs1;
377
378__END__
 
# spent 103µs within IO::Socket::CORE:connect which was called 3 times, avg 34µs/call: # 2 times (101µs+0s) by IO::Socket::connect at line 114, avg 50µs/call # once (2µs+0s) by IO::Socket::connect at line 122
sub IO::Socket::CORE:connect; # opcode
# spent 42µs within IO::Socket::CORE:socket which was called 2 times, avg 21µs/call: # 2 times (42µs+0s) by IO::Socket::socket at line 80, avg 21µs/call
sub IO::Socket::CORE:socket; # opcode
# spent 5µs within IO::Socket::CORE:ssockopt which was called: # once (5µs+0s) by IO::Socket::setsockopt at line 312
sub IO::Socket::CORE:ssockopt; # opcode