Filename | /usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm |
Statements | Executed 1757 statements in 37.3ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1692 | 4 | 1 | 19.1ms | 32.0ms | __ANON__[:116] | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 13.5ms | 91.6ms | _FindMatchingZoneinfoFile | DateTime::TimeZone::Local::Unix::
1692 | 1 | 1 | 7.62ms | 7.62ms | CORE:ftfile (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 6.80ms | 7.46ms | BEGIN@12 | DateTime::TimeZone::Local::Unix::
1636 | 2 | 1 | 4.44ms | 4.44ms | CORE:ftlink (opcode) | DateTime::TimeZone::Local::Unix::
791 | 3 | 1 | 438µs | 438µs | CORE:ftsize (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 140µs | 110ms | FromEtcLocaltime | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 20µs | 20µs | BEGIN@5 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 20µs | 71µs | BEGIN@13 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 16µs | 23µs | BEGIN@9 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 16µs | 28µs | BEGIN@10 | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 8µs | 8µs | CORE:fteread (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 5µs | 5µs | Methods | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 4µs | 4µs | CORE:ftdir (opcode) | DateTime::TimeZone::Local::Unix::
1 | 1 | 1 | 2µs | 2µs | 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 | 3µs | $DateTime::TimeZone::Local::Unix::VERSION = '1.63'; | ||
4 | } | ||||
5 | # spent 20µs within DateTime::TimeZone::Local::Unix::BEGIN@5 which was called:
# once (20µs+0s) by Module::Runtime::require_module at line 7 | ||||
6 | 1 | 11µs | $DateTime::TimeZone::Local::Unix::AUTHORITY = 'cpan:DROLSKY'; | ||
7 | 1 | 47µs | 1 | 20µs | } # spent 20µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@5 |
8 | |||||
9 | 2 | 65µs | 2 | 30µs | # spent 23µs (16+7) within DateTime::TimeZone::Local::Unix::BEGIN@9 which was called:
# once (16µs+7µs) by Module::Runtime::require_module at line 9 # spent 23µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@9
# spent 7µs making 1 call to strict::import |
10 | 2 | 56µs | 2 | 41µs | # spent 28µs (16+12) within DateTime::TimeZone::Local::Unix::BEGIN@10 which was called:
# once (16µs+12µs) by Module::Runtime::require_module at line 10 # spent 28µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@10
# spent 12µs making 1 call to warnings::import |
11 | |||||
12 | 3 | 274µs | 3 | 7.58ms | # spent 7.46ms (6.80+660µs) within DateTime::TimeZone::Local::Unix::BEGIN@12 which was called:
# once (6.80ms+660µs) by Module::Runtime::require_module at line 12 # spent 7.46ms making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@12
# spent 92µs making 1 call to Exporter::import
# spent 28µs making 1 call to UNIVERSAL::VERSION |
13 | 2 | 2.14ms | 2 | 122µs | # spent 71µs (20+51) within DateTime::TimeZone::Local::Unix::BEGIN@13 which was called:
# once (20µs+51µs) by Module::Runtime::require_module at line 13 # spent 71µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@13
# spent 51µs making 1 call to parent::import |
14 | |||||
15 | # spent 5µs within DateTime::TimeZone::Local::Unix::Methods which was called:
# once (5µs+0s) by DateTime::TimeZone::Local::TimeZone at line 21 of DateTime/TimeZone/Local.pm | ||||
16 | 1 | 8µs | return qw( | ||
17 | FromEnv | ||||
18 | FromEtcLocaltime | ||||
19 | FromEtcTimezone | ||||
20 | FromEtcTIMEZONE | ||||
21 | FromEtcSysconfigClock | ||||
22 | FromEtcDefaultInit | ||||
23 | ); | ||||
24 | } | ||||
25 | |||||
26 | 1 | 6µs | # spent 2µs within DateTime::TimeZone::Local::Unix::EnvVars which was called:
# once (2µs+0s) by DateTime::TimeZone::Local::FromEnv at line 67 of DateTime/TimeZone/Local.pm | ||
27 | |||||
28 | # spent 110ms (140µs+110) within DateTime::TimeZone::Local::Unix::FromEtcLocaltime which was called:
# once (140µs+110ms) by DateTime::TimeZone::Local::TimeZone at line 22 of DateTime/TimeZone/Local.pm | ||||
29 | 1 | 800ns | my $class = shift; | ||
30 | |||||
31 | 1 | 600ns | my $lt_file = '/etc/localtime'; | ||
32 | |||||
33 | 1 | 30µs | 2 | 9µs | return unless -r $lt_file && -s _; # spent 8µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:fteread
# spent 600ns making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize |
34 | |||||
35 | 1 | 300ns | my $real_name; | ||
36 | 1 | 16µs | 1 | 9µs | if ( -l $lt_file ) { # spent 9µ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 | 6µs | 1 | 91.6ms | $real_name ||= $class->_FindMatchingZoneinfoFile($lt_file); # spent 91.6ms making 1 call to DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile |
43 | |||||
44 | 1 | 900ns | if ( defined $real_name ) { | ||
45 | 1 | 14µs | 1 | 32µs | my ( $vol, $dirs, $file ) = File::Spec->splitpath($real_name); # spent 32µs making 1 call to File::Spec::Unix::splitpath |
46 | |||||
47 | my @parts | ||||
48 | 8 | 19µs | 1 | 6µs | = grep { defined && length } File::Spec->splitdir($dirs), $file; # spent 6µs making 1 call to File::Spec::Unix::splitdir |
49 | |||||
50 | 1 | 4µs | foreach my $x ( reverse 0 .. $#parts ) { | ||
51 | 2 | 9µs | my $name = ( | ||
52 | $x < $#parts | ||||
53 | ? join '/', @parts[ $x .. $#parts ] | ||||
54 | : $parts[$x] | ||||
55 | ); | ||||
56 | |||||
57 | 2 | 400ns | my $tz; | ||
58 | { | ||||
59 | 4 | 2µs | local $@; | ||
60 | 2 | 6µs | local $SIG{__DIE__}; | ||
61 | 4 | 24µs | 2 | 0s | $tz = eval { DateTime::TimeZone->new( name => $name ) }; # spent 18.3ms making 2 calls to DateTime::TimeZone::new, avg 9.17ms/call, recursion: max depth 1, sum of overlapping time 18.3ms |
62 | } | ||||
63 | |||||
64 | 2 | 11µs | 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 91.6ms (13.5+78.1) within DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile which was called:
# once (13.5ms+78.1ms) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 42 | ||||
79 | 1 | 1µs | my $class = shift; | ||
80 | 1 | 500ns | my $file_to_match = shift; | ||
81 | |||||
82 | 1 | 48µs | 1 | 4µs | return unless -d '/usr/share/zoneinfo'; # spent 4µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftdir |
83 | |||||
84 | 1 | 249µs | require File::Basename; | ||
85 | 1 | 168µs | require File::Compare; | ||
86 | 1 | 165µs | require File::Find; | ||
87 | |||||
88 | 1 | 17µs | 1 | 8µs | my $size = -s $file_to_match; # spent 8µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize |
89 | |||||
90 | 1 | 200ns | my $real_name; | ||
91 | 1 | 400ns | local $@; | ||
92 | 1 | 5µs | local $SIG{__DIE__}; | ||
93 | 1 | 400ns | local $_; | ||
94 | 1 | 800ns | eval { | ||
95 | File::Find::find( | ||||
96 | { | ||||
97 | # spent 32.0ms (19.1+12.9) 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 19µs/call:
# 1082 times (12.3ms+8.75ms) by File::Find::_find_dir at line 749 of File/Find.pm, avg 19µs/call
# 475 times (5.51ms+3.31ms) by File::Find::_find_dir at line 781 of File/Find.pm, avg 19µs/call
# 78 times (869µs+616µs) by File::Find::_find_dir at line 787 of File/Find.pm, avg 19µs/call
# 57 times (406µs+215µs) by File::Find::_find_dir at line 691 of File/Find.pm, avg 11µs/call | ||||
98 | 1692 | 33.8ms | 4118 | 12.9ms | if ( # spent 7.62ms making 1692 calls to DateTime::TimeZone::Local::Unix::CORE:ftfile, avg 5µs/call
# spent 4.43ms making 1635 calls to DateTime::TimeZone::Local::Unix::CORE:ftlink, avg 3µs/call
# spent 429µs making 789 calls to DateTime::TimeZone::Local::Unix::CORE:ftsize, avg 544ns/call
# spent 271µs making 1 call to File::Compare::compare
# spent 135µ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 | 1 | 2µs | $real_name = $_; | ||
111 | |||||
112 | # File::Find has no mechanism for bailing in the | ||||
113 | # middle of a find. | ||||
114 | 1 | 65µs | die { found => 1 }; | ||
115 | } | ||||
116 | }, | ||||
117 | 1 | 12µs | 1 | 74.4ms | no_chdir => 1, # spent 74.4ms making 1 call to File::Find::find |
118 | }, | ||||
119 | '/usr/share/zoneinfo', | ||||
120 | ); | ||||
121 | }; | ||||
122 | |||||
123 | 1 | 1µs | if ($@) { | ||
124 | 1 | 17µs | 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 | 6µs | 1; | ||
238 | |||||
239 | # ABSTRACT: Determine the local system's time zone on Unix | ||||
240 | |||||
241 | __END__ | ||||
# spent 4µs within DateTime::TimeZone::Local::Unix::CORE:ftdir which was called:
# once (4µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 82 | |||||
# spent 8µs within DateTime::TimeZone::Local::Unix::CORE:fteread which was called:
# once (8µs+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 33 | |||||
# spent 7.62ms within DateTime::TimeZone::Local::Unix::CORE:ftfile which was called 1692 times, avg 5µs/call:
# 1692 times (7.62ms+0s) by DateTime::TimeZone::Local::Unix::__ANON__[/usr/local/share/perl/5.14.2/DateTime/TimeZone/Local/Unix.pm:116] at line 98, avg 5µs/call | |||||
# spent 4.44ms within DateTime::TimeZone::Local::Unix::CORE:ftlink which was called 1636 times, avg 3µs/call:
# 1635 times (4.43ms+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
# once (9µs+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 36 | |||||
# spent 438µs within DateTime::TimeZone::Local::Unix::CORE:ftsize which was called 791 times, avg 553ns/call:
# 789 times (429µ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 544ns/call
# once (8µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 88
# once (600ns+0s) by DateTime::TimeZone::Local::Unix::FromEtcLocaltime at line 33 |