Filename | /usr/lib64/perl5/vendor_perl/5.16.0/IO/AtomicFile.pm |
Statements | Executed 828 statements in 27.6ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
39 | 1 | 1 | 13.4ms | 13.4ms | CORE:rename (opcode) | IO::AtomicFile::
1 | 1 | 1 | 4.44ms | 44.2ms | BEGIN@9 | IO::AtomicFile::
39 | 1 | 1 | 3.60ms | 23.3ms | close | IO::AtomicFile::
39 | 1 | 1 | 2.83ms | 22.1ms | open | IO::AtomicFile::
39 | 1 | 1 | 2.51ms | 8.67ms | new | IO::AtomicFile::
39 | 1 | 1 | 1.06ms | 26.3ms | DESTROY | IO::AtomicFile::
39 | 1 | 1 | 767µs | 767µs | _closed | IO::AtomicFile::
1 | 1 | 1 | 96µs | 193µs | BEGIN@6 | IO::AtomicFile::
1 | 1 | 1 | 60µs | 284µs | BEGIN@17 | IO::AtomicFile::
0 | 0 | 0 | 0s | 0s | delete | IO::AtomicFile::
0 | 0 | 0 | 0s | 0s | detach | IO::AtomicFile::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package IO::AtomicFile; | ||||
2 | |||||
3 | ### DOCUMENTATION AT BOTTOM OF FILE | ||||
4 | |||||
5 | # Be strict: | ||||
6 | 2 | 164µs | 2 | 290µs | # spent 193µs (96+97) within IO::AtomicFile::BEGIN@6 which was called:
# once (96µs+97µs) by base::import at line 6 # spent 193µs making 1 call to IO::AtomicFile::BEGIN@6
# spent 97µs making 1 call to strict::import |
7 | |||||
8 | # External modules: | ||||
9 | 2 | 812µs | 2 | 45.2ms | # spent 44.2ms (4.44+39.7) within IO::AtomicFile::BEGIN@9 which was called:
# once (4.44ms+39.7ms) by base::import at line 9 # spent 44.2ms making 1 call to IO::AtomicFile::BEGIN@9
# spent 988µs making 1 call to Exporter::import |
10 | |||||
11 | |||||
12 | #------------------------------ | ||||
13 | # | ||||
14 | # GLOBALS... | ||||
15 | # | ||||
16 | #------------------------------ | ||||
17 | 2 | 2.10ms | 2 | 508µs | # spent 284µs (60+224) within IO::AtomicFile::BEGIN@17 which was called:
# once (60µs+224µs) by base::import at line 17 # spent 284µs making 1 call to IO::AtomicFile::BEGIN@17
# spent 224µs making 1 call to vars::import |
18 | |||||
19 | # The package version, both in 1.23 style *and* usable by MakeMaker: | ||||
20 | 1 | 4µs | $VERSION = "2.110"; | ||
21 | |||||
22 | # Inheritance: | ||||
23 | 1 | 46µs | @ISA = qw(IO::File); | ||
24 | |||||
25 | |||||
26 | #------------------------------ | ||||
27 | # new ARGS... | ||||
28 | #------------------------------ | ||||
29 | # Class method, constructor. | ||||
30 | # Any arguments are sent to open(). | ||||
31 | # | ||||
32 | # spent 8.67ms (2.51+6.15) within IO::AtomicFile::new which was called 39 times, avg 222µs/call:
# 39 times (2.51ms+6.15ms) by RTP::IO::AtomicFile::new at line 29 of webmerge/scripts/modules/RTP/IO/AtomicFile.pm, avg 222µs/call | ||||
33 | 39 | 130µs | my $class = shift; | ||
34 | 39 | 1.32ms | 39 | 6.15ms | my $self = $class->SUPER::new(); # spent 6.15ms making 39 calls to IO::File::new, avg 158µs/call |
35 | 39 | 436µs | ${*$self}{'io_atomicfile_suffix'} = ''; | ||
36 | 39 | 69µs | $self->open(@_) if @_; | ||
37 | 39 | 778µs | $self; | ||
38 | } | ||||
39 | |||||
40 | #------------------------------ | ||||
41 | # DESTROY | ||||
42 | #------------------------------ | ||||
43 | # Destructor. | ||||
44 | # | ||||
45 | # spent 26.3ms (1.06+25.3) within IO::AtomicFile::DESTROY which was called 39 times, avg 675µs/call:
# 39 times (1.06ms+25.3ms) by RTP::IO::AtomicFile::DESTROY at line 43 of webmerge/scripts/modules/RTP/IO/AtomicFile.pm, avg 675µs/call | ||||
46 | 39 | 976µs | 39 | 25.3ms | shift->close(1); ### like close, but raises fatal exception on failure # spent 25.3ms making 39 calls to RTP::IO::AtomicFile::close, avg 648µs/call |
47 | } | ||||
48 | |||||
49 | #------------------------------ | ||||
50 | # open PATH, MODE | ||||
51 | #------------------------------ | ||||
52 | # Class/instance method. | ||||
53 | # | ||||
54 | # spent 22.1ms (2.83+19.2) within IO::AtomicFile::open which was called 39 times, avg 566µs/call:
# 39 times (2.83ms+19.2ms) by RTP::IO::AtomicFile::open at line 56 of webmerge/scripts/modules/RTP/IO/AtomicFile.pm, avg 566µs/call | ||||
55 | 39 | 263µs | my ($self, $path, $mode) = @_; | ||
56 | 39 | 134µs | ref($self) or $self = $self->new; ### now we have an instance! | ||
57 | |||||
58 | ### Create tmp path, and remember this info: | ||||
59 | 39 | 486µs | my $temp = "${path}..TMP" . ${*$self}{'io_atomicfile_suffix'}; | ||
60 | 39 | 240µs | ${*$self}{'io_atomicfile_temp'} = $temp; | ||
61 | 39 | 175µs | ${*$self}{'io_atomicfile_path'} = $path; | ||
62 | |||||
63 | ### Open the file! Returns filehandle on success, for use as a constructor: | ||||
64 | 39 | 1.46ms | 39 | 19.2ms | $self->SUPER::open($temp, $mode) ? $self : undef; # spent 19.2ms making 39 calls to IO::File::open, avg 493µs/call |
65 | } | ||||
66 | |||||
67 | #------------------------------ | ||||
68 | # _closed [YESNO] | ||||
69 | #------------------------------ | ||||
70 | # Instance method, private. | ||||
71 | # Are we already closed? Argument sets new value, returns previous one. | ||||
72 | # | ||||
73 | # spent 767µs within IO::AtomicFile::_closed which was called 39 times, avg 20µs/call:
# 39 times (767µs+0s) by RTP::IO::AtomicFile::_closed at line 70 of webmerge/scripts/modules/RTP/IO/AtomicFile.pm, avg 20µs/call | ||||
74 | 39 | 84µs | my $self = shift; | ||
75 | 39 | 119µs | my $oldval = ${*$self}{'io_atomicfile_closed'}; | ||
76 | 39 | 176µs | ${*$self}{'io_atomicfile_closed'} = shift if @_; | ||
77 | 39 | 687µs | $oldval; | ||
78 | } | ||||
79 | |||||
80 | #------------------------------ | ||||
81 | # close | ||||
82 | #------------------------------ | ||||
83 | # Instance method. | ||||
84 | # Close the handle, and rename the temp file to its final name. | ||||
85 | # | ||||
86 | # spent 23.3ms (3.60+19.7) within IO::AtomicFile::close which was called 39 times, avg 598µs/call:
# 39 times (3.60ms+19.7ms) by RTP::IO::AtomicFile::close at line 84 of webmerge/scripts/modules/RTP/IO/AtomicFile.pm, avg 598µs/call | ||||
87 | 39 | 150µs | my ($self, $die) = @_; | ||
88 | 39 | 608µs | 39 | 2.63ms | unless ($self->_closed(1)) { ### sentinel... # spent 2.63ms making 39 calls to RTP::IO::AtomicFile::_closed, avg 67µs/call |
89 | 39 | 1.00ms | 39 | 3.74ms | $self->SUPER::close(); # spent 3.74ms making 39 calls to IO::Handle::close, avg 96µs/call |
90 | rename(${*$self}{'io_atomicfile_temp'}, | ||||
91 | 39 | 14.5ms | 39 | 13.4ms | ${*$self}{'io_atomicfile_path'}) # spent 13.4ms making 39 calls to IO::AtomicFile::CORE:rename, avg 343µs/call |
92 | or ($die ? die "close atomic file: $!\n" : return undef); | ||||
93 | } | ||||
94 | 39 | 653µs | 1; | ||
95 | } | ||||
96 | |||||
97 | #------------------------------ | ||||
98 | # delete | ||||
99 | #------------------------------ | ||||
100 | # Instance method. | ||||
101 | # Close the handle, and delete the temp file. | ||||
102 | # | ||||
103 | sub delete { | ||||
104 | my $self = shift; | ||||
105 | unless ($self->_closed(1)) { ### sentinel... | ||||
106 | $self->SUPER::close(); | ||||
107 | return unlink(${*$self}{'io_atomicfile_temp'}); | ||||
108 | } | ||||
109 | 1; | ||||
110 | } | ||||
111 | |||||
112 | #------------------------------ | ||||
113 | # detach | ||||
114 | #------------------------------ | ||||
115 | # Instance method. | ||||
116 | # Close the handle, but DO NOT delete the temp file. | ||||
117 | # | ||||
118 | sub detach { | ||||
119 | my $self = shift; | ||||
120 | $self->SUPER::close() unless ($self->_closed(1)); | ||||
121 | 1; | ||||
122 | } | ||||
123 | |||||
124 | #------------------------------ | ||||
125 | 1 | 18µs | 1; | ||
126 | __END__ | ||||
# spent 13.4ms within IO::AtomicFile::CORE:rename which was called 39 times, avg 343µs/call:
# 39 times (13.4ms+0s) by IO::AtomicFile::close at line 91, avg 343µs/call |