| Filename | /usr/share/perl5/DateTime/TimeZone/Local/Unix.pm |
| Statements | Executed 88 statements in 2.48ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.00ms | 1.97ms | DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile |
| 36 | 1 | 1 | 43µs | 43µs | DateTime::TimeZone::Local::Unix::CORE:ftfile (opcode) |
| 36 | 2 | 1 | 41µs | 41µs | DateTime::TimeZone::Local::Unix::CORE:ftlink (opcode) |
| 1 | 1 | 1 | 35µs | 96µs | DateTime::TimeZone::Local::Unix::BEGIN@6 |
| 1 | 1 | 1 | 26µs | 39µs | DateTime::TimeZone::Local::Unix::BEGIN@3 |
| 1 | 1 | 1 | 14µs | 24µs | DateTime::TimeZone::Local::Unix::BEGIN@4 |
| 1 | 1 | 1 | 12µs | 40µs | DateTime::TimeZone::Local::Unix::_EtcFile |
| 1 | 1 | 1 | 11µs | 45µs | DateTime::TimeZone::Local::Unix::BEGIN@7 |
| 30 | 3 | 1 | 11µs | 11µs | DateTime::TimeZone::Local::Unix::CORE:ftsize (opcode) |
| 1 | 1 | 1 | 7µs | 7µs | DateTime::TimeZone::Local::Unix::CORE:fteread (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | DateTime::TimeZone::Local::Unix::CORE:ftdir (opcode) |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::EnvVars |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::FromEtcDefaultInit |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::FromEtcLocaltime |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::FromEtcSysconfigClock |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::FromEtcTIMEZONE |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::FromEtcTimezone |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::Methods |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::_ReadEtcDefaultInit |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::_ReadEtcSysconfigClock |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::_Readlink |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::Local::Unix::__ANON__[:117] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::TimeZone::Local::Unix; | ||||
| 2 | 1 | 15µs | $DateTime::TimeZone::Local::Unix::VERSION = '1.75'; | ||
| 3 | 2 | 54µs | 2 | 51µs | # spent 39µs (26+12) within DateTime::TimeZone::Local::Unix::BEGIN@3 which was called:
# once (26µs+12µs) by C4::NewsChannels::GetNewsToDisplay at line 3 # spent 39µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@3
# spent 12µs making 1 call to strict::import |
| 4 | 2 | 52µs | 2 | 33µs | # spent 24µs (14+10) within DateTime::TimeZone::Local::Unix::BEGIN@4 which was called:
# once (14µs+10µs) by C4::NewsChannels::GetNewsToDisplay at line 4 # spent 24µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@4
# spent 10µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 3 | 122µs | 3 | 158µs | # spent 96µs (35+62) within DateTime::TimeZone::Local::Unix::BEGIN@6 which was called:
# once (35µs+62µs) by C4::NewsChannels::GetNewsToDisplay at line 6 # spent 96µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@6
# spent 46µs making 1 call to Exporter::import
# spent 16µs making 1 call to version::vxs::_VERSION |
| 7 | 2 | 679µs | 2 | 80µs | # spent 45µs (11+34) within DateTime::TimeZone::Local::Unix::BEGIN@7 which was called:
# once (11µs+34µs) by C4::NewsChannels::GetNewsToDisplay at line 7 # spent 45µs making 1 call to DateTime::TimeZone::Local::Unix::BEGIN@7
# spent 34µs making 1 call to parent::import |
| 8 | |||||
| 9 | sub Methods { | ||||
| 10 | 1 | 9µs | return qw( | ||
| 11 | FromEnv | ||||
| 12 | FromEtcLocaltime | ||||
| 13 | FromEtcTimezone | ||||
| 14 | FromEtcTIMEZONE | ||||
| 15 | FromEtcSysconfigClock | ||||
| 16 | FromEtcDefaultInit | ||||
| 17 | ); | ||||
| 18 | } | ||||
| 19 | |||||
| 20 | 1 | 4µs | sub EnvVars { return 'TZ' } | ||
| 21 | |||||
| 22 | 1 | 701µs | our $EtcDir = '/etc'; | ||
| 23 | |||||
| 24 | # spent 40µs (12+27) within DateTime::TimeZone::Local::Unix::_EtcFile which was called:
# once (12µs+27µs) by C4::NewsChannels::GetNewsToDisplay at line 32 | ||||
| 25 | 1 | 1µs | shift; | ||
| 26 | 1 | 38µs | 4 | 37µs | return File::Spec->catfile( $EtcDir, @_ ); # spent 27µs making 1 call to File::Spec::Unix::catfile
# spent 7µs making 1 call to File::Spec::Unix::catdir
# spent 3µs making 2 calls to File::Spec::Unix::canonpath, avg 1µs/call |
| 27 | } | ||||
| 28 | |||||
| 29 | sub FromEtcLocaltime { | ||||
| 30 | 1 | 2µs | my $class = shift; | ||
| 31 | |||||
| 32 | 1 | 6µs | 1 | 40µs | my $lt_file = $class->_EtcFile('localtime'); # spent 40µs making 1 call to DateTime::TimeZone::Local::Unix::_EtcFile |
| 33 | 1 | 20µs | 2 | 9µs | return unless -r $lt_file && -s _; # spent 7µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:fteread
# spent 2µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize |
| 34 | |||||
| 35 | 1 | 100ns | my $real_name; | ||
| 36 | 1 | 6µs | 1 | 3µs | if ( -l $lt_file ) { # spent 3µ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 | 2µs | 1 | 1.97ms | $real_name ||= $class->_FindMatchingZoneinfoFile($lt_file); # spent 1.97ms making 1 call to DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile |
| 43 | |||||
| 44 | 1 | 500ns | if ( defined $real_name ) { | ||
| 45 | 1 | 20µs | 1 | 11µs | my ( $vol, $dirs, $file ) = File::Spec->splitpath($real_name); # spent 11µs making 1 call to File::Spec::Unix::splitpath |
| 46 | |||||
| 47 | my @parts | ||||
| 48 | 1 | 12µs | 1 | 4µs | = grep { defined && length } File::Spec->splitdir($dirs), $file; # spent 4µs making 1 call to File::Spec::Unix::splitdir |
| 49 | |||||
| 50 | 1 | 2µs | foreach my $x ( reverse 0 .. $#parts ) { | ||
| 51 | 1 | 1µs | my $name = ( | ||
| 52 | $x < $#parts | ||||
| 53 | ? join '/', @parts[ $x .. $#parts ] | ||||
| 54 | : $parts[$x] | ||||
| 55 | ); | ||||
| 56 | |||||
| 57 | 1 | 200ns | my $tz; | ||
| 58 | { | ||||
| 59 | 2 | 500ns | local $@; | ||
| 60 | 1 | 2µs | local $SIG{__DIE__}; | ||
| 61 | 2 | 82µs | 1 | 0s | $tz = eval { DateTime::TimeZone->new( name => $name ) }; # spent 68µs making 1 call to DateTime::TimeZone::new, recursion: max depth 1, sum of overlapping time 68µs |
| 62 | } | ||||
| 63 | |||||
| 64 | 1 | 8µ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 | 1 | 24µs | our $ZoneinfoDir = '/usr/share/zoneinfo'; | ||
| 78 | # for systems where /etc/localtime is a copy of a zoneinfo file | ||||
| 79 | # spent 1.97ms (1.00+970µs) within DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile which was called:
# once (1.00ms+970µs) by C4::NewsChannels::GetNewsToDisplay at line 42 | ||||
| 80 | 1 | 400ns | my $class = shift; | ||
| 81 | 1 | 200ns | my $file_to_match = shift; | ||
| 82 | |||||
| 83 | 1 | 8µs | 1 | 2µs | return unless -d $ZoneinfoDir; # spent 2µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftdir |
| 84 | |||||
| 85 | 1 | 2µs | require File::Basename; | ||
| 86 | 1 | 135µs | require File::Compare; | ||
| 87 | 1 | 800ns | require File::Find; | ||
| 88 | |||||
| 89 | 1 | 12µs | 1 | 6µs | my $size = -s $file_to_match; # spent 6µs making 1 call to DateTime::TimeZone::Local::Unix::CORE:ftsize |
| 90 | |||||
| 91 | 1 | 100ns | my $real_name; | ||
| 92 | 1 | 300ns | local $@; | ||
| 93 | 1 | 2µs | local $SIG{__DIE__}; | ||
| 94 | 1 | 300ns | local $_; | ||
| 95 | 1 | 500ns | eval { | ||
| 96 | File::Find::find( | ||||
| 97 | { | ||||
| 98 | wanted => sub { | ||||
| 99 | 36 | 314µs | 103 | 317µs | if ( # spent 170µs making 2 calls to File::Compare::compare, avg 85µs/call
# spent 62µs making 2 calls to File::Basename::basename, avg 31µs/call
# spent 43µs making 36 calls to DateTime::TimeZone::Local::Unix::CORE:ftfile, avg 1µs/call
# spent 38µs making 35 calls to DateTime::TimeZone::Local::Unix::CORE:ftlink, avg 1µs/call
# spent 3µs making 28 calls to DateTime::TimeZone::Local::Unix::CORE:ftsize, avg 121ns/call |
| 100 | !defined $real_name | ||||
| 101 | && -f $_ | ||||
| 102 | && !-l $_ | ||||
| 103 | && $size == -s _ | ||||
| 104 | |||||
| 105 | # This fixes RT 24026 - apparently such a | ||||
| 106 | # file exists on FreeBSD and it can cause a | ||||
| 107 | # false positive | ||||
| 108 | && File::Basename::basename($_) ne 'posixrules' | ||||
| 109 | && File::Compare::compare( $_, $file_to_match ) == 0 | ||||
| 110 | ) { | ||||
| 111 | 1 | 400ns | $real_name = $_; | ||
| 112 | |||||
| 113 | # File::Find has no mechanism for bailing in the | ||||
| 114 | # middle of a find. | ||||
| 115 | 1 | 26µs | die { found => 1 }; | ||
| 116 | } | ||||
| 117 | }, | ||||
| 118 | 1 | 85µs | 1 | 898µs | no_chdir => 1, # spent 898µs making 1 call to File::Find::find |
| 119 | }, | ||||
| 120 | $ZoneinfoDir, | ||||
| 121 | ); | ||||
| 122 | }; | ||||
| 123 | |||||
| 124 | 1 | 400ns | if ($@) { | ||
| 125 | 1 | 9µs | return $real_name if ref $@ && $@->{found}; | ||
| 126 | die $@; | ||||
| 127 | } | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | sub FromEtcTimezone { | ||||
| 131 | my $class = shift; | ||||
| 132 | |||||
| 133 | my $tz_file = $class->_EtcFile('timezone'); | ||||
| 134 | return unless -f $tz_file && -r _; | ||||
| 135 | |||||
| 136 | open my $fh, '<', $tz_file | ||||
| 137 | or die "Cannot read $tz_file: $!"; | ||||
| 138 | my $name = join '', <$fh>; | ||||
| 139 | close $fh; | ||||
| 140 | |||||
| 141 | $name =~ s/^\s+|\s+$//g; | ||||
| 142 | |||||
| 143 | return unless $class->_IsValidName($name); | ||||
| 144 | |||||
| 145 | local $@; | ||||
| 146 | local $SIG{__DIE__}; | ||||
| 147 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | sub FromEtcTIMEZONE { | ||||
| 151 | my $class = shift; | ||||
| 152 | |||||
| 153 | my $tz_file = $class->_EtcFile('TIMEZONE'); | ||||
| 154 | return unless -f $tz_file && -r _; | ||||
| 155 | |||||
| 156 | open my $fh, '<', $tz_file | ||||
| 157 | or die "Cannot read $tz_file: $!"; | ||||
| 158 | |||||
| 159 | my $name; | ||||
| 160 | while ( defined( $name = <$fh> ) ) { | ||||
| 161 | if ( $name =~ /\A\s*TZ\s*=\s*(\S+)/ ) { | ||||
| 162 | $name = $1; | ||||
| 163 | last; | ||||
| 164 | } | ||||
| 165 | } | ||||
| 166 | |||||
| 167 | close $fh; | ||||
| 168 | |||||
| 169 | return unless $class->_IsValidName($name); | ||||
| 170 | |||||
| 171 | local $@; | ||||
| 172 | local $SIG{__DIE__}; | ||||
| 173 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | # RedHat uses this | ||||
| 177 | sub FromEtcSysconfigClock { | ||||
| 178 | my $class = shift; | ||||
| 179 | |||||
| 180 | my $clock_file = $class->_EtcFile('sysconfig/clock'); | ||||
| 181 | return unless -r $clock_file && -f _; | ||||
| 182 | |||||
| 183 | my $name = $class->_ReadEtcSysconfigClock($clock_file); | ||||
| 184 | |||||
| 185 | return unless $class->_IsValidName($name); | ||||
| 186 | |||||
| 187 | local $@; | ||||
| 188 | local $SIG{__DIE__}; | ||||
| 189 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
| 190 | } | ||||
| 191 | |||||
| 192 | # this is a separate function so that it can be overridden in the test suite | ||||
| 193 | sub _ReadEtcSysconfigClock { | ||||
| 194 | my $class = shift; | ||||
| 195 | my $clock_file = shift; | ||||
| 196 | |||||
| 197 | open my $fh, '<', $clock_file | ||||
| 198 | or die "Cannot read $clock_file: $!"; | ||||
| 199 | |||||
| 200 | local $_; | ||||
| 201 | while (<$fh>) { | ||||
| 202 | return $1 if /^(?:TIME)?ZONE="([^"]+)"/; | ||||
| 203 | } | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | sub FromEtcDefaultInit { | ||||
| 207 | my $class = shift; | ||||
| 208 | |||||
| 209 | my $init_file = $class->_EtcFile('default/init'); | ||||
| 210 | return unless -r $init_file && -f _; | ||||
| 211 | |||||
| 212 | my $name = $class->_ReadEtcDefaultInit($init_file); | ||||
| 213 | |||||
| 214 | return unless $class->_IsValidName($name); | ||||
| 215 | |||||
| 216 | local $@; | ||||
| 217 | local $SIG{__DIE__}; | ||||
| 218 | return eval { DateTime::TimeZone->new( name => $name ) }; | ||||
| 219 | } | ||||
| 220 | |||||
| 221 | # this is a separate function so that it can be overridden in the test | ||||
| 222 | # suite | ||||
| 223 | sub _ReadEtcDefaultInit { | ||||
| 224 | my $class = shift; | ||||
| 225 | my $init_file = shift; | ||||
| 226 | |||||
| 227 | open my $fh, '<', $init_file | ||||
| 228 | or die "Cannot read $init_file: $!"; | ||||
| 229 | |||||
| 230 | local $_; | ||||
| 231 | while (<$fh>) { | ||||
| 232 | return $1 if /^TZ=(.+)/; | ||||
| 233 | } | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | 1 | 22µs | 1; | ||
| 237 | |||||
| 238 | # ABSTRACT: Determine the local system's time zone on Unix | ||||
| 239 | |||||
| 240 | __END__ | ||||
# spent 2µs within DateTime::TimeZone::Local::Unix::CORE:ftdir which was called:
# once (2µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 83 | |||||
# spent 7µs within DateTime::TimeZone::Local::Unix::CORE:fteread which was called:
# once (7µs+0s) by C4::NewsChannels::GetNewsToDisplay at line 33 | |||||
# spent 43µs within DateTime::TimeZone::Local::Unix::CORE:ftfile which was called 36 times, avg 1µs/call:
# 36 times (43µs+0s) by File::Find::find at line 99, avg 1µs/call | |||||
sub DateTime::TimeZone::Local::Unix::CORE:ftlink; # opcode | |||||
# spent 11µs within DateTime::TimeZone::Local::Unix::CORE:ftsize which was called 30 times, avg 377ns/call:
# 28 times (3µs+0s) by File::Find::find at line 99, avg 121ns/call
# once (6µs+0s) by DateTime::TimeZone::Local::Unix::_FindMatchingZoneinfoFile at line 89
# once (2µs+0s) by C4::NewsChannels::GetNewsToDisplay at line 33 |