| Filename | /usr/libdata/perl5/OpenBSD/Error.pm |
| Statements | Executed 450 statements in 6.85ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 80 | 2 | 2 | 1.16ms | 44.3ms | OpenBSD::Error::rmtree |
| 1 | 1 | 1 | 136µs | 136µs | OpenBSD::Handler::reset |
| 4 | 4 | 2 | 78µs | 78µs | OpenBSD::Auto::cache |
| 1 | 1 | 1 | 59µs | 70µs | OpenBSD::State::BEGIN@17 |
| 1 | 1 | 1 | 42µs | 64µs | OpenBSD::State::BEGIN@18.5 |
| 1 | 1 | 1 | 34µs | 202µs | OpenBSD::Error::BEGIN@72 |
| 1 | 1 | 1 | 29µs | 80µs | OpenBSD::Auto::BEGIN@29 |
| 1 | 1 | 1 | 21µs | 395µs | OpenBSD::Error::try |
| 2 | 2 | 2 | 13µs | 13µs | OpenBSD::Handler::register |
| 1 | 1 | 1 | 11µs | 121µs | OpenBSD::Auto::__ANON__[:28] |
| 1 | 1 | 1 | 6µs | 6µs | OpenBSD::Error::dienow |
| 1 | 1 | 1 | 6µs | 6µs | OpenBSD::Error::catchall |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::Copy |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::Unlink |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::catch |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::catch::exec |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::catchall::exec |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::child_error |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::fillup_names |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::find_signal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::rethrow |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Error::throw |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Handler::__ANON__[:50] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: Error.pm,v 1.32 2017/04/18 15:12:00 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org> | ||||
| 5 | # | ||||
| 6 | # Permission to use, copy, modify, and distribute this software for any | ||||
| 7 | # purpose with or without fee is hereby granted, provided that the above | ||||
| 8 | # copyright notice and this permission notice appear in all copies. | ||||
| 9 | # | ||||
| 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
| 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
| 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
| 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
| 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
| 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
| 16 | |||||
| 17 | 2 | 124µs | 2 | 81µs | # spent 70µs (59+11) within OpenBSD::State::BEGIN@17 which was called:
# once (59µs+11µs) by OpenBSD::State::BEGIN@88 at line 17 # spent 70µs making 1 call to OpenBSD::State::BEGIN@17
# spent 11µs making 1 call to strict::import |
| 18 | 2 | 349µs | 2 | 86µs | # spent 64µs (42+22) within OpenBSD::State::BEGIN@18.5 which was called:
# once (42µs+22µs) by OpenBSD::State::BEGIN@88 at line 18 # spent 64µs making 1 call to OpenBSD::State::BEGIN@18.5
# spent 22µs making 1 call to warnings::import |
| 19 | |||||
| 20 | package OpenBSD::Auto; | ||||
| 21 | sub cache(*&) | ||||
| 22 | # spent 78µs within OpenBSD::Auto::cache which was called 4 times, avg 20µs/call:
# once (35µs+0s) by main::BEGIN@22 at line 137 of OpenBSD/State.pm
# once (21µs+0s) by main::BEGIN@22 at line 366 of OpenBSD/State.pm
# once (15µs+0s) by OpenBSD::PackageRepository::BEGIN@30 at line 54 of OpenBSD/PackageLocation.pm
# once (7µs+0s) by OpenBSD::PackageRepository::BEGIN@30 at line 68 of OpenBSD/PackageLocation.pm | ||||
| 23 | 4 | 8µs | my ($sym, $code) = @_; | ||
| 24 | 4 | 10µs | my $callpkg = caller; | ||
| 25 | # spent 121µs (11+110) within OpenBSD::Auto::__ANON__[/usr/libdata/perl5/OpenBSD/Error.pm:28] which was called:
# once (11µs+110µs) by OpenBSD::PackageRepository::parse at line 118 of OpenBSD/PackageRepository.pm | ||||
| 26 | 1 | 800ns | my $self = shift; | ||
| 27 | 1 | 8µs | 1 | 110µs | return $self->{$sym} //= &$code($self); # spent 110µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:137] |
| 28 | 4 | 19µs | }; | ||
| 29 | 2 | 968µs | 2 | 130µs | # spent 80µs (29+50) within OpenBSD::Auto::BEGIN@29 which was called:
# once (29µs+50µs) by OpenBSD::State::BEGIN@88 at line 29 # spent 80µs making 1 call to OpenBSD::Auto::BEGIN@29
# spent 50µs making 1 call to strict::unimport |
| 30 | 4 | 67µs | *{$callpkg."::$sym"} = $actual; | ||
| 31 | } | ||||
| 32 | |||||
| 33 | package OpenBSD::Handler; | ||||
| 34 | |||||
| 35 | 1 | 61µs | my $list = []; | ||
| 36 | |||||
| 37 | sub register | ||||
| 38 | # spent 13µs within OpenBSD::Handler::register which was called 2 times, avg 7µs/call:
# once (8µs+0s) by OpenBSD::PackageLocation::BEGIN@24 at line 44 of OpenBSD/Temp.pm
# once (5µs+0s) by OpenBSD::PackageLocator::BEGIN@24 at line 91 of OpenBSD/PackageRepository.pm | ||||
| 39 | 2 | 3µs | my ($class, $code) = @_; | ||
| 40 | 2 | 17µs | push(@$list, $code); | ||
| 41 | } | ||||
| 42 | |||||
| 43 | my $handler = sub { | ||||
| 44 | my $sig = shift; | ||||
| 45 | for my $c (@$list) { | ||||
| 46 | &$c($sig); | ||||
| 47 | } | ||||
| 48 | $SIG{$sig} = 'DEFAULT'; | ||||
| 49 | kill $sig, $$; | ||||
| 50 | 1 | 12µs | }; | ||
| 51 | |||||
| 52 | sub reset | ||||
| 53 | # spent 136µs within OpenBSD::Handler::reset which was called:
# once (136µs+0s) by OpenBSD::State::BEGIN@88 at line 61 | ||||
| 54 | 1 | 96µs | $SIG{'INT'} = $handler; | ||
| 55 | 1 | 10µs | $SIG{'QUIT'} = $handler; | ||
| 56 | 1 | 8µs | $SIG{'HUP'} = $handler; | ||
| 57 | 1 | 9µs | $SIG{'KILL'} = $handler; | ||
| 58 | 1 | 37µs | $SIG{'TERM'} = $handler; | ||
| 59 | } | ||||
| 60 | |||||
| 61 | 1 | 10µs | 1 | 136µs | __PACKAGE__->reset; # spent 136µs making 1 call to OpenBSD::Handler::reset |
| 62 | |||||
| 63 | package OpenBSD::Error; | ||||
| 64 | 1 | 4µs | require Exporter; | ||
| 65 | 1 | 29µs | our @ISA=qw(Exporter); | ||
| 66 | 1 | 8µs | our @EXPORT=qw(Copy Unlink try throw catch catchall rethrow); | ||
| 67 | |||||
| 68 | our ($FileName, $Line, $FullMessage); | ||||
| 69 | |||||
| 70 | 1 | 2µs | my @signal_name = (); | ||
| 71 | |||||
| 72 | 2 | 2.84ms | 2 | 370µs | # spent 202µs (34+168) within OpenBSD::Error::BEGIN@72 which was called:
# once (34µs+168µs) by OpenBSD::State::BEGIN@88 at line 72 # spent 202µs making 1 call to OpenBSD::Error::BEGIN@72
# spent 168µs making 1 call to Exporter::import |
| 73 | |||||
| 74 | sub fillup_names | ||||
| 75 | { | ||||
| 76 | { | ||||
| 77 | # XXX force autoload | ||||
| 78 | package verylocal; | ||||
| 79 | |||||
| 80 | require POSIX; | ||||
| 81 | POSIX->import(qw(signal_h)); | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | for my $sym (keys %POSIX::) { | ||||
| 85 | next unless $sym =~ /^SIG([A-Z].*)/; | ||||
| 86 | my $i = eval "&POSIX::$sym()"; | ||||
| 87 | next unless defined $i; | ||||
| 88 | $signal_name[$i] = $1; | ||||
| 89 | } | ||||
| 90 | # extra BSD signals | ||||
| 91 | $signal_name[5] = 'TRAP'; | ||||
| 92 | $signal_name[7] = 'IOT'; | ||||
| 93 | $signal_name[10] = 'BUS'; | ||||
| 94 | $signal_name[12] = 'SYS'; | ||||
| 95 | $signal_name[16] = 'URG'; | ||||
| 96 | $signal_name[23] = 'IO'; | ||||
| 97 | $signal_name[24] = 'XCPU'; | ||||
| 98 | $signal_name[25] = 'XFSZ'; | ||||
| 99 | $signal_name[26] = 'VTALRM'; | ||||
| 100 | $signal_name[27] = 'PROF'; | ||||
| 101 | $signal_name[28] = 'WINCH'; | ||||
| 102 | $signal_name[29] = 'INFO'; | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | sub find_signal | ||||
| 106 | { | ||||
| 107 | my $number = shift; | ||||
| 108 | |||||
| 109 | if (@signal_name == 0) { | ||||
| 110 | fillup_names(); | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | return $signal_name[$number] || $number; | ||||
| 114 | } | ||||
| 115 | |||||
| 116 | sub child_error | ||||
| 117 | { | ||||
| 118 | my $error = shift // $?; | ||||
| 119 | |||||
| 120 | my $extra = ""; | ||||
| 121 | |||||
| 122 | if ($error & 128) { | ||||
| 123 | $extra = " (core dumped)"; | ||||
| 124 | } | ||||
| 125 | if ($error & 127) { | ||||
| 126 | return "killed by signal ". find_signal($error & 127).$extra; | ||||
| 127 | } else { | ||||
| 128 | return "exit(". ($error >> 8) . ")$extra"; | ||||
| 129 | } | ||||
| 130 | } | ||||
| 131 | |||||
| 132 | sub Copy | ||||
| 133 | { | ||||
| 134 | require File::Copy; | ||||
| 135 | |||||
| 136 | my $r = File::Copy::copy(@_); | ||||
| 137 | if (!$r) { | ||||
| 138 | print "copy(", join(',', @_),") failed: $!\n"; | ||||
| 139 | } | ||||
| 140 | return $r; | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | sub Unlink | ||||
| 144 | { | ||||
| 145 | my $verbose = shift; | ||||
| 146 | my $r = unlink @_; | ||||
| 147 | if ($r != @_) { | ||||
| 148 | print "rm @_ failed: removed only $r targets, $!\n"; | ||||
| 149 | } elsif ($verbose) { | ||||
| 150 | print "rm @_\n"; | ||||
| 151 | } | ||||
| 152 | return $r; | ||||
| 153 | } | ||||
| 154 | |||||
| 155 | sub dienow | ||||
| 156 | # spent 6µs within OpenBSD::Error::dienow which was called:
# once (6µs+0s) by OpenBSD::Error::try at line 176 | ||||
| 157 | 1 | 2µs | my ($error, $handler) = @_; | ||
| 158 | 1 | 6µs | if ($error) { | ||
| 159 | if ($error =~ m/^(.*?)(?:\s+at\s+(.*)\s+line\s+(\d+)\.?)?$/o) { | ||||
| 160 | local $_ = $1; | ||||
| 161 | $FileName = $2; | ||||
| 162 | $Line = $3; | ||||
| 163 | $FullMessage = $error; | ||||
| 164 | |||||
| 165 | $handler->exec($error, '', $1, $2, $3); | ||||
| 166 | } else { | ||||
| 167 | die "Fatal error: can't parse $error"; | ||||
| 168 | } | ||||
| 169 | } | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | sub try(&@) | ||||
| 173 | # spent 395µs (21+374) within OpenBSD::Error::try which was called:
# once (21µs+374µs) by OpenBSD::State::do_options at line 271 of OpenBSD/State.pm | ||||
| 174 | 1 | 2µs | my ($try, $catch) = @_; | ||
| 175 | 2 | 6µs | 1 | 368µs | eval { &$try }; # spent 368µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:269] |
| 176 | 1 | 9µs | 1 | 6µs | dienow($@, $catch); # spent 6µs making 1 call to OpenBSD::Error::dienow |
| 177 | } | ||||
| 178 | |||||
| 179 | sub throw | ||||
| 180 | { | ||||
| 181 | croak @_; | ||||
| 182 | |||||
| 183 | } | ||||
| 184 | |||||
| 185 | sub rethrow | ||||
| 186 | { | ||||
| 187 | my $e = shift; | ||||
| 188 | die $e if $e; | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | sub catch(&) | ||||
| 192 | { | ||||
| 193 | bless $_[0], "OpenBSD::Error::catch"; | ||||
| 194 | } | ||||
| 195 | |||||
| 196 | sub catchall(&) | ||||
| 197 | # spent 6µs within OpenBSD::Error::catchall which was called:
# once (6µs+0s) by OpenBSD::State::do_options at line 271 of OpenBSD/State.pm | ||||
| 198 | 1 | 8µs | bless $_[0], "OpenBSD::Error::catchall"; | ||
| 199 | } | ||||
| 200 | |||||
| 201 | sub rmtree | ||||
| 202 | # spent 44.3ms (1.16+43.1) within OpenBSD::Error::rmtree which was called 80 times, avg 553µs/call:
# 40 times (800µs+38.4ms) by OpenBSD::PackageRepository::wipe_info at line 184 of OpenBSD/PackageRepository.pm, avg 981µs/call
# 40 times (357µs+4.65ms) by OpenBSD::Temp::__ANON__[/usr/libdata/perl5/OpenBSD/Temp.pm:39] at line 36 of OpenBSD/Temp.pm, avg 125µs/call | ||||
| 203 | 80 | 78µs | my $class = shift; | ||
| 204 | 80 | 80µs | require File::Path; | ||
| 205 | 80 | 74µs | require Cwd; | ||
| 206 | |||||
| 207 | # XXX make sure we live somewhere | ||||
| 208 | 80 | 855µs | 80 | 527µs | Cwd::getcwd() || chdir('/'); # spent 527µs making 80 calls to Cwd::getcwd, avg 7µs/call |
| 209 | |||||
| 210 | 80 | 998µs | 80 | 42.6ms | File::Path::rmtree(@_); # spent 42.6ms making 80 calls to File::Path::rmtree, avg 532µs/call |
| 211 | } | ||||
| 212 | |||||
| 213 | package OpenBSD::Error::catch; | ||||
| 214 | sub exec | ||||
| 215 | { | ||||
| 216 | my ($self, $full, $e) = @_; | ||||
| 217 | if ($e) { | ||||
| 218 | &$self; | ||||
| 219 | } else { | ||||
| 220 | die $full; | ||||
| 221 | } | ||||
| 222 | } | ||||
| 223 | |||||
| 224 | package OpenBSD::Error::catchall; | ||||
| 225 | sub exec | ||||
| 226 | { | ||||
| 227 | my ($self, $full, $e) = @_; | ||||
| 228 | &$self; | ||||
| 229 | } | ||||
| 230 | |||||
| 231 | 1 | 36µs | 1; |