| Filename | /usr/share/perl/5.28/File/Basename.pm |
| Statements | Executed 103693 statements in 377ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 4145 | 2 | 1 | 141ms | 160ms | File::Basename::fileparse |
| 4127 | 3 | 1 | 118ms | 383ms | File::Basename::basename |
| 4145 | 2 | 1 | 61.0ms | 106ms | File::Basename::_strip_trailing_sep |
| 4145 | 1 | 1 | 45.4ms | 45.4ms | File::Basename::CORE:subst (opcode) |
| 4155 | 2 | 1 | 18.8ms | 18.8ms | File::Basename::CORE:match (opcode) |
| 1 | 1 | 1 | 2.64ms | 2.66ms | File::Basename::BEGIN@14 |
| 18 | 6 | 3 | 550µs | 2.00ms | File::Basename::dirname |
| 1 | 1 | 1 | 32µs | 61µs | File::Basename::fileparse_set_fstype |
| 10 | 1 | 1 | 26µs | 26µs | File::Basename::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 16µs | 16µs | File::Basename::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 6µs | File::Basename::BEGIN@184 |
| 1 | 1 | 1 | 6µs | 6µs | File::Basename::BEGIN@5 |
| 1 | 1 | 1 | 5µs | 7µs | File::Basename::BEGIN@12 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package File::Basename; | ||||
| 2 | |||||
| 3 | # File::Basename is used during the Perl build, when the re extension may | ||||
| 4 | # not be available, but we only actually need it if running under tainting. | ||||
| 5 | # spent 6µs within File::Basename::BEGIN@5 which was called:
# once (6µs+0s) by main::BEGIN@4 at line 10 | ||||
| 6 | 1 | 4µs | if (${^TAINT}) { | ||
| 7 | require re; | ||||
| 8 | re->import('taint'); | ||||
| 9 | } | ||||
| 10 | 1 | 21µs | 1 | 6µs | } # spent 6µs making 1 call to File::Basename::BEGIN@5 |
| 11 | |||||
| 12 | 2 | 19µs | 2 | 8µs | # spent 7µs (5+2) within File::Basename::BEGIN@12 which was called:
# once (5µs+2µs) by main::BEGIN@4 at line 12 # spent 7µs making 1 call to File::Basename::BEGIN@12
# spent 2µs making 1 call to strict::import |
| 13 | 2 | 42µs | 1 | 16µs | # spent 16µs within File::Basename::BEGIN@13 which was called:
# once (16µs+0s) by main::BEGIN@4 at line 13 # spent 16µs making 1 call to File::Basename::BEGIN@13 |
| 14 | 2 | 3.61ms | 2 | 2.68ms | # spent 2.66ms (2.64+21µs) within File::Basename::BEGIN@14 which was called:
# once (2.64ms+21µs) by main::BEGIN@4 at line 14 # spent 2.66ms making 1 call to File::Basename::BEGIN@14
# spent 17µs making 1 call to warnings::import |
| 15 | our(@ISA, @EXPORT, $VERSION, $Fileparse_fstype, $Fileparse_igncase); | ||||
| 16 | 1 | 625µs | require Exporter; | ||
| 17 | 1 | 6µs | @ISA = qw(Exporter); | ||
| 18 | 1 | 700ns | @EXPORT = qw(fileparse fileparse_set_fstype basename dirname); | ||
| 19 | 1 | 200ns | $VERSION = "2.85"; | ||
| 20 | |||||
| 21 | 1 | 1µs | 1 | 61µs | fileparse_set_fstype($^O); # spent 61µs making 1 call to File::Basename::fileparse_set_fstype |
| 22 | |||||
| 23 | sub fileparse { | ||||
| 24 | 4145 | 4.52ms | my($fullname,@suffices) = @_; | ||
| 25 | |||||
| 26 | 4145 | 3.03ms | unless (defined $fullname) { | ||
| 27 | require Carp; | ||||
| 28 | Carp::croak("fileparse(): need a valid pathname"); | ||||
| 29 | } | ||||
| 30 | |||||
| 31 | 4145 | 5.54ms | my $orig_type = ''; | ||
| 32 | 4145 | 3.87ms | my($type,$igncase) = ($Fileparse_fstype, $Fileparse_igncase); | ||
| 33 | |||||
| 34 | 4145 | 9.16ms | my($taint) = substr($fullname,0,0); # Is $fullname tainted? | ||
| 35 | |||||
| 36 | 4145 | 3.84ms | if ($type eq "VMS" and $fullname =~ m{/} ) { | ||
| 37 | # We're doing Unix emulation | ||||
| 38 | $orig_type = $type; | ||||
| 39 | $type = 'Unix'; | ||||
| 40 | } | ||||
| 41 | |||||
| 42 | 4145 | 1.95ms | my($dirpath, $basename); | ||
| 43 | |||||
| 44 | 4145 | 21.1ms | if (grep { $type eq $_ } qw(MSDOS DOS MSWin32 Epoc)) { | ||
| 45 | ($dirpath,$basename) = ($fullname =~ /^((?:.*[:\\\/])?)(.*)/s); | ||||
| 46 | $dirpath .= '.\\' unless $dirpath =~ /[\\\/]\z/; | ||||
| 47 | } | ||||
| 48 | elsif ($type eq "OS2") { | ||||
| 49 | ($dirpath,$basename) = ($fullname =~ m#^((?:.*[:\\/])?)(.*)#s); | ||||
| 50 | $dirpath = './' unless $dirpath; # Can't be 0 | ||||
| 51 | $dirpath .= '/' unless $dirpath =~ m#[\\/]\z#; | ||||
| 52 | } | ||||
| 53 | elsif ($type eq "MacOS") { | ||||
| 54 | ($dirpath,$basename) = ($fullname =~ /^(.*:)?(.*)/s); | ||||
| 55 | $dirpath = ':' unless $dirpath; | ||||
| 56 | } | ||||
| 57 | elsif ($type eq "AmigaOS") { | ||||
| 58 | ($dirpath,$basename) = ($fullname =~ /(.*[:\/])?(.*)/s); | ||||
| 59 | $dirpath = './' unless $dirpath; | ||||
| 60 | } | ||||
| 61 | elsif ($type eq 'VMS' ) { | ||||
| 62 | ($dirpath,$basename) = ($fullname =~ /^(.*[:>\]])?(.*)/s); | ||||
| 63 | $dirpath ||= ''; # should always be defined | ||||
| 64 | } | ||||
| 65 | else { # Default to Unix semantics. | ||||
| 66 | 4145 | 62.1ms | 4145 | 18.8ms | ($dirpath,$basename) = ($fullname =~ m{^(.*/)?(.*)}s); # spent 18.8ms making 4145 calls to File::Basename::CORE:match, avg 5µs/call |
| 67 | 4145 | 2.31ms | if ($orig_type eq 'VMS' and $fullname =~ m{^(/[^/]+/000000(/|$))(.*)}) { | ||
| 68 | # dev:[000000] is top of VMS tree, similar to Unix '/' | ||||
| 69 | # so strip it off and treat the rest as "normal" | ||||
| 70 | my $devspec = $1; | ||||
| 71 | my $remainder = $3; | ||||
| 72 | ($dirpath,$basename) = ($remainder =~ m{^(.*/)?(.*)}s); | ||||
| 73 | $dirpath ||= ''; # should always be defined | ||||
| 74 | $dirpath = $devspec.$dirpath; | ||||
| 75 | } | ||||
| 76 | 4145 | 1.91ms | $dirpath = './' unless $dirpath; | ||
| 77 | } | ||||
| 78 | |||||
| 79 | |||||
| 80 | 4145 | 4.26ms | my $tail = ''; | ||
| 81 | 4145 | 4.43ms | my $suffix = ''; | ||
| 82 | 4145 | 1.93ms | if (@suffices) { | ||
| 83 | foreach $suffix (@suffices) { | ||||
| 84 | my $pat = ($igncase ? '(?i)' : '') . "($suffix)\$"; | ||||
| 85 | if ($basename =~ s/$pat//s) { | ||||
| 86 | $taint .= substr($suffix,0,0); | ||||
| 87 | $tail = $1 . $tail; | ||||
| 88 | } | ||||
| 89 | } | ||||
| 90 | } | ||||
| 91 | |||||
| 92 | # Ensure taint is propagated from the path to its pieces. | ||||
| 93 | 4145 | 3.80ms | $tail .= $taint; | ||
| 94 | 4145 | 42.4ms | wantarray ? ($basename .= $taint, $dirpath .= $taint, $tail) | ||
| 95 | : ($basename .= $taint); | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | # spent 383ms (118+265) within File::Basename::basename which was called 4127 times, avg 93µs/call:
# 1992 times (69.2ms+135ms) by RBM::input_files at line 872 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 103µs/call
# 1992 times (47.9ms+127ms) by RBM::__ANON__[rbm/lib/RBM.pm:858] at line 853 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 88µs/call
# 143 times (676µs+2.64ms) by RBM::load_config at line 55 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 23µs/call | ||||
| 99 | 4127 | 6.06ms | my($path) = shift; | ||
| 100 | |||||
| 101 | # From BSD basename(1) | ||||
| 102 | # The basename utility deletes any prefix ending with the last slash '/' | ||||
| 103 | # character present in string (after first stripping trailing slashes) | ||||
| 104 | 4127 | 23.6ms | 4127 | 106ms | _strip_trailing_sep($path); # spent 106ms making 4127 calls to File::Basename::_strip_trailing_sep, avg 26µs/call |
| 105 | |||||
| 106 | 4127 | 23.5ms | 4127 | 159ms | my($basename, $dirname, $suffix) = fileparse( $path, map("\Q$_\E",@_) ); # spent 159ms making 4127 calls to File::Basename::fileparse, avg 39µs/call |
| 107 | |||||
| 108 | # From BSD basename(1) | ||||
| 109 | # The suffix is not stripped if it is identical to the remaining | ||||
| 110 | # characters in string. | ||||
| 111 | 4127 | 2.94ms | if( length $suffix and !length $basename ) { | ||
| 112 | $basename = $suffix; | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | # Ensure that basename '/' == '/' | ||||
| 116 | 4127 | 2.62ms | if( !length $basename ) { | ||
| 117 | $basename = $dirname; | ||||
| 118 | } | ||||
| 119 | |||||
| 120 | 4127 | 20.0ms | return $basename; | ||
| 121 | } | ||||
| 122 | |||||
| 123 | # spent 2.00ms (550µs+1.45) within File::Basename::dirname which was called 18 times, avg 111µs/call:
# 8 times (298µs+769µs) by RBM::build_run at line 1088 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 133µs/call
# 6 times (174µs+404µs) by RBM::input_files at line 973 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 96µs/call
# once (16µs+137µs) by RBM::load_config at line 49 of /root/tor-browser-build/rbm/lib/RBM.pm
# once (31µs+66µs) by RBM::build_run at line 1079 of /root/tor-browser-build/rbm/lib/RBM.pm
# once (20µs+44µs) by File::Path::_mkpath at line 191 of File/Path.pm
# once (10µs+24µs) by main::BEGIN@5 at line 5 of /root/tor-browser-build/rbm/rbm | ||||
| 124 | 18 | 54µs | my $path = shift; | ||
| 125 | |||||
| 126 | 18 | 38µs | my($type) = $Fileparse_fstype; | ||
| 127 | |||||
| 128 | 18 | 17µs | if( $type eq 'VMS' and $path =~ m{/} ) { | ||
| 129 | # Parse as Unix | ||||
| 130 | local($File::Basename::Fileparse_fstype) = ''; | ||||
| 131 | return dirname($path); | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 18 | 165µs | 18 | 1.07ms | my($basename, $dirname) = fileparse($path); # spent 1.07ms making 18 calls to File::Basename::fileparse, avg 59µs/call |
| 135 | |||||
| 136 | 18 | 97µs | if ($type eq 'VMS') { | ||
| 137 | $dirname ||= $ENV{DEFAULT}; | ||||
| 138 | } | ||||
| 139 | elsif ($type eq 'MacOS') { | ||||
| 140 | if( !length($basename) && $dirname !~ /^[^:]+:\z/) { | ||||
| 141 | _strip_trailing_sep($dirname); | ||||
| 142 | ($basename,$dirname) = fileparse $dirname; | ||||
| 143 | } | ||||
| 144 | $dirname .= ":" unless $dirname =~ /:\z/; | ||||
| 145 | } | ||||
| 146 | elsif (grep { $type eq $_ } qw(MSDOS DOS MSWin32 OS2)) { | ||||
| 147 | _strip_trailing_sep($dirname); | ||||
| 148 | unless( length($basename) ) { | ||||
| 149 | ($basename,$dirname) = fileparse $dirname; | ||||
| 150 | _strip_trailing_sep($dirname); | ||||
| 151 | } | ||||
| 152 | } | ||||
| 153 | elsif ($type eq 'AmigaOS') { | ||||
| 154 | if ( $dirname =~ /:\z/) { return $dirname } | ||||
| 155 | chop $dirname; | ||||
| 156 | $dirname =~ s{[^:/]+\z}{} unless length($basename); | ||||
| 157 | } | ||||
| 158 | else { | ||||
| 159 | 18 | 88µs | 18 | 376µs | _strip_trailing_sep($dirname); # spent 376µs making 18 calls to File::Basename::_strip_trailing_sep, avg 21µs/call |
| 160 | 18 | 14µs | unless( length($basename) ) { | ||
| 161 | ($basename,$dirname) = fileparse $dirname; | ||||
| 162 | _strip_trailing_sep($dirname); | ||||
| 163 | } | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | 18 | 81µs | $dirname; | ||
| 167 | } | ||||
| 168 | |||||
| 169 | # Strip the trailing path separator. | ||||
| 170 | sub _strip_trailing_sep { | ||||
| 171 | 4145 | 8.08ms | my $type = $Fileparse_fstype; | ||
| 172 | |||||
| 173 | 4145 | 44.1ms | if ($type eq 'MacOS') { | ||
| 174 | $_[0] =~ s/([^:]):\z/$1/s; | ||||
| 175 | } | ||||
| 176 | elsif (grep { $type eq $_ } qw(MSDOS DOS MSWin32 OS2)) { | ||||
| 177 | $_[0] =~ s/([^:])[\\\/]*\z/$1/; | ||||
| 178 | } | ||||
| 179 | else { | ||||
| 180 | 4145 | 64.5ms | 4145 | 45.4ms | $_[0] =~ s{(.)/*\z}{$1}s; # spent 45.4ms making 4145 calls to File::Basename::CORE:subst, avg 11µs/call |
| 181 | } | ||||
| 182 | } | ||||
| 183 | |||||
| 184 | # spent 6µs within File::Basename::BEGIN@184 which was called:
# once (6µs+0s) by main::BEGIN@4 at line 207 | ||||
| 185 | |||||
| 186 | 1 | 2µs | my @Ignore_Case = qw(MacOS VMS AmigaOS OS2 RISCOS MSWin32 MSDOS DOS Epoc); | ||
| 187 | 1 | 6µs | my @Types = (@Ignore_Case, qw(Unix)); | ||
| 188 | |||||
| 189 | # spent 61µs (32+29) within File::Basename::fileparse_set_fstype which was called:
# once (32µs+29µs) by main::BEGIN@4 at line 21 | ||||
| 190 | 1 | 200ns | my $old = $Fileparse_fstype; | ||
| 191 | |||||
| 192 | 1 | 300ns | if (@_) { | ||
| 193 | 1 | 1µs | my $new_type = shift; | ||
| 194 | |||||
| 195 | 1 | 200ns | $Fileparse_fstype = 'Unix'; # default | ||
| 196 | 1 | 400ns | foreach my $type (@Types) { | ||
| 197 | 10 | 56µs | 20 | 29µs | $Fileparse_fstype = $type if $new_type =~ /^$type/i; # spent 26µs making 10 calls to File::Basename::CORE:regcomp, avg 3µs/call
# spent 3µs making 10 calls to File::Basename::CORE:match, avg 320ns/call |
| 198 | } | ||||
| 199 | |||||
| 200 | $Fileparse_igncase = | ||||
| 201 | 1 | 2µs | (grep $Fileparse_fstype eq $_, @Ignore_Case) ? 1 : 0; | ||
| 202 | } | ||||
| 203 | |||||
| 204 | 1 | 2µs | return $old; | ||
| 205 | } | ||||
| 206 | |||||
| 207 | 1 | 29µs | 1 | 6µs | } # spent 6µs making 1 call to File::Basename::BEGIN@184 |
| 208 | |||||
| 209 | 1 | 6µs | 1; | ||
| 210 | |||||
sub File::Basename::CORE:match; # opcode | |||||
# spent 26µs within File::Basename::CORE:regcomp which was called 10 times, avg 3µs/call:
# 10 times (26µs+0s) by File::Basename::fileparse_set_fstype at line 197, avg 3µs/call | |||||
# spent 45.4ms within File::Basename::CORE:subst which was called 4145 times, avg 11µs/call:
# 4145 times (45.4ms+0s) by File::Basename::_strip_trailing_sep at line 180, avg 11µs/call |