← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:46 2015

Filename/usr/lib/x86_64-linux-gnu/perl/5.20/IO/Handle.pm
StatementsExecuted 47 statements in 4.82ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.44ms1.80msIO::Handle::::BEGIN@9IO::Handle::BEGIN@9
111116µs116µsIO::Handle::::_create_getline_subsIO::Handle::_create_getline_subs (xsub)
41131µs57µsIO::Handle::::readIO::Handle::read
41126µs26µsIO::Handle::::CORE:readIO::Handle::CORE:read (opcode)
11124µs24µsIO::Handle::::BEGIN@3IO::Handle::BEGIN@3
41121µs21µsIO::Handle::::CORE:eofIO::Handle::CORE:eof (opcode)
11117µs34µsIO::Handle::::BEGIN@370IO::Handle::BEGIN@370
42115µs36µsIO::Handle::::eofIO::Handle::eof
21114µs29µsIO::Handle::::newIO::Handle::new
11110µs60µsIO::Handle::::BEGIN@6IO::Handle::BEGIN@6
1119µs50µsIO::Handle::::BEGIN@7IO::Handle::BEGIN@7
1118µs24µsIO::Handle::::BEGIN@4IO::Handle::BEGIN@4
1115µs5µsIO::Handle::::BEGIN@8IO::Handle::BEGIN@8
0000s0sIO::Handle::::DESTROYIO::Handle::DESTROY
0000s0sIO::Handle::::_open_mode_stringIO::Handle::_open_mode_string
0000s0sIO::Handle::::autoflushIO::Handle::autoflush
0000s0sIO::Handle::::closeIO::Handle::close
0000s0sIO::Handle::::constantIO::Handle::constant
0000s0sIO::Handle::::fcntlIO::Handle::fcntl
0000s0sIO::Handle::::fdopenIO::Handle::fdopen
0000s0sIO::Handle::::filenoIO::Handle::fileno
0000s0sIO::Handle::::format_formfeedIO::Handle::format_formfeed
0000s0sIO::Handle::::format_line_break_charactersIO::Handle::format_line_break_characters
0000s0sIO::Handle::::format_lines_leftIO::Handle::format_lines_left
0000s0sIO::Handle::::format_lines_per_pageIO::Handle::format_lines_per_page
0000s0sIO::Handle::::format_nameIO::Handle::format_name
0000s0sIO::Handle::::format_page_numberIO::Handle::format_page_number
0000s0sIO::Handle::::format_top_nameIO::Handle::format_top_name
0000s0sIO::Handle::::format_writeIO::Handle::format_write
0000s0sIO::Handle::::formlineIO::Handle::formline
0000s0sIO::Handle::::getcIO::Handle::getc
0000s0sIO::Handle::::input_line_numberIO::Handle::input_line_number
0000s0sIO::Handle::::input_record_separatorIO::Handle::input_record_separator
0000s0sIO::Handle::::ioctlIO::Handle::ioctl
0000s0sIO::Handle::::new_from_fdIO::Handle::new_from_fd
0000s0sIO::Handle::::openedIO::Handle::opened
0000s0sIO::Handle::::output_field_separatorIO::Handle::output_field_separator
0000s0sIO::Handle::::output_record_separatorIO::Handle::output_record_separator
0000s0sIO::Handle::::printIO::Handle::print
0000s0sIO::Handle::::printfIO::Handle::printf
0000s0sIO::Handle::::printflushIO::Handle::printflush
0000s0sIO::Handle::::sayIO::Handle::say
0000s0sIO::Handle::::statIO::Handle::stat
0000s0sIO::Handle::::sysreadIO::Handle::sysread
0000s0sIO::Handle::::syswriteIO::Handle::syswrite
0000s0sIO::Handle::::truncateIO::Handle::truncate
0000s0sIO::Handle::::writeIO::Handle::write
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package IO::Handle;
2
3260µs124µs
# spent 24µs within IO::Handle::BEGIN@3 which was called: # once (24µs+0s) by IO::Seekable::BEGIN@9 at line 3
use 5.006_001;
# spent 24µs making 1 call to IO::Handle::BEGIN@3
4264µs240µs
# spent 24µs (8+16) within IO::Handle::BEGIN@4 which was called: # once (8µs+16µs) by IO::Seekable::BEGIN@9 at line 4
use strict;
# spent 24µs making 1 call to IO::Handle::BEGIN@4 # spent 16µs making 1 call to strict::import
51600nsour($VERSION, @EXPORT_OK, @ISA);
6234µs2111µs
# spent 60µs (10+50) within IO::Handle::BEGIN@6 which was called: # once (10µs+50µs) by IO::Seekable::BEGIN@9 at line 6
use Carp;
# spent 60µs making 1 call to IO::Handle::BEGIN@6 # spent 50µs making 1 call to Exporter::import
7232µs292µs
# spent 50µs (9+42) within IO::Handle::BEGIN@7 which was called: # once (9µs+42µs) by IO::Seekable::BEGIN@9 at line 7
use Symbol;
# spent 50µs making 1 call to IO::Handle::BEGIN@7 # spent 42µs making 1 call to Exporter::import
8234µs15µs
# spent 5µs within IO::Handle::BEGIN@8 which was called: # once (5µs+0s) by IO::Seekable::BEGIN@9 at line 8
use SelectSaver;
# spent 5µs making 1 call to IO::Handle::BEGIN@8
924.07ms11.80ms
# spent 1.80ms (1.44+355µs) within IO::Handle::BEGIN@9 which was called: # once (1.44ms+355µs) by IO::Seekable::BEGIN@9 at line 9
use IO (); # Load the XS module
# spent 1.80ms making 1 call to IO::Handle::BEGIN@9
10
111900nsrequire Exporter;
12116µs@ISA = qw(Exporter);
13
141400ns$VERSION = "1.35";
15120µs$VERSION = eval $VERSION;
# spent 3µs executing statements in string eval
16
1713µs@EXPORT_OK = qw(
18 autoflush
19 output_field_separator
20 output_record_separator
21 input_record_separator
22 input_line_number
23 format_page_number
24 format_lines_per_page
25 format_lines_left
26 format_name
27 format_top_name
28 format_line_break_characters
29 format_formfeed
30 format_write
31
32 print
33 printf
34 say
35 getline
36 getlines
37
38 printflush
39 flush
40
41 SEEK_SET
42 SEEK_CUR
43 SEEK_END
44 _IOFBF
45 _IOLBF
46 _IONBF
47);
48
49################################################
50## Constructors, destructors.
51##
52
53
# spent 29µs (14+16) within IO::Handle::new which was called 2 times, avg 15µs/call: # 2 times (14µs+16µs) by IO::File::new at line 38 of IO/File.pm, avg 15µs/call
sub new {
5422µs my $class = ref($_[0]) || $_[0] || "IO::Handle";
5521µs if (@_ != 1) {
56 # Since perl will automatically require IO::File if needed, but
57 # also initialises IO::File's @ISA as part of the core we must
58 # ensure IO::File is loaded if IO::Handle is. This avoids effect-
59 # ively "half-loading" IO::File.
60 if ($] > 5.013 && $class eq 'IO::File' && !$INC{"IO/File.pm"}) {
61 require IO::File;
62 shift;
63 return IO::File::->new(@_);
64 }
65 croak "usage: $class->new()";
66 }
6725µs216µs my $io = gensym;
# spent 16µs making 2 calls to Symbol::gensym, avg 8µs/call
6828µs bless $io, $class;
69}
70
71sub new_from_fd {
72 my $class = ref($_[0]) || $_[0] || "IO::Handle";
73 @_ == 3 or croak "usage: $class->new_from_fd(FD, MODE)";
74 my $io = gensym;
75 shift;
76 IO::Handle::fdopen($io, @_)
77 or return undef;
78 bless $io, $class;
79}
80
81#
82# There is no need for DESTROY to do anything, because when the
83# last reference to an IO object is gone, Perl automatically
84# closes its associated files (if any). However, to avoid any
85# attempts to autoload DESTROY, we here define it to do nothing.
86#
87sub DESTROY {}
88
89################################################
90## Open and close.
91##
92
93sub _open_mode_string {
94 my ($mode) = @_;
95 $mode =~ /^\+?(<|>>?)$/
96 or $mode =~ s/^r(\+?)$/$1</
97 or $mode =~ s/^w(\+?)$/$1>/
98 or $mode =~ s/^a(\+?)$/$1>>/
99 or croak "IO::Handle: bad open mode: $mode";
100 $mode;
101}
102
103sub fdopen {
104 @_ == 3 or croak 'usage: $io->fdopen(FD, MODE)';
105 my ($io, $fd, $mode) = @_;
106 local(*GLOB);
107
108 if (ref($fd) && "".$fd =~ /GLOB\(/o) {
109 # It's a glob reference; Alias it as we cannot get name of anon GLOBs
110 my $n = qualify(*GLOB);
111 *GLOB = *{*$fd};
112 $fd = $n;
113 } elsif ($fd =~ m#^\d+$#) {
114 # It's an FD number; prefix with "=".
115 $fd = "=$fd";
116 }
117
118 open($io, _open_mode_string($mode) . '&' . $fd)
119 ? $io : undef;
120}
121
122sub close {
123 @_ == 1 or croak 'usage: $io->close()';
124 my($io) = @_;
125
126 close($io);
127}
128
129################################################
130## Normal I/O functions.
131##
132
133# flock
134# select
135
136sub opened {
137 @_ == 1 or croak 'usage: $io->opened()';
138 defined fileno($_[0]);
139}
140
141sub fileno {
142 @_ == 1 or croak 'usage: $io->fileno()';
143 fileno($_[0]);
144}
145
146sub getc {
147 @_ == 1 or croak 'usage: $io->getc()';
148 getc($_[0]);
149}
150
151
# spent 36µs (15+21) within IO::Handle::eof which was called 4 times, avg 9µs/call: # 2 times (10µs+17µs) by Date::Manip::TZ::_get_curr_zone at line 475 of Date/Manip/TZ.pm, avg 14µs/call # 2 times (5µs+4µs) by Date::Manip::TZ::_get_curr_zone at line 526 of Date/Manip/TZ.pm, avg 4µs/call
sub eof {
15241µs @_ == 1 or croak 'usage: $io->eof()';
153437µs421µs eof($_[0]);
# spent 21µs making 4 calls to IO::Handle::CORE:eof, avg 5µs/call
154}
155
156sub print {
157 @_ or croak 'usage: $io->print(ARGS)';
158 my $this = shift;
159 print $this @_;
160}
161
162sub printf {
163 @_ >= 2 or croak 'usage: $io->printf(FMT,[ARGS])';
164 my $this = shift;
165 printf $this @_;
166}
167
168sub say {
169 @_ or croak 'usage: $io->say(ARGS)';
170 my $this = shift;
171 local $\ = "\n";
172 print $this @_;
173}
174
175# Special XS wrapper to make them inherit lexical hints from the caller.
1761121µs1116µs_create_getline_subs( <<'END' ) or die $@;
# spent 116µs making 1 call to IO::Handle::_create_getline_subs
# spent 3µs executing statements in string eval
177sub getline {
178 @_ == 1 or croak 'usage: $io->getline()';
179 my $this = shift;
180 return scalar <$this>;
181}
182
183sub getlines {
184 @_ == 1 or croak 'usage: $io->getlines()';
185 wantarray or
186 croak 'Can\'t call $io->getlines in a scalar context, use $io->getline';
187 my $this = shift;
188 return <$this>;
189}
1901; # return true for error checking
191END
192
19312µs*gets = \&getline; # deprecated
194
195sub truncate {
196 @_ == 2 or croak 'usage: $io->truncate(LEN)';
197 truncate($_[0], $_[1]);
198}
199
200
# spent 57µs (31+26) within IO::Handle::read which was called 4 times, avg 14µs/call: # 4 times (31µs+26µs) by XML::Parser::Expat::ParseStream at line 470 of XML/Parser/Expat.pm, avg 14µs/call
sub read {
20142µs @_ == 3 || @_ == 4 or croak 'usage: $io->read(BUF, LEN [, OFFSET])';
202455µs426µs read($_[0], $_[1], $_[2], $_[3] || 0);
# spent 26µs making 4 calls to IO::Handle::CORE:read, avg 6µs/call
203}
204
205sub sysread {
206 @_ == 3 || @_ == 4 or croak 'usage: $io->sysread(BUF, LEN [, OFFSET])';
207 sysread($_[0], $_[1], $_[2], $_[3] || 0);
208}
209
210sub write {
211 @_ >= 2 && @_ <= 4 or croak 'usage: $io->write(BUF [, LEN [, OFFSET]])';
212 local($\) = "";
213 $_[2] = length($_[1]) unless defined $_[2];
214 print { $_[0] } substr($_[1], $_[3] || 0, $_[2]);
215}
216
217sub syswrite {
218 @_ >= 2 && @_ <= 4 or croak 'usage: $io->syswrite(BUF [, LEN [, OFFSET]])';
219 if (defined($_[2])) {
220 syswrite($_[0], $_[1], $_[2], $_[3] || 0);
221 } else {
222 syswrite($_[0], $_[1]);
223 }
224}
225
226sub stat {
227 @_ == 1 or croak 'usage: $io->stat()';
228 stat($_[0]);
229}
230
231################################################
232## State modification functions.
233##
234
235sub autoflush {
236 my $old = new SelectSaver qualify($_[0], caller);
237 my $prev = $|;
238 $| = @_ > 1 ? $_[1] : 1;
239 $prev;
240}
241
242sub output_field_separator {
243 carp "output_field_separator is not supported on a per-handle basis"
244 if ref($_[0]);
245 my $prev = $,;
246 $, = $_[1] if @_ > 1;
247 $prev;
248}
249
250sub output_record_separator {
251 carp "output_record_separator is not supported on a per-handle basis"
252 if ref($_[0]);
253 my $prev = $\;
254 $\ = $_[1] if @_ > 1;
255 $prev;
256}
257
258sub input_record_separator {
259 carp "input_record_separator is not supported on a per-handle basis"
260 if ref($_[0]);
261 my $prev = $/;
262 $/ = $_[1] if @_ > 1;
263 $prev;
264}
265
266sub input_line_number {
267 local $.;
268 () = tell qualify($_[0], caller) if ref($_[0]);
269 my $prev = $.;
270 $. = $_[1] if @_ > 1;
271 $prev;
272}
273
274sub format_page_number {
275 my $old;
276 $old = new SelectSaver qualify($_[0], caller) if ref($_[0]);
277 my $prev = $%;
278 $% = $_[1] if @_ > 1;
279 $prev;
280}
281
282sub format_lines_per_page {
283 my $old;
284 $old = new SelectSaver qualify($_[0], caller) if ref($_[0]);
285 my $prev = $=;
286 $= = $_[1] if @_ > 1;
287 $prev;
288}
289
290sub format_lines_left {
291 my $old;
292 $old = new SelectSaver qualify($_[0], caller) if ref($_[0]);
293 my $prev = $-;
294 $- = $_[1] if @_ > 1;
295 $prev;
296}
297
298sub format_name {
299 my $old;
300 $old = new SelectSaver qualify($_[0], caller) if ref($_[0]);
301 my $prev = $~;
302 $~ = qualify($_[1], caller) if @_ > 1;
303 $prev;
304}
305
306sub format_top_name {
307 my $old;
308 $old = new SelectSaver qualify($_[0], caller) if ref($_[0]);
309 my $prev = $^;
310 $^ = qualify($_[1], caller) if @_ > 1;
311 $prev;
312}
313
314sub format_line_break_characters {
315 carp "format_line_break_characters is not supported on a per-handle basis"
316 if ref($_[0]);
317 my $prev = $:;
318 $: = $_[1] if @_ > 1;
319 $prev;
320}
321
322sub format_formfeed {
323 carp "format_formfeed is not supported on a per-handle basis"
324 if ref($_[0]);
325 my $prev = $^L;
326 $^L = $_[1] if @_ > 1;
327 $prev;
328}
329
330sub formline {
331 my $io = shift;
332 my $picture = shift;
333 local($^A) = $^A;
334 local($\) = "";
335 formline($picture, @_);
336 print $io $^A;
337}
338
339sub format_write {
340 @_ < 3 || croak 'usage: $io->write( [FORMAT_NAME] )';
341 if (@_ == 2) {
342 my ($io, $fmt) = @_;
343 my $oldfmt = $io->format_name(qualify($fmt,caller));
344 CORE::write($io);
345 $io->format_name($oldfmt);
346 } else {
347 CORE::write($_[0]);
348 }
349}
350
351sub fcntl {
352 @_ == 3 || croak 'usage: $io->fcntl( OP, VALUE );';
353 my ($io, $op) = @_;
354 return fcntl($io, $op, $_[2]);
355}
356
357sub ioctl {
358 @_ == 3 || croak 'usage: $io->ioctl( OP, VALUE );';
359 my ($io, $op) = @_;
360 return ioctl($io, $op, $_[2]);
361}
362
363# this sub is for compatibility with older releases of IO that used
364# a sub called constant to determine if a constant existed -- GMB
365#
366# The SEEK_* and _IO?BF constants were the only constants at that time
367# any new code should just check defined(&CONSTANT_NAME)
368
369sub constant {
3702245µs251µs
# spent 34µs (17+17) within IO::Handle::BEGIN@370 which was called: # once (17µs+17µs) by IO::Seekable::BEGIN@9 at line 370
no strict 'refs';
# spent 34µs making 1 call to IO::Handle::BEGIN@370 # spent 17µs making 1 call to strict::unimport
371 my $name = shift;
372 (($name =~ /^(SEEK_(SET|CUR|END)|_IO[FLN]BF)$/) && defined &{$name})
373 ? &{$name}() : undef;
374}
375
376# so that flush.pl can be deprecated
377
378sub printflush {
379 my $io = shift;
380 my $old;
381 $old = new SelectSaver qualify($io, caller) if ref($io);
382 local $| = 1;
383 if(ref($io)) {
384 print $io @_;
385 }
386 else {
387 print @_;
388 }
389}
390
39119µs1;
 
# spent 21µs within IO::Handle::CORE:eof which was called 4 times, avg 5µs/call: # 4 times (21µs+0s) by IO::Handle::eof at line 153, avg 5µs/call
sub IO::Handle::CORE:eof; # opcode
# spent 26µs within IO::Handle::CORE:read which was called 4 times, avg 6µs/call: # 4 times (26µs+0s) by IO::Handle::read at line 202, avg 6µs/call
sub IO::Handle::CORE:read; # opcode
# spent 116µs within IO::Handle::_create_getline_subs which was called: # once (116µs+0s) by IO::Seekable::BEGIN@9 at line 176
sub IO::Handle::_create_getline_subs; # xsub