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

Filename/usr/lib/perl/5.18/IO/Select.pm
StatementsExecuted 78 statements in 1.36ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11128µs42µsIO::Select::::selectIO::Select::select
11119µs30µsIO::Select::::_updateIO::Select::_update
11116µs30µsIO::Select::::BEGIN@9IO::Select::BEGIN@9
11110µs10µsIO::Select::::CORE:sselectIO::Select::CORE:sselect (opcode)
1119µs101µsIO::Select::::BEGIN@10IO::Select::BEGIN@10
1118µs11µsIO::Select::::_filenoIO::Select::_fileno
1118µs43µsIO::Select::::newIO::Select::new
1118µs42µsIO::Select::::BEGIN@11IO::Select::BEGIN@11
1114µs35µsIO::Select::::addIO::Select::add
1113µs3µsIO::Select::::CORE:matchIO::Select::CORE:match (opcode)
1113µs3µsIO::Select::::_maxIO::Select::_max
0000s0sIO::Select::::as_stringIO::Select::as_string
0000s0sIO::Select::::bitsIO::Select::bits
0000s0sIO::Select::::can_readIO::Select::can_read
0000s0sIO::Select::::can_writeIO::Select::can_write
0000s0sIO::Select::::countIO::Select::count
0000s0sIO::Select::::existsIO::Select::exists
0000s0sIO::Select::::handlesIO::Select::handles
0000s0sIO::Select::::has_errorIO::Select::has_error
0000s0sIO::Select::::has_exceptionIO::Select::has_exception
0000s0sIO::Select::::removeIO::Select::remove
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# IO::Select.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::Select;
8
9229µs244µs
# spent 30µs (16+14) within IO::Select::BEGIN@9 which was called: # once (16µs+14µs) by Search::Elasticsearch::Role::CxnPool::BEGIN@6 at line 9
use strict;
# spent 30µs making 1 call to IO::Select::BEGIN@9 # spent 14µs making 1 call to strict::import
10236µs2194µs
# spent 101µs (9+92) within IO::Select::BEGIN@10 which was called: # once (9µs+92µs) by Search::Elasticsearch::Role::CxnPool::BEGIN@6 at line 10
use warnings::register;
# spent 101µs making 1 call to IO::Select::BEGIN@10 # spent 92µs making 1 call to warnings::register::import
1121.20ms276µs
# spent 42µs (8+34) within IO::Select::BEGIN@11 which was called: # once (8µs+34µs) by Search::Elasticsearch::Role::CxnPool::BEGIN@6 at line 11
use vars qw($VERSION @ISA);
# spent 42µs making 1 call to IO::Select::BEGIN@11 # spent 34µs making 1 call to vars::import
121600nsrequire Exporter;
13
141600ns$VERSION = "1.21";
15
1616µs@ISA = qw(Exporter); # This is only so we can do version checking
17
18sub VEC_BITS () {0}
19sub FD_COUNT () {1}
20sub FIRST_FD () {2}
21
22sub new
23
# spent 43µs (8+35) within IO::Select::new which was called: # once (8µs+35µs) by IO::Socket::connect at line 118 of IO/Socket.pm
{
241800ns my $self = shift;
251500ns my $type = ref($self) || $self;
26
2712µs my $vec = bless [undef,0], $type;
28
2912µs135µs $vec->add(@_)
# spent 35µs making 1 call to IO::Select::add
30 if @_;
31
3213µs $vec;
33}
34
35sub add
36
# spent 35µs (4+30) within IO::Select::add which was called: # once (4µs+30µs) by IO::Select::new at line 29
{
3714µs130µs shift->_update('add', @_);
# spent 30µs making 1 call to IO::Select::_update
38}
39
40sub remove
41{
42 shift->_update('remove', @_);
43}
44
45sub exists
46{
47 my $vec = shift;
48 my $fno = $vec->_fileno(shift);
49 return undef unless defined $fno;
50 $vec->[$fno + FIRST_FD];
51}
52
53sub _fileno
54
# spent 11µs (8+3) within IO::Select::_fileno which was called: # once (8µs+3µs) by IO::Select::_update at line 73
{
551400ns my($self, $f) = @_;
561200ns return unless defined $f;
571600ns $f = $f->[0] if ref($f) eq 'ARRAY';
58112µs13µs ($f =~ /^\d+$/) ? $f : fileno($f);
# spent 3µs making 1 call to IO::Select::CORE:match
59}
60
61sub _update
62
# spent 30µs (19+11) within IO::Select::_update which was called: # once (19µs+11µs) by IO::Select::add at line 37
{
631300ns my $vec = shift;
641700ns my $add = shift eq 'add';
65
6614µs my $bits = $vec->[VEC_BITS];
671700ns $bits = '' unless defined $bits;
68
691300ns my $count = 0;
701100ns my $f;
7111µs foreach $f (@_)
72 {
7312µs111µs my $fn = $vec->_fileno($f);
# spent 11µs making 1 call to IO::Select::_fileno
741300ns if ($add) {
751200ns next unless defined $fn;
761700ns my $i = $fn + FIRST_FD;
771600ns if (defined $vec->[$i]) {
78 $vec->[$i] = $f; # if array rest might be different, so we update
79 next;
80 }
811600ns $vec->[FD_COUNT]++;
8212µs vec($bits, $fn, 1) = 1;
831800ns $vec->[$i] = $f;
84 } else { # remove
85 if ( ! defined $fn ) { # remove if fileno undef'd
86 defined($_) && $_ == $f and do { $vec->[FD_COUNT]--; $_ = undef; }
87 for @{$vec}[FIRST_FD .. $#$vec];
88 next;
89 }
90 my $i = $fn + FIRST_FD;
91 next unless defined $vec->[$i];
92 $vec->[FD_COUNT]--;
93 vec($bits, $fn, 1) = 0;
94 $vec->[$i] = undef;
95 }
9611µs $count++;
97 }
981700ns $vec->[VEC_BITS] = $vec->[FD_COUNT] ? $bits : undef;
9913µs $count;
100}
101
102sub can_read
103{
104 my $vec = shift;
105 my $timeout = shift;
106 my $r = $vec->[VEC_BITS];
107
108 defined($r) && (select($r,undef,undef,$timeout) > 0)
109 ? handles($vec, $r)
110 : ();
111}
112
113sub can_write
114{
115 my $vec = shift;
116 my $timeout = shift;
117 my $w = $vec->[VEC_BITS];
118
119 defined($w) && (select(undef,$w,undef,$timeout) > 0)
120 ? handles($vec, $w)
121 : ();
122}
123
124sub has_exception
125{
126 my $vec = shift;
127 my $timeout = shift;
128 my $e = $vec->[VEC_BITS];
129
130 defined($e) && (select(undef,undef,$e,$timeout) > 0)
131 ? handles($vec, $e)
132 : ();
133}
134
135sub has_error
136{
137 warnings::warn("Call to deprecated method 'has_error', use 'has_exception'")
138 if warnings::enabled();
139 goto &has_exception;
140}
141
142sub count
143{
144 my $vec = shift;
145 $vec->[FD_COUNT];
146}
147
148sub bits
149{
150 my $vec = shift;
151 $vec->[VEC_BITS];
152}
153
154sub as_string # for debugging
155{
156 my $vec = shift;
157 my $str = ref($vec) . ": ";
158 my $bits = $vec->bits;
159 my $count = $vec->count;
160 $str .= defined($bits) ? unpack("b*", $bits) : "undef";
161 $str .= " $count";
162 my @handles = @$vec;
163 splice(@handles, 0, FIRST_FD);
164 for (@handles) {
165 $str .= " " . (defined($_) ? "$_" : "-");
166 }
167 $str;
168}
169
170sub _max
171
# spent 3µs within IO::Select::_max which was called: # once (3µs+0s) by IO::Select::select at line 199
{
1721600ns my($a,$b,$c) = @_;
17314µs $a > $b
174 ? $a > $c
175 ? $a
176 : $c
177 : $b > $c
178 ? $b
179 : $c;
180}
181
182sub select
183
# spent 42µs (28+13) within IO::Select::select which was called: # once (28µs+13µs) by IO::Socket::connect at line 121 of IO/Socket.pm
{
184 shift
1851300ns if defined $_[0] && !ref($_[0]);
186
1871900ns my($r,$w,$e,$t) = @_;
1881500ns my @result = ();
189
1901400ns my $rb = defined $r ? $r->[VEC_BITS] : undef;
1911700ns my $wb = defined $w ? $w->[VEC_BITS] : undef;
1921500ns my $eb = defined $e ? $e->[VEC_BITS] : undef;
193
194116µs110µs if(select($rb,$wb,$eb,$t) > 0)
# spent 10µs making 1 call to IO::Select::CORE:sselect
195 {
1961400ns my @r = ();
1971400ns my @w = ();
1981200ns my @e = ();
19914µs13µs my $i = _max(defined $r ? scalar(@$r)-1 : 0,
# spent 3µs making 1 call to IO::Select::_max
200 defined $w ? scalar(@$w)-1 : 0,
201 defined $e ? scalar(@$e)-1 : 0);
202
20313µs for( ; $i >= FIRST_FD ; $i--)
204 {
20561µs my $j = $i - FIRST_FD;
2066600ns push(@r, $r->[$i])
207 if defined $rb && defined $r->[$i] && vec($rb, $j, 1);
20862µs push(@w, $w->[$i])
209 if defined $wb && defined $w->[$i] && vec($wb, $j, 1);
21062µs push(@e, $e->[$i])
211 if defined $eb && defined $e->[$i] && vec($eb, $j, 1);
212 }
213
21412µs @result = (\@r, \@w, \@e);
215 }
21614µs @result;
217}
218
219sub handles
220{
221 my $vec = shift;
222 my $bits = shift;
223 my @h = ();
224 my $i;
225 my $max = scalar(@$vec) - 1;
226
227 for ($i = FIRST_FD; $i <= $max; $i++)
228 {
229 next unless defined $vec->[$i];
230 push(@h, $vec->[$i])
231 if !defined($bits) || vec($bits, $i - FIRST_FD, 1);
232 }
233
234 @h;
235}
236
23714µs1;
238__END__
 
# spent 3µs within IO::Select::CORE:match which was called: # once (3µs+0s) by IO::Select::_fileno at line 58
sub IO::Select::CORE:match; # opcode
# spent 10µs within IO::Select::CORE:sselect which was called: # once (10µs+0s) by IO::Select::select at line 194
sub IO::Select::CORE:sselect; # opcode