Filename | /usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm |
Statements | Executed 1757 statements in 19.3ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1692 | 4 | 1 | 8.71ms | 17.0ms | __ANON__[:116] | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 6.11ms | 44.4ms | _FindMatchingZoneinfoFile | DateTime::TimeZone::Local::Unix::
1692 | 1 | 1 | 5.19ms | 5.19ms | CORE:ftfile (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 3.03ms | 3.33ms | BEGIN@12 | DateTime::TimeZone::Local::Unix::
1636 | 2 | 1 | 2.68ms | 2.68ms | CORE:ftlink (opcode) | DateTime::TimeZone::Local::Unix::
791 | 3 | 1 | 200µs | 200µs | CORE:ftsize (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 62µs | 52.7ms | FromEtcLocaltime | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 9µs | 9µs | BEGIN@5 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 9µs | 31µs | BEGIN@13 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 7µs | 10µs | BEGIN@9 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 7µs | 12µs | BEGIN@10 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 6µs | 6µs | CORE:fteread (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 3µs | 3µs | CORE:ftdir (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 2µs | 2µs | Methods | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 800ns | 800ns | EnvVars | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | FromEtcDefaultInit | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | FromEtcSysconfigClock | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | FromEtcTIMEZONE | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | FromEtcTimezone | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | _ReadEtcDefaultInit | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | _ReadEtcSysconfigClock | DateTime::TimeZone::Local::Unix::
0 | 0 | 0 | 0s | 0s | _Readlink | DateTime::TimeZone::Local::Unix::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::TimeZone::Local::Unix; | ||||
2 | { | ||||
3 | 2 | 1µs | $DateTime::TimeZone::Local::Unix::VERSION = '1.63'; | ||
4 | } | ||||
5 | # spent 9µs within DateTime::TimeZone::Local::Unix::BEGIN@5 which was called:
# once (9µs+0s) by Module::Runtime::require_module at line 7 | ||||
6 | 1 | 5µs | $DateTime::TimeZone::Local::Unix::AUTHORITY = 'cpan:DROLSKY'; | ||
7 | 1 | 21µs | 1 | 9µs | } # spent 9µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@5 |
8 | |||||
9 | 2 | 35µs | 2 | 13µs | # spent 10µs (7+3) within DateTime::TimeZone::Local::Unix::BEGIN@9 which was called:
# once (7µs+3µs) by Module::Runtime::require_module at line 9 # spent 10µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 25µs | 2 | 17µs | # spent 12µs (7+5) within DateTime::TimeZone::Local::Unix::BEGIN@10 which was called:
# once (7µs+5µs) by Module::Runtime::require_module at line 10 # spent 12µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | |||||
12 | 3 | 131µs | 3 | 3.38ms | # spent 3.33ms (3.03+297µs) within DateTime::TimeZone::Local::Unix::BEGIN@12 which was called:
# once (3.03ms+297µs) by Module::Runtime::require_module at line 12 # spent 3.33ms making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@12
# spent 39µs making 1 call to Exporter::import
# spent 12µs making 1 call to UNIVERSAL::VERSION |
13 | 2 | 922µs | 2 | 53µs | # spent 31µs (9+22) within DateTime::TimeZone::Local::Unix::BEGIN@13 which was called:
# once (9µs+22µs) by Module::Runtime::require_module at line 13 # spent 31µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@13
# spent 22µs making 1 call to parent::import |
14 | |||||
15 | # spent 2µs within DateTime::TimeZone::Local::Unix::Methods which was called:
# once (2µs+0s) by DateTime::TimeZone::Local::TimeZone at line 21 of DateTime/TimeZone/Local.pm | ||||
16 | 1 | 3µs | return qw( | ||
17 | FromEnv | ||||
18 | FromEtcLocaltime | ||||
19 | FromEtcTimezone | ||||
20 | FromEtcTIMEZONE | ||||
21 | FromEtcSysconfigClock | ||||
22 | FromEtcDefaultInit | ||||
23 | ); | ||||
24 | } | ||||
25 | |||||
26 | 1 | 3µs | # spent 800ns within DateTime::TimeZone::Local::Unix::EnvVars which was called:
# once (800ns+0s) by DateTime::TimeZone::Local::FromEnv at line 67 of DateTime/TimeZone/Local.pm | ||
27 | |||||
28 | # spent 52.7ms (62µs+52.6) within DateTime::TimeZone::Local::Unix::FromEtcLocaltime which was called:
# once (62µs+52.6ms) by DateTime::TimeZone::Local::TimeZone at line 22 of DateTime/TimeZone/Local.pm | ||||
29 | 33 | 69µs | my $class = shift; | ||
30 | |||||
31 | my $lt_file = '/etc/localtime'; | ||||
32 | |||||
33 | 2 | 6µs | return unless -r $lt_file && -s _; # spent 6µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:fteread
# spent 300ns making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize | ||
34 | |||||
35 | my $real_name; | ||||
36 | 1 | 5µs | if ( -l $lt_file ) { # spent 5µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftlink | ||
37 | |||||
38 | # The _Readlink sub exists so the test suite can mock it. | ||||
39 | $real_name = $class->_Readlink($lt_file); | ||||
40 | } | ||||
41 | |||||
42 | 1 | 44.4ms | $real_name ||= $class->_FindMatchingZoneinfoFile($lt_file); # spent 44.4ms making 1 call to DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile | ||
43 | |||||
44 | if ( defined $real_name ) { | ||||
45 | 1 | 14µs | my ( $vol, $dirs, $file ) = File::Spec->splitpath($real_name); # spent 14µs making 1 call to File::Spec::Unix::splitpath | ||
46 | |||||
47 | my @parts | ||||
48 | 1 | 3µs | = grep { defined && length } File::Spec->splitdir($dirs), $file; # spent 3µs making 1 call to File::Spec::Unix::splitdir | ||
49 | |||||
50 | foreach my $x ( reverse 0 .. $#parts ) { | ||||
51 | my $name = ( | ||||
52 | $x < $#parts | ||||
53 | ? join '/', @parts[ $x .. $#parts ] | ||||
54 | : $parts[$x] | ||||
55 | ); | ||||
56 | |||||
57 | my $tz; | ||||
58 | { | ||||
59 | local $@; | ||||
60 | local $SIG{__DIE__}; | ||||
61 | 2 | 0s | $tz = eval { DateTime::TimeZone->new( name => $name ) }; # spent 8.23ms making 2 calls to DateTime::TimeZone::new, avg 4.12ms/call, recursion: max depth 1, sum of overlapping time 8.23ms | ||
62 | } | ||||
63 | |||||
64 | return $tz if $tz; | ||||
65 | } | ||||
66 | } | ||||
67 | } | ||||
68 | |||||
69 | sub _Readlink { | ||||
70 | my $link = $_[1]; | ||||
71 | |||||
72 | # Using abs_path will resolve multiple levels of link indirection, | ||||
73 | # whereas readlink just follows the link to the next target. | ||||
74 | return Cwd::abs_path($link); | ||||
75 | } | ||||
76 | |||||
77 | # for systems where /etc/localtime is a copy of a zoneinfo file | ||||
78 | # spent 44.4ms (6.11+38.2) within DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile which was called:
# once (6.11ms+38.2ms) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 42 | ||||
79 | 15 | 343µs | my $class = shift; | ||
80 | my $file_to_match = shift; | ||||
81 | |||||
82 | 1 | 3µs | return unless -d '/usr/share/zoneinfo'; # spent 3µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftdir | ||
83 | |||||
84 | require File::Basename; | ||||
85 | require File::Compare; | ||||
86 | require File::Find; | ||||
87 | |||||
88 | 1 | 5µs | my $size = -s $file_to_match; # spent 5µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize | ||
89 | |||||
90 | my $real_name; | ||||
91 | local $@; | ||||
92 | local $SIG{__DIE__}; | ||||
93 | local $_; | ||||
94 | eval { | ||||
95 | File::Find::find( | ||||
96 | { | ||||
97 | # spent 17.0ms (8.71+8.29) within DateTime::TimeZone::Local::Unix::__ANON__[/usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm:116] which was called 1692 times, avg 10µs/call:
# 1082 times (5.62ms+5.80ms) by File::Find::_find_dir at line 749 of File/Find.pm, avg 11µs/call
# 475 times (2.50ms+1.94ms) by File::Find::_find_dir at line 781 of File/Find.pm, avg 9µs/call
# 78 times (398µs+402µs) by File::Find::_find_dir at line 787 of File/Find.pm, avg 10µs/call
# 57 times (184µs+141µs) by File::Find::_find_dir at line 691 of File/Find.pm, avg 6µs/call | ||||
98 | 1694 | 17.8ms | 4118 | 8.29ms | if ( # spent 5.19ms making 1692 calls to DateTime::TimeZone::Local::Unix::CORE:ftfile, avg 3µs/call
# spent 2.68ms making 1635 calls to DateTime::TimeZone::Local::Unix::CORE:ftlink, avg 2µs/call
# spent 195µs making 789 calls to DateTime::TimeZone::Local::Unix::CORE:ftsize, avg 247ns/call
# spent 158µs making 1 call to File::Compare::compare
# spent 73µs making 1 call to File::Basename::basename |
99 | !defined $real_name | ||||
100 | && -f $_ | ||||
101 | && !-l $_ | ||||
102 | && $size == -s _ | ||||
103 | |||||
104 | # This fixes RT 24026 - apparently such a | ||||
105 | # file exists on FreeBSD and it can cause a | ||||
106 | # false positive | ||||
107 | && File::Basename::basename($_) ne 'posixrules' | ||||
108 | && File::Compare::compare( $_, $file_to_match ) == 0 | ||||
109 | ) { | ||||
110 | $real_name = $_; | ||||
111 | |||||
112 | # File::Find has no mechanism for bailing in the | ||||
113 | # middle of a find. | ||||
114 | die { found => 1 }; | ||||
115 | } | ||||
116 | }, | ||||
117 | 1 | 36.6ms | no_chdir => 1, # spent 36.6ms making 1 call to File::Find::find | ||
118 | }, | ||||
119 | '/usr/share/zoneinfo', | ||||
120 | ); | ||||
121 | }; | ||||
122 | |||||
123 | if ($@) { | ||||
124 | return $real_name if ref $@ && $@->{found}; | ||||
125 | die $@; | ||||
126 | } | ||||
127 | } | ||||
128 | |||||
129 | sub FromEtcTimezone { | ||||
130 | my $class = shift; | ||||
131 | |||||
132 | my $tz_file = '/etc/timezone'; | ||||
133 | |||||
134 | return unless -f $tz_file && -r _; | ||||
135 | |||||
136 | local *TZ; | ||||
137 | open TZ, "<$tz_file" | ||||
138 | or die "Cannot read $tz_file: $!"; | ||||
139 | my $name = join '', <TZ>; | ||||
140 | close TZ; | ||||
141 | |||||
142 | $name =~ s/^\s+|\s+$//g; | ||||
143 | |||||
144 | return unless $class->_IsValidName($name); | ||||
145 | |||||
146 | local $@; | ||||
147 | local $SIG{__DIE__}; | ||||
148 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
149 | } | ||||
150 | |||||
151 | sub FromEtcTIMEZONE { | ||||
152 | my $class = shift; | ||||
153 | |||||
154 | my $tz_file = '/etc/TIMEZONE'; | ||||
155 | |||||
156 | return unless -f $tz_file && -r _; | ||||
157 | |||||
158 | local *TZ; | ||||
159 | open TZ, "<$tz_file" | ||||
160 | or die "Cannot read $tz_file: $!"; | ||||
161 | |||||
162 | my $name; | ||||
163 | while ( defined( $name = <TZ> ) ) { | ||||
164 | if ( $name =~ /\A\s*TZ\s*=\s*(\S+)/ ) { | ||||
165 | $name = $1; | ||||
166 | last; | ||||
167 | } | ||||
168 | } | ||||
169 | |||||
170 | close TZ; | ||||
171 | |||||
172 | return unless $class->_IsValidName($name); | ||||
173 | |||||
174 | local $@; | ||||
175 | local $SIG{__DIE__}; | ||||
176 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
177 | } | ||||
178 | |||||
179 | # RedHat uses this | ||||
180 | sub FromEtcSysconfigClock { | ||||
181 | my $class = shift; | ||||
182 | |||||
183 | return unless -r "/etc/sysconfig/clock" && -f _; | ||||
184 | |||||
185 | my $name = $class->_ReadEtcSysconfigClock(); | ||||
186 | |||||
187 | return unless $class->_IsValidName($name); | ||||
188 | |||||
189 | local $@; | ||||
190 | local $SIG{__DIE__}; | ||||
191 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
192 | } | ||||
193 | |||||
194 | # this is a separate function so that it can be overridden in the test suite | ||||
195 | sub _ReadEtcSysconfigClock { | ||||
196 | my $class = shift; | ||||
197 | |||||
198 | local *CLOCK; | ||||
199 | open CLOCK, '</etc/sysconfig/clock' | ||||
200 | or die "Cannot read /etc/sysconfig/clock: $!"; | ||||
201 | |||||
202 | local $_; | ||||
203 | while (<CLOCK>) { | ||||
204 | return $1 if /^(?:TIME)?ZONE="([^"]+)"/; | ||||
205 | } | ||||
206 | } | ||||
207 | |||||
208 | sub FromEtcDefaultInit { | ||||
209 | my $class = shift; | ||||
210 | |||||
211 | return unless -r "/etc/default/init" && -f _; | ||||
212 | |||||
213 | my $name = $class->_ReadEtcDefaultInit(); | ||||
214 | |||||
215 | return unless $class->_IsValidName($name); | ||||
216 | |||||
217 | local $@; | ||||
218 | local $SIG{__DIE__}; | ||||
219 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
220 | } | ||||
221 | |||||
222 | # this is a separate function so that it can be overridden in the test | ||||
223 | # suite | ||||
224 | sub _ReadEtcDefaultInit { | ||||
225 | my $class = shift; | ||||
226 | |||||
227 | local *INIT; | ||||
228 | open INIT, '</etc/default/init' | ||||
229 | or die "Cannot read /etc/default/init: $!"; | ||||
230 | |||||
231 | local $_; | ||||
232 | while (<INIT>) { | ||||
233 | return $1 if /^TZ=(.+)/; | ||||
234 | } | ||||
235 | } | ||||
236 | |||||
237 | 1 | 3µs | 1; | ||
238 | |||||
239 | # ABSTRACT: Determine the local system's time zone on Unix | ||||
240 | |||||
241 | __END__ | ||||
# spent 3µs within DateTime::TimeZone::Local::Unix::CORE:ftdir which was called:
# once (3µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 82 | |||||
# spent 6µs within DateTime::TimeZone::Local::Unix::CORE:fteread which was called:
# once (6µs+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 33 | |||||
# spent 5.19ms within DateTime::TimeZone::Local::Unix::CORE:ftfile which was called 1692 times, avg 3µs/call:
# 1692 times (5.19ms+0s) by DateTime::TimeZone::Local::Unix::__ANON__[/usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm:116] at line 98, avg 3µs/call | |||||
# spent 2.68ms within DateTime::TimeZone::Local::Unix::CORE:ftlink which was called 1636 times, avg 2µs/call:
# 1635 times (2.68ms+0s) by DateTime::TimeZone::Local::Unix::__ANON__[/usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm:116] at line 98, avg 2µs/call
# once (5µs+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 36 | |||||
# spent 200µs within DateTime::TimeZone::Local::Unix::CORE:ftsize which was called 791 times, avg 253ns/call:
# 789 times (195µs+0s) by DateTime::TimeZone::Local::Unix::__ANON__[/usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm:116] at line 98, avg 247ns/call
# once (5µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 88
# once (300ns+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 33 |