Filename | /usr/lib/perl/5.18/IO/Select.pm |
Statements | Executed 78 statements in 1.36ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 28µs | 42µs | select | IO::Select::
1 | 1 | 1 | 19µs | 30µs | _update | IO::Select::
1 | 1 | 1 | 16µs | 30µs | BEGIN@9 | IO::Select::
1 | 1 | 1 | 10µs | 10µs | CORE:sselect (opcode) | IO::Select::
1 | 1 | 1 | 9µs | 101µs | BEGIN@10 | IO::Select::
1 | 1 | 1 | 8µs | 11µs | _fileno | IO::Select::
1 | 1 | 1 | 8µs | 43µs | new | IO::Select::
1 | 1 | 1 | 8µs | 42µs | BEGIN@11 | IO::Select::
1 | 1 | 1 | 4µs | 35µs | add | IO::Select::
1 | 1 | 1 | 3µs | 3µs | CORE:match (opcode) | IO::Select::
1 | 1 | 1 | 3µs | 3µs | _max | IO::Select::
0 | 0 | 0 | 0s | 0s | as_string | IO::Select::
0 | 0 | 0 | 0s | 0s | bits | IO::Select::
0 | 0 | 0 | 0s | 0s | can_read | IO::Select::
0 | 0 | 0 | 0s | 0s | can_write | IO::Select::
0 | 0 | 0 | 0s | 0s | count | IO::Select::
0 | 0 | 0 | 0s | 0s | exists | IO::Select::
0 | 0 | 0 | 0s | 0s | handles | IO::Select::
0 | 0 | 0 | 0s | 0s | has_error | IO::Select::
0 | 0 | 0 | 0s | 0s | has_exception | IO::Select::
0 | 0 | 0 | 0s | 0s | remove | IO::Select::
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 | |||||
7 | package IO::Select; | ||||
8 | |||||
9 | 2 | 29µs | 2 | 44µ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 # spent 30µs making 1 call to IO::Select::BEGIN@9
# spent 14µs making 1 call to strict::import |
10 | 2 | 36µs | 2 | 194µ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 # spent 101µs making 1 call to IO::Select::BEGIN@10
# spent 92µs making 1 call to warnings::register::import |
11 | 2 | 1.20ms | 2 | 76µ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 # spent 42µs making 1 call to IO::Select::BEGIN@11
# spent 34µs making 1 call to vars::import |
12 | 1 | 600ns | require Exporter; | ||
13 | |||||
14 | 1 | 600ns | $VERSION = "1.21"; | ||
15 | |||||
16 | 1 | 6µs | @ISA = qw(Exporter); # This is only so we can do version checking | ||
17 | |||||
18 | sub VEC_BITS () {0} | ||||
19 | sub FD_COUNT () {1} | ||||
20 | sub FIRST_FD () {2} | ||||
21 | |||||
22 | sub 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 | ||||
24 | 1 | 800ns | my $self = shift; | ||
25 | 1 | 500ns | my $type = ref($self) || $self; | ||
26 | |||||
27 | 1 | 2µs | my $vec = bless [undef,0], $type; | ||
28 | |||||
29 | 1 | 2µs | 1 | 35µs | $vec->add(@_) # spent 35µs making 1 call to IO::Select::add |
30 | if @_; | ||||
31 | |||||
32 | 1 | 3µs | $vec; | ||
33 | } | ||||
34 | |||||
35 | sub 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 | ||||
37 | 1 | 4µs | 1 | 30µs | shift->_update('add', @_); # spent 30µs making 1 call to IO::Select::_update |
38 | } | ||||
39 | |||||
40 | sub remove | ||||
41 | { | ||||
42 | shift->_update('remove', @_); | ||||
43 | } | ||||
44 | |||||
45 | sub 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 | |||||
53 | sub _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 | ||||
55 | 1 | 400ns | my($self, $f) = @_; | ||
56 | 1 | 200ns | return unless defined $f; | ||
57 | 1 | 600ns | $f = $f->[0] if ref($f) eq 'ARRAY'; | ||
58 | 1 | 12µs | 1 | 3µs | ($f =~ /^\d+$/) ? $f : fileno($f); # spent 3µs making 1 call to IO::Select::CORE:match |
59 | } | ||||
60 | |||||
61 | sub _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 | ||||
63 | 1 | 300ns | my $vec = shift; | ||
64 | 1 | 700ns | my $add = shift eq 'add'; | ||
65 | |||||
66 | 1 | 4µs | my $bits = $vec->[VEC_BITS]; | ||
67 | 1 | 700ns | $bits = '' unless defined $bits; | ||
68 | |||||
69 | 1 | 300ns | my $count = 0; | ||
70 | 1 | 100ns | my $f; | ||
71 | 1 | 1µs | foreach $f (@_) | ||
72 | { | ||||
73 | 1 | 2µs | 1 | 11µs | my $fn = $vec->_fileno($f); # spent 11µs making 1 call to IO::Select::_fileno |
74 | 1 | 300ns | if ($add) { | ||
75 | 1 | 200ns | next unless defined $fn; | ||
76 | 1 | 700ns | my $i = $fn + FIRST_FD; | ||
77 | 1 | 600ns | if (defined $vec->[$i]) { | ||
78 | $vec->[$i] = $f; # if array rest might be different, so we update | ||||
79 | next; | ||||
80 | } | ||||
81 | 1 | 600ns | $vec->[FD_COUNT]++; | ||
82 | 1 | 2µs | vec($bits, $fn, 1) = 1; | ||
83 | 1 | 800ns | $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 | } | ||||
96 | 1 | 1µs | $count++; | ||
97 | } | ||||
98 | 1 | 700ns | $vec->[VEC_BITS] = $vec->[FD_COUNT] ? $bits : undef; | ||
99 | 1 | 3µs | $count; | ||
100 | } | ||||
101 | |||||
102 | sub 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 | |||||
113 | sub 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 | |||||
124 | sub 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 | |||||
135 | sub 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 | |||||
142 | sub count | ||||
143 | { | ||||
144 | my $vec = shift; | ||||
145 | $vec->[FD_COUNT]; | ||||
146 | } | ||||
147 | |||||
148 | sub bits | ||||
149 | { | ||||
150 | my $vec = shift; | ||||
151 | $vec->[VEC_BITS]; | ||||
152 | } | ||||
153 | |||||
154 | sub 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 | |||||
170 | sub _max | ||||
171 | # spent 3µs within IO::Select::_max which was called:
# once (3µs+0s) by IO::Select::select at line 199 | ||||
172 | 1 | 600ns | my($a,$b,$c) = @_; | ||
173 | 1 | 4µs | $a > $b | ||
174 | ? $a > $c | ||||
175 | ? $a | ||||
176 | : $c | ||||
177 | : $b > $c | ||||
178 | ? $b | ||||
179 | : $c; | ||||
180 | } | ||||
181 | |||||
182 | sub 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 | ||||
185 | 1 | 300ns | if defined $_[0] && !ref($_[0]); | ||
186 | |||||
187 | 1 | 900ns | my($r,$w,$e,$t) = @_; | ||
188 | 1 | 500ns | my @result = (); | ||
189 | |||||
190 | 1 | 400ns | my $rb = defined $r ? $r->[VEC_BITS] : undef; | ||
191 | 1 | 700ns | my $wb = defined $w ? $w->[VEC_BITS] : undef; | ||
192 | 1 | 500ns | my $eb = defined $e ? $e->[VEC_BITS] : undef; | ||
193 | |||||
194 | 1 | 16µs | 1 | 10µs | if(select($rb,$wb,$eb,$t) > 0) # spent 10µs making 1 call to IO::Select::CORE:sselect |
195 | { | ||||
196 | 1 | 400ns | my @r = (); | ||
197 | 1 | 400ns | my @w = (); | ||
198 | 1 | 200ns | my @e = (); | ||
199 | 1 | 4µs | 1 | 3µ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 | |||||
203 | 1 | 3µs | for( ; $i >= FIRST_FD ; $i--) | ||
204 | { | ||||
205 | 6 | 1µs | my $j = $i - FIRST_FD; | ||
206 | 6 | 600ns | push(@r, $r->[$i]) | ||
207 | if defined $rb && defined $r->[$i] && vec($rb, $j, 1); | ||||
208 | 6 | 2µs | push(@w, $w->[$i]) | ||
209 | if defined $wb && defined $w->[$i] && vec($wb, $j, 1); | ||||
210 | 6 | 2µs | push(@e, $e->[$i]) | ||
211 | if defined $eb && defined $e->[$i] && vec($eb, $j, 1); | ||||
212 | } | ||||
213 | |||||
214 | 1 | 2µs | @result = (\@r, \@w, \@e); | ||
215 | } | ||||
216 | 1 | 4µs | @result; | ||
217 | } | ||||
218 | |||||
219 | sub 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 | |||||
237 | 1 | 4µs | 1; | ||
238 | __END__ | ||||
# spent 3µs within IO::Select::CORE:match which was called:
# once (3µs+0s) by IO::Select::_fileno at line 58 | |||||
# spent 10µs within IO::Select::CORE:sselect which was called:
# once (10µs+0s) by IO::Select::select at line 194 |