| Filename | /usr/libdata/perl5/OpenBSD/State.pm |
| Statements | Executed 205 statements in 6.76ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 21.4ms | 22.3ms | OpenBSD::State::BEGIN@86 |
| 1 | 1 | 1 | 4.33ms | 5.04ms | OpenBSD::State::BEGIN@88 |
| 1 | 1 | 1 | 1.95ms | 2.03ms | OpenBSD::State::BEGIN@87 |
| 3 | 1 | 1 | 741µs | 13.0ms | OpenBSD::State::locator |
| 25 | 8 | 2 | 92µs | 92µs | OpenBSD::State::opt |
| 3 | 1 | 1 | 71µs | 108µs | OpenBSD::State::f |
| 1 | 1 | 1 | 67µs | 323µs | OpenBSD::State::handle_options |
| 1 | 1 | 1 | 65µs | 110µs | OpenBSD::State::__ANON__[:137] |
| 3 | 1 | 1 | 57µs | 279µs | OpenBSD::State::fhsay |
| 3 | 1 | 1 | 54µs | 54µs | OpenBSD::State::CORE:print (opcode) |
| 3 | 1 | 1 | 51µs | 114µs | OpenBSD::State::_fhprint |
| 2 | 1 | 1 | 42µs | 465ms | OpenBSD::PackageRepositoryFactory::find |
| 3 | 2 | 1 | 41µs | 13.0ms | OpenBSD::PackageRepositoryFactory::locator |
| 3 | 1 | 1 | 41µs | 79µs | OpenBSD::PackageRepositoryFactory::installed |
| 1 | 1 | 1 | 37µs | 45µs | OpenBSD::State::init |
| 6 | 3 | 1 | 34µs | 34µs | OpenBSD::State::repo |
| 3 | 2 | 2 | 33µs | 57µs | OpenBSD::State::defines |
| 3 | 1 | 1 | 32µs | 310µs | OpenBSD::State::say |
| 1 | 1 | 1 | 31µs | 38µs | main::BEGIN@19.3 |
| 3 | 1 | 1 | 24µs | 24µs | OpenBSD::State::CORE:subst (opcode) |
| 1 | 1 | 1 | 23µs | 1.29s | OpenBSD::PackageRepositoryFactory::match_locations |
| 1 | 1 | 1 | 23µs | 23µs | OpenBSD::State::CORE:open (opcode) |
| 1 | 1 | 1 | 19µs | 62µs | OpenBSD::State::BEGIN@300 |
| 1 | 1 | 1 | 18µs | 18µs | OpenBSD::State::CORE:readline (opcode) |
| 1 | 1 | 1 | 18µs | 31µs | main::BEGIN@20.4 |
| 1 | 1 | 1 | 15µs | 60µs | OpenBSD::State::new |
| 1 | 1 | 1 | 14µs | 224µs | OpenBSD::State::do_options |
| 6 | 1 | 1 | 13µs | 13µs | OpenBSD::State::CORE:substcont (opcode) |
| 1 | 1 | 1 | 12µs | 31µs | OpenBSD::State::BEGIN@301 |
| 3 | 1 | 1 | 8µs | 8µs | OpenBSD::State::sync_display |
| 5 | 5 | 1 | 7µs | 7µs | OpenBSD::State::CORE:match (opcode) |
| 1 | 1 | 1 | 7µs | 184µs | OpenBSD::State::__ANON__[:287] |
| 1 | 1 | 1 | 6µs | 190µs | OpenBSD::State::__ANON__[:269] |
| 1 | 1 | 1 | 5µs | 5µs | OpenBSD::PackageRepositoryFactory::new |
| 1 | 1 | 1 | 5µs | 5µs | OpenBSD::State::verbose |
| 1 | 1 | 1 | 4µs | 4µs | OpenBSD::State::usage_is |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::grabPlist |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::path |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::path_parse |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::reinitialize |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:271] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:280] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:283] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:347] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:351] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:366] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:436] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::__ANON__[:441] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::_errprint |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::_fatal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::_print |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::_system |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::child_error |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::copy |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::copy_file |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::errprint |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::errsay |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::fatal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::fhprint |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::fillup_names |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::find_signal |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::find_window_size |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::height |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::print |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::system |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::unlink |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::usage |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::verbose_system |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::State::width |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: State.pm,v 1.46 2017/05/29 12:28:54 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2007-2014 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 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
| 17 | # | ||||
| 18 | |||||
| 19 | 2 | 50µs | 2 | 44µs | # spent 38µs (31+7) within main::BEGIN@19.3 which was called:
# once (31µs+7µs) by main::BEGIN@22 at line 19 # spent 38µs making 1 call to main::BEGIN@19.3
# spent 7µs making 1 call to strict::import |
| 20 | 2 | 687µs | 2 | 45µs | # spent 31µs (18+13) within main::BEGIN@20.4 which was called:
# once (18µs+13µs) by main::BEGIN@22 at line 20 # spent 31µs making 1 call to main::BEGIN@20.4
# spent 13µs making 1 call to warnings::import |
| 21 | |||||
| 22 | package OpenBSD::PackageRepositoryFactory; | ||||
| 23 | sub new | ||||
| 24 | # spent 5µs within OpenBSD::PackageRepositoryFactory::new which was called:
# once (5µs+0s) by OpenBSD::State::init at line 112 | ||||
| 25 | 1 | 1µs | my ($class, $state) = @_; | ||
| 26 | 1 | 9µs | bless {state => $state}, $class; | ||
| 27 | } | ||||
| 28 | |||||
| 29 | sub locator | ||||
| 30 | { | ||||
| 31 | 3 | 3µs | my $self = shift; | ||
| 32 | 3 | 30µs | 3 | 13.0ms | return $self->{state}->locator; # spent 13.0ms making 3 calls to OpenBSD::State::locator, avg 4.32ms/call |
| 33 | } | ||||
| 34 | |||||
| 35 | sub installed | ||||
| 36 | # spent 79µs (41+38) within OpenBSD::PackageRepositoryFactory::installed which was called 3 times, avg 26µs/call:
# 3 times (41µs+38µs) by OpenBSD::PkgInfo::find_pkg at line 237 of OpenBSD/PkgInfo.pm, avg 26µs/call | ||||
| 37 | 3 | 4µs | my ($self, $all) = @_; | ||
| 38 | 3 | 5µs | require OpenBSD::PackageRepository::Installed; | ||
| 39 | |||||
| 40 | 3 | 50µs | 3 | 38µs | return OpenBSD::PackageRepository::Installed->new($all, $self->{state}); # spent 38µs making 3 calls to OpenBSD::PackageRepository::Installed::new, avg 13µs/call |
| 41 | } | ||||
| 42 | |||||
| 43 | sub path_parse | ||||
| 44 | { | ||||
| 45 | my ($self, $pkgname) = @_; | ||||
| 46 | |||||
| 47 | return $self->locator->path_parse($pkgname, $self->{state}); | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | sub find | ||||
| 51 | # spent 465ms (42µs+465) within OpenBSD::PackageRepositoryFactory::find which was called 2 times, avg 233ms/call:
# 2 times (42µs+465ms) by OpenBSD::PkgInfo::find_pkg_in at line 222 of OpenBSD/PkgInfo.pm, avg 233ms/call | ||||
| 52 | 2 | 2µs | my ($self, $pkg) = @_; | ||
| 53 | |||||
| 54 | 2 | 47µs | 4 | 465ms | return $self->locator->find($pkg, $self->{state}); # spent 465ms making 2 calls to OpenBSD::PackageLocator::find, avg 232ms/call
# spent 32µs making 2 calls to OpenBSD::PackageRepositoryFactory::locator, avg 16µs/call |
| 55 | } | ||||
| 56 | |||||
| 57 | sub reinitialize | ||||
| 58 | { | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub match_locations | ||||
| 62 | # spent 1.29s (23µs+1.29) within OpenBSD::PackageRepositoryFactory::match_locations which was called:
# once (23µs+1.29s) by OpenBSD::PkgInfo::parse_and_run at line 606 of OpenBSD/PkgInfo.pm | ||||
| 63 | 1 | 900ns | my $self = shift; | ||
| 64 | |||||
| 65 | 1 | 23µs | 2 | 1.29s | return $self->locator->match_locations(@_, $self->{state}); # spent 1.27s making 1 call to OpenBSD::PackageLocator::match_locations
# spent 13.0ms making 1 call to OpenBSD::PackageRepositoryFactory::locator |
| 66 | } | ||||
| 67 | |||||
| 68 | sub grabPlist | ||||
| 69 | { | ||||
| 70 | my ($self, $url, $code) = @_; | ||||
| 71 | |||||
| 72 | return $self->locator->grabPlist($url, $code, $self->{state}); | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | sub path | ||||
| 76 | { | ||||
| 77 | my $self = shift; | ||||
| 78 | require OpenBSD::PackageRepositoryList; | ||||
| 79 | |||||
| 80 | return OpenBSD::PackageRepositoryList->new($self->{state}); | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | # common routines to everything state. | ||||
| 84 | # in particular, provides "singleton-like" access to UI. | ||||
| 85 | package OpenBSD::State; | ||||
| 86 | 2 | 339µs | 2 | 22.4ms | # spent 22.3ms (21.4+841µs) within OpenBSD::State::BEGIN@86 which was called:
# once (21.4ms+841µs) by main::BEGIN@22 at line 86 # spent 22.3ms making 1 call to OpenBSD::State::BEGIN@86
# spent 167µs making 1 call to Exporter::import |
| 87 | 2 | 269µs | 1 | 2.03ms | # spent 2.03ms (1.95+78µs) within OpenBSD::State::BEGIN@87 which was called:
# once (1.95ms+78µs) by main::BEGIN@22 at line 87 # spent 2.03ms making 1 call to OpenBSD::State::BEGIN@87 |
| 88 | 2 | 2.95ms | 2 | 5.16ms | # spent 5.04ms (4.33+703µs) within OpenBSD::State::BEGIN@88 which was called:
# once (4.33ms+703µs) by main::BEGIN@22 at line 88 # spent 5.04ms making 1 call to OpenBSD::State::BEGIN@88
# spent 125µs making 1 call to Exporter::import |
| 89 | 1 | 1µs | require Exporter; | ||
| 90 | 1 | 7µs | our @ISA = qw(Exporter); | ||
| 91 | 1 | 800ns | our @EXPORT = (); | ||
| 92 | |||||
| 93 | sub locator | ||||
| 94 | # spent 13.0ms (741µs+12.2) within OpenBSD::State::locator which was called 3 times, avg 4.32ms/call:
# 3 times (741µs+12.2ms) by OpenBSD::PackageRepositoryFactory::locator at line 32, avg 4.32ms/call | ||||
| 95 | 3 | 130µs | require OpenBSD::PackageLocator; | ||
| 96 | 3 | 22µs | return "OpenBSD::PackageLocator"; | ||
| 97 | } | ||||
| 98 | |||||
| 99 | sub new | ||||
| 100 | # spent 60µs (15+45) within OpenBSD::State::new which was called:
# once (15µs+45µs) by OpenBSD::PkgInfo::parse_and_run at line 529 of OpenBSD/PkgInfo.pm | ||||
| 101 | 1 | 1µs | my $class = shift; | ||
| 102 | 1 | 800ns | my $cmd = shift; | ||
| 103 | 1 | 2µs | my $o = bless {cmd => $cmd}, $class; | ||
| 104 | 1 | 6µs | 1 | 45µs | $o->init(@_); # spent 45µs making 1 call to OpenBSD::State::init |
| 105 | 1 | 5µs | return $o; | ||
| 106 | } | ||||
| 107 | |||||
| 108 | sub init | ||||
| 109 | # spent 45µs (37+8) within OpenBSD::State::init which was called:
# once (37µs+8µs) by OpenBSD::State::new at line 104 | ||||
| 110 | 1 | 900ns | my $self = shift; | ||
| 111 | 1 | 19µs | 1 | 3µs | $self->{subst} = OpenBSD::Subst->new; # spent 3µs making 1 call to OpenBSD::Subst::new |
| 112 | 1 | 4µs | 1 | 5µs | $self->{repo} = OpenBSD::PackageRepositoryFactory->new($self); # spent 5µs making 1 call to OpenBSD::PackageRepositoryFactory::new |
| 113 | 1 | 5µs | $self->{export_level} = 1; | ||
| 114 | } | ||||
| 115 | |||||
| 116 | sub repo | ||||
| 117 | # spent 34µs within OpenBSD::State::repo which was called 6 times, avg 6µs/call:
# 3 times (23µs+0s) by OpenBSD::PkgInfo::find_pkg at line 237 of OpenBSD/PkgInfo.pm, avg 8µs/call
# 2 times (7µs+0s) by OpenBSD::PkgInfo::find_pkg at line 246 of OpenBSD/PkgInfo.pm, avg 3µs/call
# once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 606 of OpenBSD/PkgInfo.pm | ||||
| 118 | 6 | 5µs | my $self = shift; | ||
| 119 | 6 | 33µs | return $self->{repo}; | ||
| 120 | } | ||||
| 121 | |||||
| 122 | sub sync_display | ||||
| 123 | 3 | 10µs | # spent 8µs within OpenBSD::State::sync_display which was called 3 times, avg 3µs/call:
# 3 times (8µs+0s) by OpenBSD::State::_fhprint at line 205, avg 3µs/call | ||
| 124 | } | ||||
| 125 | |||||
| 126 | OpenBSD::Auto::cache(installpath, | ||||
| 127 | # spent 110µs (65+46) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] which was called:
# once (65µs+46µs) by OpenBSD::Auto::__ANON__[/usr/libdata/perl5/OpenBSD/Error.pm:28] at line 27 of OpenBSD/Error.pm | ||||
| 128 | 1 | 800ns | my $self = shift; | ||
| 129 | 1 | 2µs | require OpenBSD::Paths; | ||
| 130 | 1 | 44µs | 2 | 24µs | open(my $fh, '<', OpenBSD::Paths->installurl) or return undef; # spent 23µs making 1 call to OpenBSD::State::CORE:open
# spent 1µs making 1 call to OpenBSD::Paths::installurl |
| 131 | 1 | 24µs | 1 | 18µs | while (<$fh>) { # spent 18µs making 1 call to OpenBSD::State::CORE:readline |
| 132 | 1 | 1µs | chomp; | ||
| 133 | 1 | 5µs | 1 | 2µs | next if m/^\s*\#/; # spent 2µs making 1 call to OpenBSD::State::CORE:match |
| 134 | 1 | 5µs | 1 | 2µs | next if m/^\s*$/; # spent 2µs making 1 call to OpenBSD::State::CORE:match |
| 135 | 1 | 31µs | return "$_/%c/packages/%a/"; | ||
| 136 | } | ||||
| 137 | 1 | 6µs | 1 | 13µs | }); # spent 13µs making 1 call to OpenBSD::Auto::cache |
| 138 | |||||
| 139 | sub usage_is | ||||
| 140 | # spent 4µs within OpenBSD::State::usage_is which was called:
# once (4µs+0s) by OpenBSD::State::handle_options at line 284 | ||||
| 141 | 1 | 1µs | my ($self, @usage) = @_; | ||
| 142 | 1 | 4µs | $self->{usage} = \@usage; | ||
| 143 | } | ||||
| 144 | |||||
| 145 | sub verbose | ||||
| 146 | # spent 5µs within OpenBSD::State::verbose which was called:
# once (5µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 604 of OpenBSD/PkgInfo.pm | ||||
| 147 | 1 | 1µs | my $self = shift; | ||
| 148 | 1 | 7µs | return $self->{v}; | ||
| 149 | } | ||||
| 150 | |||||
| 151 | sub opt | ||||
| 152 | # spent 92µs within OpenBSD::State::opt which was called 25 times, avg 4µs/call:
# 11 times (25µs+0s) by OpenBSD::PkgInfo::State::hasanyopt at line 151 of OpenBSD/PkgInfo.pm, avg 2µs/call
# 6 times (42µs+0s) by OpenBSD::PkgInfo::print_info at line 393 of OpenBSD/PkgInfo.pm, avg 7µs/call
# 3 times (10µs+0s) by OpenBSD::PkgInfo::print_info at line 409 of OpenBSD/PkgInfo.pm, avg 3µs/call
# once (4µs+0s) by OpenBSD::State::handle_options at line 288
# once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 605 of OpenBSD/PkgInfo.pm
# once (3µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 601 of OpenBSD/PkgInfo.pm
# once (3µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 564 of OpenBSD/PkgInfo.pm
# once (2µs+0s) by OpenBSD::PkgInfo::State::lock at line 72 of OpenBSD/PkgInfo.pm | ||||
| 153 | 25 | 26µs | my ($self, $k) = @_; | ||
| 154 | 25 | 88µs | return $self->{opt}{$k}; | ||
| 155 | } | ||||
| 156 | |||||
| 157 | sub usage | ||||
| 158 | { | ||||
| 159 | my $self = shift; | ||||
| 160 | my $code = 0; | ||||
| 161 | if (@_) { | ||||
| 162 | print STDERR "$self->{cmd}: ", $self->f(@_), "\n"; | ||||
| 163 | $code = 1; | ||||
| 164 | } | ||||
| 165 | print STDERR "Usage: $self->{cmd} ", shift(@{$self->{usage}}), "\n"; | ||||
| 166 | for my $l (@{$self->{usage}}) { | ||||
| 167 | print STDERR " $l\n"; | ||||
| 168 | } | ||||
| 169 | exit($code); | ||||
| 170 | } | ||||
| 171 | |||||
| 172 | sub f | ||||
| 173 | # spent 108µs (71+37) within OpenBSD::State::f which was called 3 times, avg 36µs/call:
# 3 times (71µs+37µs) by OpenBSD::State::fhsay at line 234, avg 36µs/call | ||||
| 174 | 3 | 3µs | my $self = shift; | ||
| 175 | 3 | 3µs | if (@_ == 0) { | ||
| 176 | return undef; | ||||
| 177 | } | ||||
| 178 | 3 | 17µs | my ($fmt, @l) = @_; | ||
| 179 | # make it so that #0 is # | ||||
| 180 | 3 | 5µs | unshift(@l, '#'); | ||
| 181 | 3 | 68µs | 9 | 37µs | $fmt =~ s,\#(\d+),($l[$1] // "<Undefined #$1>"),ge; # spent 24µs making 3 calls to OpenBSD::State::CORE:subst, avg 8µs/call
# spent 13µs making 6 calls to OpenBSD::State::CORE:substcont, avg 2µs/call |
| 182 | 3 | 18µs | return $fmt; | ||
| 183 | } | ||||
| 184 | |||||
| 185 | sub _fatal | ||||
| 186 | { | ||||
| 187 | my $self = shift; | ||||
| 188 | # implementation note: to print "fatal errors" elsewhere, | ||||
| 189 | # the way is to eval { croak @_}; and decide what to do with $@. | ||||
| 190 | delete $SIG{__DIE__}; | ||||
| 191 | $self->sync_display; | ||||
| 192 | croak "Fatal error: ", @_, "\n"; | ||||
| 193 | } | ||||
| 194 | |||||
| 195 | sub fatal | ||||
| 196 | { | ||||
| 197 | my $self = shift; | ||||
| 198 | $self->_fatal($self->f(@_)); | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | sub _fhprint | ||||
| 202 | # spent 114µs (51+63) within OpenBSD::State::_fhprint which was called 3 times, avg 38µs/call:
# 3 times (51µs+63µs) by OpenBSD::State::fhsay at line 234, avg 38µs/call | ||||
| 203 | 3 | 3µs | my $self = shift; | ||
| 204 | 3 | 3µs | my $fh = shift; | ||
| 205 | 3 | 13µs | 3 | 8µs | $self->sync_display; # spent 8µs making 3 calls to OpenBSD::State::sync_display, avg 3µs/call |
| 206 | 3 | 89µs | 3 | 54µs | print $fh @_; # spent 54µs making 3 calls to OpenBSD::State::CORE:print, avg 18µs/call |
| 207 | } | ||||
| 208 | sub _print | ||||
| 209 | { | ||||
| 210 | my $self = shift; | ||||
| 211 | $self->_fhprint(\*STDOUT, @_); | ||||
| 212 | } | ||||
| 213 | |||||
| 214 | sub _errprint | ||||
| 215 | { | ||||
| 216 | my $self = shift; | ||||
| 217 | $self->_fhprint(\*STDERR, @_); | ||||
| 218 | } | ||||
| 219 | |||||
| 220 | sub fhprint | ||||
| 221 | { | ||||
| 222 | my $self = shift; | ||||
| 223 | my $fh = shift; | ||||
| 224 | $self->_fhprint($fh, $self->f(@_)); | ||||
| 225 | } | ||||
| 226 | |||||
| 227 | sub fhsay | ||||
| 228 | # spent 279µs (57+222) within OpenBSD::State::fhsay which was called 3 times, avg 93µs/call:
# 3 times (57µs+222µs) by OpenBSD::State::say at line 247, avg 93µs/call | ||||
| 229 | 3 | 3µs | my $self = shift; | ||
| 230 | 3 | 3µs | my $fh = shift; | ||
| 231 | 3 | 15µs | if (@_ == 0) { | ||
| 232 | $self->_fhprint($fh, "\n"); | ||||
| 233 | } else { | ||||
| 234 | 3 | 31µs | 6 | 222µs | $self->_fhprint($fh, $self->f(@_), "\n"); # spent 114µs making 3 calls to OpenBSD::State::_fhprint, avg 38µs/call
# spent 108µs making 3 calls to OpenBSD::State::f, avg 36µs/call |
| 235 | } | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | sub print | ||||
| 239 | { | ||||
| 240 | my $self = shift; | ||||
| 241 | $self->fhprint(\*STDOUT, @_); | ||||
| 242 | } | ||||
| 243 | |||||
| 244 | sub say | ||||
| 245 | # spent 310µs (32+279) within OpenBSD::State::say which was called 3 times, avg 104µs/call:
# 3 times (32µs+279µs) by OpenBSD::PkgInfo::print_info at line 409 of OpenBSD/PkgInfo.pm, avg 104µs/call | ||||
| 246 | 3 | 3µs | my $self = shift; | ||
| 247 | 3 | 25µs | 3 | 279µs | $self->fhsay(\*STDOUT, @_); # spent 279µs making 3 calls to OpenBSD::State::fhsay, avg 93µs/call |
| 248 | } | ||||
| 249 | |||||
| 250 | sub errprint | ||||
| 251 | { | ||||
| 252 | my $self = shift; | ||||
| 253 | $self->fhprint(\*STDERR, @_); | ||||
| 254 | } | ||||
| 255 | |||||
| 256 | sub errsay | ||||
| 257 | { | ||||
| 258 | my $self = shift; | ||||
| 259 | $self->fhsay(\*STDERR, @_); | ||||
| 260 | } | ||||
| 261 | |||||
| 262 | sub do_options | ||||
| 263 | # spent 224µs (14+210) within OpenBSD::State::do_options which was called:
# once (14µs+210µs) by OpenBSD::State::handle_options at line 287 | ||||
| 264 | 1 | 900ns | my ($state, $sub) = @_; | ||
| 265 | # this could be nicer... | ||||
| 266 | |||||
| 267 | # spent 190µs (6+184) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] which was called:
# once (6µs+184µs) by OpenBSD::Error::try at line 175 of OpenBSD/Error.pm | ||||
| 268 | 1 | 5µs | 1 | 184µs | &$sub; # spent 184µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:287] |
| 269 | } catchall { | ||||
| 270 | $state->usage("#1", $_); | ||||
| 271 | 1 | 14µs | 2 | 210µs | }; # spent 207µs making 1 call to OpenBSD::Error::try
# spent 3µs making 1 call to OpenBSD::Error::catchall |
| 272 | } | ||||
| 273 | |||||
| 274 | sub handle_options | ||||
| 275 | # spent 323µs (67+256) within OpenBSD::State::handle_options which was called:
# once (67µs+256µs) by OpenBSD::PkgInfo::parse_and_run at line 560 of OpenBSD/PkgInfo.pm | ||||
| 276 | 1 | 2µs | my ($state, $opt_string, @usage) = @_; | ||
| 277 | 1 | 1µs | require OpenBSD::Getopt; | ||
| 278 | |||||
| 279 | 1 | 7µs | 1 | 2µs | $state->{opt}{v} = 0 unless $opt_string =~ m/v/; # spent 2µs making 1 call to OpenBSD::State::CORE:match |
| 280 | 1 | 5µs | 1 | 1µs | $state->{opt}{h} = sub { $state->usage; } unless $opt_string =~ m/h/; # spent 1µs making 1 call to OpenBSD::State::CORE:match |
| 281 | $state->{opt}{D} = sub { | ||||
| 282 | $state->{subst}->parse_option(shift); | ||||
| 283 | 1 | 6µs | 1 | 900ns | } unless $opt_string =~ m/D/; # spent 900ns making 1 call to OpenBSD::State::CORE:match |
| 284 | 1 | 5µs | 1 | 4µs | $state->usage_is(@usage); # spent 4µs making 1 call to OpenBSD::State::usage_is |
| 285 | # spent 184µs (7+177) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:287] which was called:
# once (7µs+177µs) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] at line 268 | ||||
| 286 | 1 | 7µs | 1 | 177µs | OpenBSD::Getopt::getopts($opt_string.'hvD:', $state->{opt}); # spent 177µs making 1 call to OpenBSD::Getopt::getopts |
| 287 | 1 | 13µs | 1 | 224µs | }); # spent 224µs making 1 call to OpenBSD::State::do_options |
| 288 | 1 | 6µs | 1 | 4µs | $state->{v} = $state->opt('v'); # spent 4µs making 1 call to OpenBSD::State::opt |
| 289 | |||||
| 290 | 1 | 7µs | 2 | 20µs | if ($state->defines('unsigned')) { # spent 20µs making 2 calls to OpenBSD::State::defines, avg 10µs/call |
| 291 | $state->{signature_style} //= 'unsigned'; | ||||
| 292 | } elsif ($state->defines('oldsign')) { | ||||
| 293 | $state->fatal('old style signature no longer supported'); | ||||
| 294 | } else { | ||||
| 295 | 1 | 1µs | $state->{signature_style} //= 'new'; | ||
| 296 | } | ||||
| 297 | |||||
| 298 | 1 | 5µs | return if $state->{no_exports}; | ||
| 299 | # XXX | ||||
| 300 | 2 | 62µs | 2 | 104µs | # spent 62µs (19+43) within OpenBSD::State::BEGIN@300 which was called:
# once (19µs+43µs) by main::BEGIN@22 at line 300 # spent 62µs making 1 call to OpenBSD::State::BEGIN@300
# spent 43µs making 1 call to strict::unimport |
| 301 | 2 | 1.29ms | 2 | 50µs | # spent 31µs (12+19) within OpenBSD::State::BEGIN@301 which was called:
# once (12µs+19µs) by main::BEGIN@22 at line 301 # spent 31µs making 1 call to OpenBSD::State::BEGIN@301
# spent 19µs making 1 call to strict::unimport |
| 302 | for my $k (keys %{$state->{opt}}) { | ||||
| 303 | ${"opt_$k"} = $state->opt($k); | ||||
| 304 | push(@EXPORT, "\$opt_$k"); | ||||
| 305 | } | ||||
| 306 | local $Exporter::ExportLevel = $state->{export_level}; | ||||
| 307 | import OpenBSD::State; | ||||
| 308 | } | ||||
| 309 | |||||
| 310 | sub defines | ||||
| 311 | # spent 57µs (33+24) within OpenBSD::State::defines which was called 3 times, avg 19µs/call:
# 2 times (12µs+7µs) by OpenBSD::State::handle_options at line 290, avg 10µs/call
# once (21µs+17µs) by OpenBSD::PackageRepositoryBase::parse_url at line 73 of OpenBSD/PackageRepository/Installed.pm | ||||
| 312 | 3 | 6µs | my ($self, $k) = @_; | ||
| 313 | 3 | 39µs | 3 | 24µs | return $self->{subst}->value($k); # spent 24µs making 3 calls to OpenBSD::Subst::value, avg 8µs/call |
| 314 | } | ||||
| 315 | |||||
| 316 | sub width | ||||
| 317 | { | ||||
| 318 | my $self = shift; | ||||
| 319 | if (!defined $self->{width}) { | ||||
| 320 | $self->find_window_size; | ||||
| 321 | } | ||||
| 322 | return $self->{width}; | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | sub height | ||||
| 326 | { | ||||
| 327 | my $self = shift; | ||||
| 328 | if (!defined $self->{height}) { | ||||
| 329 | $self->find_window_size; | ||||
| 330 | } | ||||
| 331 | return $self->{height}; | ||||
| 332 | } | ||||
| 333 | |||||
| 334 | sub find_window_size | ||||
| 335 | { | ||||
| 336 | my $self = shift; | ||||
| 337 | require Term::ReadKey; | ||||
| 338 | my @l = Term::ReadKey::GetTermSizeGWINSZ(\*STDOUT); | ||||
| 339 | if (@l != 4) { | ||||
| 340 | $self->{width} = 80; | ||||
| 341 | $self->{height} = 24; | ||||
| 342 | } else { | ||||
| 343 | $self->{width} = $l[0]; | ||||
| 344 | $self->{height} = $l[1]; | ||||
| 345 | $SIG{'WINCH'} = sub { | ||||
| 346 | $self->find_window_size; | ||||
| 347 | }; | ||||
| 348 | } | ||||
| 349 | $SIG{'CONT'} = sub { | ||||
| 350 | $self->find_window_size(1); | ||||
| 351 | } | ||||
| 352 | } | ||||
| 353 | |||||
| 354 | OpenBSD::Auto::cache(signer_list, | ||||
| 355 | sub { | ||||
| 356 | my $self = shift; | ||||
| 357 | if ($self->defines('SIGNER')) { | ||||
| 358 | return [split /,/, $self->{subst}->value('SIGNER')]; | ||||
| 359 | } else { | ||||
| 360 | if ($self->defines('FW_UPDATE')) { | ||||
| 361 | return [qr{^.*fw$}]; | ||||
| 362 | } else { | ||||
| 363 | return [qr{^.*pkg$}]; | ||||
| 364 | } | ||||
| 365 | } | ||||
| 366 | 1 | 4µs | 1 | 7µs | }); # spent 7µs making 1 call to OpenBSD::Auto::cache |
| 367 | |||||
| 368 | 1 | 800ns | my @signal_name = (); | ||
| 369 | sub fillup_names | ||||
| 370 | { | ||||
| 371 | { | ||||
| 372 | # XXX force autoload | ||||
| 373 | package verylocal; | ||||
| 374 | |||||
| 375 | require POSIX; | ||||
| 376 | POSIX->import(qw(signal_h)); | ||||
| 377 | } | ||||
| 378 | |||||
| 379 | for my $sym (keys %POSIX::) { | ||||
| 380 | next unless $sym =~ /^SIG([A-Z].*)/; | ||||
| 381 | $signal_name[eval "&POSIX::$sym()"] = $1; | ||||
| 382 | } | ||||
| 383 | # extra BSD signals | ||||
| 384 | $signal_name[5] = 'TRAP'; | ||||
| 385 | $signal_name[7] = 'IOT'; | ||||
| 386 | $signal_name[10] = 'BUS'; | ||||
| 387 | $signal_name[12] = 'SYS'; | ||||
| 388 | $signal_name[16] = 'URG'; | ||||
| 389 | $signal_name[23] = 'IO'; | ||||
| 390 | $signal_name[24] = 'XCPU'; | ||||
| 391 | $signal_name[25] = 'XFSZ'; | ||||
| 392 | $signal_name[26] = 'VTALRM'; | ||||
| 393 | $signal_name[27] = 'PROF'; | ||||
| 394 | $signal_name[28] = 'WINCH'; | ||||
| 395 | $signal_name[29] = 'INFO'; | ||||
| 396 | } | ||||
| 397 | |||||
| 398 | sub find_signal | ||||
| 399 | { | ||||
| 400 | my $number = shift; | ||||
| 401 | |||||
| 402 | if (@signal_name == 0) { | ||||
| 403 | fillup_names(); | ||||
| 404 | } | ||||
| 405 | |||||
| 406 | return $signal_name[$number] || $number; | ||||
| 407 | } | ||||
| 408 | |||||
| 409 | sub child_error | ||||
| 410 | { | ||||
| 411 | my $self = shift; | ||||
| 412 | my $error = $?; | ||||
| 413 | |||||
| 414 | my $extra = ""; | ||||
| 415 | |||||
| 416 | if ($error & 128) { | ||||
| 417 | $extra = $self->f(" (core dumped)"); | ||||
| 418 | } | ||||
| 419 | if ($error & 127) { | ||||
| 420 | return $self->f("killed by signal #1#2", | ||||
| 421 | find_signal($error & 127), $extra); | ||||
| 422 | } else { | ||||
| 423 | return $self->f("exit(#1)#2", ($error >> 8), $extra); | ||||
| 424 | } | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | sub _system | ||||
| 428 | { | ||||
| 429 | my $self = shift; | ||||
| 430 | $self->sync_display; | ||||
| 431 | my $r = fork; | ||||
| 432 | my ($todo, $todo2); | ||||
| 433 | if (ref $_[0] eq 'CODE') { | ||||
| 434 | $todo = shift; | ||||
| 435 | } else { | ||||
| 436 | $todo = sub {}; | ||||
| 437 | } | ||||
| 438 | if (ref $_[0] eq 'CODE') { | ||||
| 439 | $todo2 = shift; | ||||
| 440 | } else { | ||||
| 441 | $todo2 = sub {}; | ||||
| 442 | } | ||||
| 443 | if (!defined $r) { | ||||
| 444 | return 1; | ||||
| 445 | } elsif ($r == 0) { | ||||
| 446 | &$todo; | ||||
| 447 | exec {$_[0]} @_ or return 1; | ||||
| 448 | } else { | ||||
| 449 | &$todo2; | ||||
| 450 | waitpid($r, 0); | ||||
| 451 | return $?; | ||||
| 452 | } | ||||
| 453 | } | ||||
| 454 | |||||
| 455 | sub system | ||||
| 456 | { | ||||
| 457 | my $self = shift; | ||||
| 458 | my $r = $self->_system(@_); | ||||
| 459 | if ($r != 0) { | ||||
| 460 | if (ref $_[0] eq 'CODE') { | ||||
| 461 | shift; | ||||
| 462 | } | ||||
| 463 | if (ref $_[0] eq 'CODE') { | ||||
| 464 | shift; | ||||
| 465 | } | ||||
| 466 | $self->say("system(#1) failed: #2", | ||||
| 467 | join(", ", @_), $self->child_error); | ||||
| 468 | } | ||||
| 469 | return $r; | ||||
| 470 | } | ||||
| 471 | |||||
| 472 | sub verbose_system | ||||
| 473 | { | ||||
| 474 | my $self = shift; | ||||
| 475 | my @p = @_; | ||||
| 476 | if (ref $p[0]) { | ||||
| 477 | shift @p; | ||||
| 478 | } | ||||
| 479 | if (ref $p[0]) { | ||||
| 480 | shift @p; | ||||
| 481 | } | ||||
| 482 | |||||
| 483 | $self->print("Running #1", join(' ', @p)); | ||||
| 484 | my $r = $self->_system(@_); | ||||
| 485 | if ($r != 0) { | ||||
| 486 | $self->say("... failed: #1", $self->child_error); | ||||
| 487 | } else { | ||||
| 488 | $self->say; | ||||
| 489 | } | ||||
| 490 | } | ||||
| 491 | |||||
| 492 | sub copy_file | ||||
| 493 | { | ||||
| 494 | my $self = shift; | ||||
| 495 | require File::Copy; | ||||
| 496 | |||||
| 497 | my $r = File::Copy::copy(@_); | ||||
| 498 | if (!$r) { | ||||
| 499 | $self->say("copy(#1) failed: #2", join(',', @_), $!); | ||||
| 500 | } | ||||
| 501 | return $r; | ||||
| 502 | } | ||||
| 503 | |||||
| 504 | sub unlink | ||||
| 505 | { | ||||
| 506 | my $self = shift; | ||||
| 507 | my $verbose = shift; | ||||
| 508 | my $r = unlink @_; | ||||
| 509 | if ($r != @_) { | ||||
| 510 | $self->say("rm #1 failed: removed only #2 targets, #3", | ||||
| 511 | join(' ', @_), $r, $!); | ||||
| 512 | } elsif ($verbose) { | ||||
| 513 | $self->say("rm #1", join(' ', @_)); | ||||
| 514 | } | ||||
| 515 | return $r; | ||||
| 516 | } | ||||
| 517 | |||||
| 518 | sub copy | ||||
| 519 | { | ||||
| 520 | my $self = shift; | ||||
| 521 | require File::Copy; | ||||
| 522 | |||||
| 523 | my $r = File::Copy::copy(@_); | ||||
| 524 | if (!$r) { | ||||
| 525 | $self->say("copy(#1) failed: #2", join(',', @_), $!); | ||||
| 526 | } | ||||
| 527 | return $r; | ||||
| 528 | } | ||||
| 529 | |||||
| 530 | 1 | 7µs | 1; | ||
# spent 7µs within OpenBSD::State::CORE:match which was called 5 times, avg 1µs/call:
# once (2µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 134
# once (2µs+0s) by OpenBSD::State::handle_options at line 279
# once (2µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 133
# once (1µs+0s) by OpenBSD::State::handle_options at line 280
# once (900ns+0s) by OpenBSD::State::handle_options at line 283 | |||||
# spent 23µs within OpenBSD::State::CORE:open which was called:
# once (23µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 130 | |||||
# spent 54µs within OpenBSD::State::CORE:print which was called 3 times, avg 18µs/call:
# 3 times (54µs+0s) by OpenBSD::State::_fhprint at line 206, avg 18µs/call | |||||
# spent 18µs within OpenBSD::State::CORE:readline which was called:
# once (18µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 131 | |||||
# spent 24µs within OpenBSD::State::CORE:subst which was called 3 times, avg 8µs/call:
# 3 times (24µs+0s) by OpenBSD::State::f at line 181, avg 8µs/call | |||||
# spent 13µs within OpenBSD::State::CORE:substcont which was called 6 times, avg 2µs/call:
# 6 times (13µs+0s) by OpenBSD::State::f at line 181, avg 2µs/call |