| Filename | /usr/libdata/perl5/OpenBSD/State.pm |
| Statements | Executed 1025 statements in 18.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 136 | 8 | 2 | 27.2ms | 27.2ms | OpenBSD::State::opt |
| 1 | 1 | 1 | 16.3ms | 17.9ms | OpenBSD::State::BEGIN@86 |
| 1 | 1 | 1 | 4.76ms | 5.53ms | OpenBSD::State::BEGIN@88 |
| 1 | 1 | 1 | 3.05ms | 3.16ms | OpenBSD::State::BEGIN@87 |
| 40 | 1 | 1 | 1.42ms | 2.21ms | OpenBSD::State::f |
| 40 | 1 | 1 | 1.29ms | 6.20ms | OpenBSD::State::say |
| 1 | 1 | 1 | 940µs | 77.4ms | OpenBSD::State::locator |
| 40 | 1 | 1 | 938µs | 1.86ms | OpenBSD::State::_fhprint |
| 40 | 1 | 1 | 835µs | 4.91ms | OpenBSD::State::fhsay |
| 40 | 1 | 1 | 550µs | 550µs | OpenBSD::State::CORE:print (opcode) |
| 40 | 1 | 1 | 430µs | 430µs | OpenBSD::State::CORE:subst (opcode) |
| 40 | 1 | 1 | 375µs | 375µs | OpenBSD::State::sync_display |
| 160 | 1 | 1 | 361µs | 361µs | OpenBSD::State::CORE:substcont (opcode) |
| 1 | 1 | 1 | 110µs | 585µs | OpenBSD::State::handle_options |
| 1 | 1 | 1 | 81µs | 93µs | OpenBSD::State::init |
| 1 | 1 | 1 | 60µs | 110µs | OpenBSD::State::__ANON__[:137] |
| 1 | 1 | 1 | 52µs | 61µs | main::BEGIN@19.3 |
| 3 | 2 | 2 | 40µs | 62µs | OpenBSD::State::defines |
| 1 | 1 | 1 | 33µs | 87µs | OpenBSD::State::BEGIN@300 |
| 1 | 1 | 1 | 28µs | 69µs | OpenBSD::State::BEGIN@301 |
| 1 | 1 | 1 | 27µs | 2.15s | OpenBSD::PackageRepositoryFactory::match_locations |
| 1 | 1 | 1 | 27µs | 27µs | OpenBSD::State::CORE:open (opcode) |
| 1 | 1 | 1 | 25µs | 119µs | OpenBSD::State::new |
| 1 | 1 | 1 | 24µs | 42µs | main::BEGIN@20.4 |
| 1 | 1 | 1 | 22µs | 423µs | OpenBSD::State::do_options |
| 1 | 1 | 1 | 19µs | 19µs | OpenBSD::State::CORE:readline (opcode) |
| 1 | 1 | 1 | 19µs | 77.5ms | OpenBSD::PackageRepositoryFactory::locator |
| 5 | 5 | 1 | 13µs | 13µs | OpenBSD::State::CORE:match (opcode) |
| 1 | 1 | 1 | 10µs | 360µs | OpenBSD::State::__ANON__[:287] |
| 1 | 1 | 1 | 9µs | 9µs | OpenBSD::State::usage_is |
| 1 | 1 | 1 | 8µs | 368µs | OpenBSD::State::__ANON__[:269] |
| 1 | 1 | 1 | 8µs | 8µs | OpenBSD::State::verbose |
| 1 | 1 | 1 | 7µs | 7µs | OpenBSD::PackageRepositoryFactory::new |
| 1 | 1 | 1 | 4µs | 4µs | OpenBSD::State::repo |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::find |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::grabPlist |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageRepositoryFactory::installed |
| 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 | 85µs | 2 | 71µs | # spent 61µs (52+9) within main::BEGIN@19.3 which was called:
# once (52µs+9µs) by main::BEGIN@22 at line 19 # spent 61µs making 1 call to main::BEGIN@19.3
# spent 9µs making 1 call to strict::import |
| 20 | 2 | 1.25ms | 2 | 61µs | # spent 42µs (24+18) within main::BEGIN@20.4 which was called:
# once (24µs+18µs) by main::BEGIN@22 at line 20 # spent 42µs making 1 call to main::BEGIN@20.4
# spent 18µs making 1 call to warnings::import |
| 21 | |||||
| 22 | package OpenBSD::PackageRepositoryFactory; | ||||
| 23 | sub new | ||||
| 24 | # spent 7µs within OpenBSD::PackageRepositoryFactory::new which was called:
# once (7µs+0s) by OpenBSD::State::init at line 112 | ||||
| 25 | 1 | 1µs | my ($class, $state) = @_; | ||
| 26 | 1 | 37µs | bless {state => $state}, $class; | ||
| 27 | } | ||||
| 28 | |||||
| 29 | sub locator | ||||
| 30 | # spent 77.5ms (19µs+77.4) within OpenBSD::PackageRepositoryFactory::locator which was called:
# once (19µs+77.4ms) by OpenBSD::PackageRepositoryFactory::match_locations at line 65 | ||||
| 31 | 1 | 900ns | my $self = shift; | ||
| 32 | 1 | 17µs | 1 | 77.4ms | return $self->{state}->locator; # spent 77.4ms making 1 call to OpenBSD::State::locator |
| 33 | } | ||||
| 34 | |||||
| 35 | sub installed | ||||
| 36 | { | ||||
| 37 | my ($self, $all) = @_; | ||||
| 38 | require OpenBSD::PackageRepository::Installed; | ||||
| 39 | |||||
| 40 | return OpenBSD::PackageRepository::Installed->new($all, $self->{state}); | ||||
| 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 | { | ||||
| 52 | my ($self, $pkg) = @_; | ||||
| 53 | |||||
| 54 | return $self->locator->find($pkg, $self->{state}); | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | sub reinitialize | ||||
| 58 | { | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub match_locations | ||||
| 62 | # spent 2.15s (27µs+2.15) within OpenBSD::PackageRepositoryFactory::match_locations which was called:
# once (27µs+2.15s) by OpenBSD::PkgInfo::parse_and_run at line 603 of OpenBSD/PkgInfo.pm | ||||
| 63 | 1 | 900ns | my $self = shift; | ||
| 64 | |||||
| 65 | 1 | 25µs | 2 | 2.15s | return $self->locator->match_locations(@_, $self->{state}); # spent 2.07s making 1 call to OpenBSD::PackageLocator::match_locations
# spent 77.5ms 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 | 528µs | 2 | 18.2ms | # spent 17.9ms (16.3+1.53) within OpenBSD::State::BEGIN@86 which was called:
# once (16.3ms+1.53ms) by main::BEGIN@22 at line 86 # spent 17.9ms making 1 call to OpenBSD::State::BEGIN@86
# spent 325µs making 1 call to Exporter::import |
| 87 | 2 | 470µs | 1 | 3.16ms | # spent 3.16ms (3.05+113µs) within OpenBSD::State::BEGIN@87 which was called:
# once (3.05ms+113µs) by main::BEGIN@22 at line 87 # spent 3.16ms making 1 call to OpenBSD::State::BEGIN@87 |
| 88 | 2 | 4.69ms | 2 | 5.75ms | # spent 5.53ms (4.76+769µs) within OpenBSD::State::BEGIN@88 which was called:
# once (4.76ms+769µs) by main::BEGIN@22 at line 88 # spent 5.53ms making 1 call to OpenBSD::State::BEGIN@88
# spent 218µs making 1 call to Exporter::import |
| 89 | 1 | 3µs | require Exporter; | ||
| 90 | 1 | 23µs | our @ISA = qw(Exporter); | ||
| 91 | 1 | 2µs | our @EXPORT = (); | ||
| 92 | |||||
| 93 | sub locator | ||||
| 94 | # spent 77.4ms (940µs+76.5) within OpenBSD::State::locator which was called:
# once (940µs+76.5ms) by OpenBSD::PackageRepositoryFactory::locator at line 32 | ||||
| 95 | 1 | 285µs | require OpenBSD::PackageLocator; | ||
| 96 | 1 | 8µs | return "OpenBSD::PackageLocator"; | ||
| 97 | } | ||||
| 98 | |||||
| 99 | sub new | ||||
| 100 | # spent 119µs (25+93) within OpenBSD::State::new which was called:
# once (25µs+93µs) by OpenBSD::PkgInfo::parse_and_run at line 526 of OpenBSD/PkgInfo.pm | ||||
| 101 | 1 | 2µs | my $class = shift; | ||
| 102 | 1 | 1µs | my $cmd = shift; | ||
| 103 | 1 | 4µs | my $o = bless {cmd => $cmd}, $class; | ||
| 104 | 1 | 10µs | 1 | 93µs | $o->init(@_); # spent 93µs making 1 call to OpenBSD::State::init |
| 105 | 1 | 9µs | return $o; | ||
| 106 | } | ||||
| 107 | |||||
| 108 | sub init | ||||
| 109 | # spent 93µs (81+12) within OpenBSD::State::init which was called:
# once (81µs+12µs) by OpenBSD::State::new at line 104 | ||||
| 110 | 1 | 1µs | my $self = shift; | ||
| 111 | 1 | 27µs | 1 | 5µs | $self->{subst} = OpenBSD::Subst->new; # spent 5µs making 1 call to OpenBSD::Subst::new |
| 112 | 1 | 8µs | 1 | 7µs | $self->{repo} = OpenBSD::PackageRepositoryFactory->new($self); # spent 7µs making 1 call to OpenBSD::PackageRepositoryFactory::new |
| 113 | 1 | 9µs | $self->{export_level} = 1; | ||
| 114 | } | ||||
| 115 | |||||
| 116 | sub repo | ||||
| 117 | # spent 4µs within OpenBSD::State::repo which was called:
# once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 603 of OpenBSD/PkgInfo.pm | ||||
| 118 | 1 | 1µs | my $self = shift; | ||
| 119 | 1 | 13µs | return $self->{repo}; | ||
| 120 | } | ||||
| 121 | |||||
| 122 | sub sync_display | ||||
| 123 | 40 | 240µs | # spent 375µs within OpenBSD::State::sync_display which was called 40 times, avg 9µs/call:
# 40 times (375µs+0s) by OpenBSD::State::_fhprint at line 205, avg 9µs/call | ||
| 124 | } | ||||
| 125 | |||||
| 126 | OpenBSD::Auto::cache(installpath, | ||||
| 127 | # spent 110µs (60+50) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] which was called:
# once (60µs+50µ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 | 42µs | 2 | 28µs | open(my $fh, '<', OpenBSD::Paths->installurl) or return undef; # spent 27µs making 1 call to OpenBSD::State::CORE:open
# spent 1µs making 1 call to OpenBSD::Paths::installurl |
| 131 | 1 | 26µs | 1 | 19µs | while (<$fh>) { # spent 19µs making 1 call to OpenBSD::State::CORE:readline |
| 132 | 1 | 1µs | chomp; | ||
| 133 | 1 | 6µs | 1 | 1µs | next if m/^\s*\#/; # spent 1µ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 | 17µs | 1 | 35µs | }); # spent 35µs making 1 call to OpenBSD::Auto::cache |
| 138 | |||||
| 139 | sub usage_is | ||||
| 140 | # spent 9µs within OpenBSD::State::usage_is which was called:
# once (9µs+0s) by OpenBSD::State::handle_options at line 284 | ||||
| 141 | 1 | 3µs | my ($self, @usage) = @_; | ||
| 142 | 1 | 9µs | $self->{usage} = \@usage; | ||
| 143 | } | ||||
| 144 | |||||
| 145 | sub verbose | ||||
| 146 | # spent 8µs within OpenBSD::State::verbose which was called:
# once (8µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 601 of OpenBSD/PkgInfo.pm | ||||
| 147 | 1 | 2µs | my $self = shift; | ||
| 148 | 1 | 14µs | return $self->{v}; | ||
| 149 | } | ||||
| 150 | |||||
| 151 | sub opt | ||||
| 152 | # spent 27.2ms within OpenBSD::State::opt which was called 136 times, avg 200µs/call:
# 80 times (27.0ms+0s) by OpenBSD::PkgInfo::print_info at line 393 of OpenBSD/PkgInfo.pm, avg 337µs/call
# 40 times (132µs+0s) by OpenBSD::PkgInfo::print_info at line 409 of OpenBSD/PkgInfo.pm, avg 3µs/call
# 11 times (30µs+0s) by OpenBSD::PkgInfo::State::hasanyopt at line 151 of OpenBSD/PkgInfo.pm, avg 3µs/call
# once (6µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 602 of OpenBSD/PkgInfo.pm
# once (5µs+0s) by OpenBSD::State::handle_options at line 288
# once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 561 of OpenBSD/PkgInfo.pm
# once (3µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 598 of OpenBSD/PkgInfo.pm
# once (3µs+0s) by OpenBSD::PkgInfo::State::lock at line 72 of OpenBSD/PkgInfo.pm | ||||
| 153 | 136 | 315µs | my ($self, $k) = @_; | ||
| 154 | 136 | 681µ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 2.21ms (1.42+792µs) within OpenBSD::State::f which was called 40 times, avg 55µs/call:
# 40 times (1.42ms+792µs) by OpenBSD::State::fhsay at line 234, avg 55µs/call | ||||
| 174 | 40 | 41µs | my $self = shift; | ||
| 175 | 40 | 48µs | if (@_ == 0) { | ||
| 176 | return undef; | ||||
| 177 | } | ||||
| 178 | 40 | 256µs | my ($fmt, @l) = @_; | ||
| 179 | # make it so that #0 is # | ||||
| 180 | 40 | 90µs | unshift(@l, '#'); | ||
| 181 | 40 | 1.40ms | 200 | 792µs | $fmt =~ s,\#(\d+),($l[$1] // "<Undefined #$1>"),ge; # spent 430µs making 40 calls to OpenBSD::State::CORE:subst, avg 11µs/call
# spent 361µs making 160 calls to OpenBSD::State::CORE:substcont, avg 2µs/call |
| 182 | 40 | 282µ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 1.86ms (938µs+925µs) within OpenBSD::State::_fhprint which was called 40 times, avg 47µs/call:
# 40 times (938µs+925µs) by OpenBSD::State::fhsay at line 234, avg 47µs/call | ||||
| 203 | 40 | 45µs | my $self = shift; | ||
| 204 | 40 | 35µs | my $fh = shift; | ||
| 205 | 40 | 450µs | 40 | 375µs | $self->sync_display; # spent 375µs making 40 calls to OpenBSD::State::sync_display, avg 9µs/call |
| 206 | 40 | 1.07ms | 40 | 550µs | print $fh @_; # spent 550µs making 40 calls to OpenBSD::State::CORE:print, avg 14µ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 4.91ms (835µs+4.07) within OpenBSD::State::fhsay which was called 40 times, avg 123µs/call:
# 40 times (835µs+4.07ms) by OpenBSD::State::say at line 247, avg 123µs/call | ||||
| 229 | 40 | 38µs | my $self = shift; | ||
| 230 | 40 | 39µs | my $fh = shift; | ||
| 231 | 40 | 333µs | if (@_ == 0) { | ||
| 232 | $self->_fhprint($fh, "\n"); | ||||
| 233 | } else { | ||||
| 234 | 40 | 691µs | 80 | 4.07ms | $self->_fhprint($fh, $self->f(@_), "\n"); # spent 2.21ms making 40 calls to OpenBSD::State::f, avg 55µs/call
# spent 1.86ms making 40 calls to OpenBSD::State::_fhprint, avg 47µs/call |
| 235 | } | ||||
| 236 | } | ||||
| 237 | |||||
| 238 | sub print | ||||
| 239 | { | ||||
| 240 | my $self = shift; | ||||
| 241 | $self->fhprint(\*STDOUT, @_); | ||||
| 242 | } | ||||
| 243 | |||||
| 244 | sub say | ||||
| 245 | # spent 6.20ms (1.29+4.91) within OpenBSD::State::say which was called 40 times, avg 155µs/call:
# 40 times (1.29ms+4.91ms) by OpenBSD::PkgInfo::print_info at line 416 of OpenBSD/PkgInfo.pm, avg 155µs/call | ||||
| 246 | 40 | 45µs | my $self = shift; | ||
| 247 | 40 | 343µs | 40 | 4.91ms | $self->fhsay(\*STDOUT, @_); # spent 4.91ms making 40 calls to OpenBSD::State::fhsay, avg 123µ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 423µs (22+401) within OpenBSD::State::do_options which was called:
# once (22µs+401µs) by OpenBSD::State::handle_options at line 287 | ||||
| 264 | 1 | 2µs | my ($state, $sub) = @_; | ||
| 265 | # this could be nicer... | ||||
| 266 | |||||
| 267 | # spent 368µs (8+360) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] which was called:
# once (8µs+360µs) by OpenBSD::Error::try at line 175 of OpenBSD/Error.pm | ||||
| 268 | 1 | 8µs | 1 | 360µs | &$sub; # spent 360µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:287] |
| 269 | } catchall { | ||||
| 270 | $state->usage("#1", $_); | ||||
| 271 | 1 | 19µs | 2 | 401µs | }; # spent 395µs making 1 call to OpenBSD::Error::try
# spent 6µs making 1 call to OpenBSD::Error::catchall |
| 272 | } | ||||
| 273 | |||||
| 274 | sub handle_options | ||||
| 275 | # spent 585µs (110+475) within OpenBSD::State::handle_options which was called:
# once (110µs+475µs) by OpenBSD::PkgInfo::parse_and_run at line 557 of OpenBSD/PkgInfo.pm | ||||
| 276 | 1 | 3µs | my ($state, $opt_string, @usage) = @_; | ||
| 277 | 1 | 2µs | require OpenBSD::Getopt; | ||
| 278 | |||||
| 279 | 1 | 16µs | 1 | 4µs | $state->{opt}{v} = 0 unless $opt_string =~ m/v/; # spent 4µs making 1 call to OpenBSD::State::CORE:match |
| 280 | 1 | 12µs | 1 | 5µs | $state->{opt}{h} = sub { $state->usage; } unless $opt_string =~ m/h/; # spent 5µs making 1 call to OpenBSD::State::CORE:match |
| 281 | $state->{opt}{D} = sub { | ||||
| 282 | $state->{subst}->parse_option(shift); | ||||
| 283 | 1 | 12µs | 1 | 2µs | } unless $opt_string =~ m/D/; # spent 2µs making 1 call to OpenBSD::State::CORE:match |
| 284 | 1 | 10µs | 1 | 9µs | $state->usage_is(@usage); # spent 9µs making 1 call to OpenBSD::State::usage_is |
| 285 | # spent 360µs (10+349) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:287] which was called:
# once (10µs+349µs) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] at line 268 | ||||
| 286 | 1 | 12µs | 1 | 349µs | OpenBSD::Getopt::getopts($opt_string.'hvD:', $state->{opt}); # spent 349µs making 1 call to OpenBSD::Getopt::getopts |
| 287 | 1 | 26µs | 1 | 423µs | }); # spent 423µs making 1 call to OpenBSD::State::do_options |
| 288 | 1 | 8µs | 1 | 5µs | $state->{v} = $state->opt('v'); # spent 5µs making 1 call to OpenBSD::State::opt |
| 289 | |||||
| 290 | 1 | 10µs | 2 | 28µs | if ($state->defines('unsigned')) { # spent 28µs making 2 calls to OpenBSD::State::defines, avg 14µ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 | 2µs | $state->{signature_style} //= 'new'; | ||
| 296 | } | ||||
| 297 | |||||
| 298 | 1 | 7µs | return if $state->{no_exports}; | ||
| 299 | # XXX | ||||
| 300 | 2 | 140µs | 2 | 140µs | # spent 87µs (33+54) within OpenBSD::State::BEGIN@300 which was called:
# once (33µs+54µs) by main::BEGIN@22 at line 300 # spent 87µs making 1 call to OpenBSD::State::BEGIN@300
# spent 54µs making 1 call to strict::unimport |
| 301 | 2 | 4.27ms | 2 | 110µs | # spent 69µs (28+41) within OpenBSD::State::BEGIN@301 which was called:
# once (28µs+41µs) by main::BEGIN@22 at line 301 # spent 69µs making 1 call to OpenBSD::State::BEGIN@301
# spent 41µ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 62µs (40+22) within OpenBSD::State::defines which was called 3 times, avg 21µs/call:
# 2 times (18µs+10µs) by OpenBSD::State::handle_options at line 290, avg 14µs/call
# once (21µs+12µs) by OpenBSD::PackageRepositoryBase::parse_url at line 73 of OpenBSD/PackageRepository/Installed.pm | ||||
| 312 | 3 | 8µs | my ($self, $k) = @_; | ||
| 313 | 3 | 36µs | 3 | 22µs | return $self->{subst}->value($k); # spent 22µs making 3 calls to OpenBSD::Subst::value, avg 7µ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 | 10µs | 1 | 21µs | }); # spent 21µs making 1 call to OpenBSD::Auto::cache |
| 367 | |||||
| 368 | 1 | 2µs | 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 | 25µs | 1; | ||
# spent 13µs within OpenBSD::State::CORE:match which was called 5 times, avg 3µs/call:
# once (5µs+0s) by OpenBSD::State::handle_options at line 280
# once (4µ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 134
# once (2µs+0s) by OpenBSD::State::handle_options at line 283
# once (1µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 133 | |||||
# spent 27µs within OpenBSD::State::CORE:open which was called:
# once (27µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 130 | |||||
# spent 550µs within OpenBSD::State::CORE:print which was called 40 times, avg 14µs/call:
# 40 times (550µs+0s) by OpenBSD::State::_fhprint at line 206, avg 14µs/call | |||||
# spent 19µs within OpenBSD::State::CORE:readline which was called:
# once (19µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 131 | |||||
# spent 430µs within OpenBSD::State::CORE:subst which was called 40 times, avg 11µs/call:
# 40 times (430µs+0s) by OpenBSD::State::f at line 181, avg 11µs/call | |||||
# spent 361µs within OpenBSD::State::CORE:substcont which was called 160 times, avg 2µs/call:
# 160 times (361µs+0s) by OpenBSD::State::f at line 181, avg 2µs/call |