| Filename | /usr/libdata/perl5/OpenBSD/PkgInfo.pm |
| Statements | Executed 141 statements in 5.10ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 4.73ms | 34.3ms | main::BEGIN@22 |
| 1 | 1 | 1 | 1.87ms | 2.09s | OpenBSD::PkgInfo::parse_and_run |
| 1 | 1 | 1 | 1.32ms | 10.0ms | OpenBSD::PkgInfo::State::BEGIN@65 |
| 1 | 1 | 1 | 582µs | 715µs | OpenBSD::PkgInfo::BEGIN@179 |
| 5 | 2 | 1 | 203µs | 797ms | OpenBSD::PkgInfo::find_pkg_in |
| 3 | 1 | 1 | 124µs | 621µs | OpenBSD::PkgInfo::print_info |
| 3 | 1 | 1 | 124µs | 797ms | OpenBSD::PkgInfo::find_pkg |
| 2 | 1 | 1 | 66µs | 66µs | main::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 48µs | 73µs | OpenBSD::PkgInfo::State::hasanyopt |
| 3 | 1 | 1 | 46µs | 667µs | OpenBSD::PkgInfo::__ANON__[:612] |
| 1 | 1 | 1 | 45µs | 45µs | OpenBSD::PkgInfo::CORE:sort (opcode) |
| 1 | 1 | 1 | 38µs | 38µs | main::CORE:pack (opcode) |
| 1 | 1 | 1 | 36µs | 43µs | main::BEGIN@19.1 |
| 2 | 1 | 1 | 23µs | 23µs | main::CORE:match (opcode) |
| 1 | 1 | 1 | 18µs | 33µs | main::BEGIN@20.2 |
| 1 | 1 | 1 | 16µs | 103µs | OpenBSD::PkgInfo::State::lock |
| 1 | 1 | 1 | 12µs | 140µs | OpenBSD::PkgInfo::BEGIN@177 |
| 7 | 2 | 1 | 11µs | 11µs | OpenBSD::PkgInfo::CORE:match (opcode) |
| 1 | 1 | 1 | 10µs | 70µs | OpenBSD::PkgInfo::BEGIN@180 |
| 1 | 1 | 1 | 7µs | 7µs | OpenBSD::PkgInfo::State::setopts |
| 1 | 1 | 1 | 6µs | 6µs | OpenBSD::PkgInfo::BEGIN@178 |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackingElement::FileBase::dump_file |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackingElement::FileObject::hunt_file |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackingElement::dump_file |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackingElement::hunt_file |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackingElement::sum_up |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::banner |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::footer |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::header |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::log |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::print_description |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::printfile |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::State::printfile_sorted |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::__ANON__[:320] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::__ANON__[:339] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::__ANON__[:550] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::__ANON__[:557] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::__ANON__[:670] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::add_to_path_info |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::filter_files |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::find_by_path |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::find_by_spec |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::get_comment |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::get_line |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PkgInfo::manual_filter |
| 0 | 0 | 0 | 0s | 0s | main::RUNTIME |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | #! /usr/bin/perl | ||||
| 2 | # ex:ts=8 sw=4: | ||||
| 3 | # $OpenBSD: PkgInfo.pm,v 1.44 2017/01/25 14:10:46 espie Exp $ | ||||
| 4 | # | ||||
| 5 | # Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org> | ||||
| 6 | # | ||||
| 7 | # Permission to use, copy, modify, and distribute this software for any | ||||
| 8 | # purpose with or without fee is hereby granted, provided that the above | ||||
| 9 | # copyright notice and this permission notice appear in all copies. | ||||
| 10 | # | ||||
| 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
| 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
| 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
| 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
| 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
| 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
| 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
| 18 | |||||
| 19 | 2 | 59µs | 2 | 51µs | # spent 43µs (36+8) within main::BEGIN@19.1 which was called:
# once (36µs+8µs) by main::run at line 19 # spent 43µs making 1 call to main::BEGIN@19.1
# spent 8µs making 1 call to strict::import |
| 20 | 2 | 54µs | 2 | 48µs | # spent 33µs (18+15) within main::BEGIN@20.2 which was called:
# once (18µs+15µs) by main::run at line 20 # spent 33µs making 1 call to main::BEGIN@20.2
# spent 15µs making 1 call to warnings::import |
| 21 | |||||
| 22 | 2 | 413µs | 2 | 34.3ms | # spent 34.3ms (4.73+29.6) within main::BEGIN@22 which was called:
# once (4.73ms+29.6ms) by main::run at line 22 # spent 34.3ms making 1 call to main::BEGIN@22
# spent 30µs making 1 call to Exporter::import |
| 23 | |||||
| 24 | package OpenBSD::PackingElement; | ||||
| 25 | sub dump_file | ||||
| 26 | { | ||||
| 27 | } | ||||
| 28 | |||||
| 29 | sub hunt_file | ||||
| 30 | { | ||||
| 31 | } | ||||
| 32 | |||||
| 33 | sub sum_up | ||||
| 34 | { | ||||
| 35 | my ($self, $rsize) = @_; | ||||
| 36 | if (defined $self->{size}) { | ||||
| 37 | $$rsize += $self->{size}; | ||||
| 38 | } | ||||
| 39 | } | ||||
| 40 | |||||
| 41 | package OpenBSD::PackingElement::FileBase; | ||||
| 42 | sub dump_file | ||||
| 43 | { | ||||
| 44 | my ($item, $opt_K) = @_; | ||||
| 45 | if ($opt_K) { | ||||
| 46 | print '@', $item->keyword, " "; | ||||
| 47 | } | ||||
| 48 | print $item->fullname, "\n"; | ||||
| 49 | } | ||||
| 50 | |||||
| 51 | package OpenBSD::PackingElement::FileObject; | ||||
| 52 | sub hunt_file | ||||
| 53 | { | ||||
| 54 | my ($item, $h, $pkgname, $l) = @_; | ||||
| 55 | my $fname = $item->fullname; | ||||
| 56 | if (defined $h->{$fname}) { | ||||
| 57 | push(@{$h->{$fname}}, $pkgname); | ||||
| 58 | push(@$l, $pkgname); | ||||
| 59 | } | ||||
| 60 | } | ||||
| 61 | |||||
| 62 | package OpenBSD::PkgInfo::State; | ||||
| 63 | 1 | 9µs | our @ISA = qw(OpenBSD::State); | ||
| 64 | |||||
| 65 | 2 | 694µs | 2 | 10.1ms | # spent 10.0ms (1.32+8.70) within OpenBSD::PkgInfo::State::BEGIN@65 which was called:
# once (1.32ms+8.70ms) by main::run at line 65 # spent 10.0ms making 1 call to OpenBSD::PkgInfo::State::BEGIN@65
# spent 125µs making 1 call to Exporter::import |
| 66 | |||||
| 67 | sub lock | ||||
| 68 | # spent 103µs (16+87) within OpenBSD::PkgInfo::State::lock which was called:
# once (16µs+87µs) by OpenBSD::PkgInfo::parse_and_run at line 589 | ||||
| 69 | 1 | 800ns | my $state = shift; | ||
| 70 | 1 | 800ns | return if $state->{locked}; | ||
| 71 | 1 | 2µs | 1 | 2µs | return if $state->{subst}->value('nolock'); # spent 2µs making 1 call to OpenBSD::Subst::value |
| 72 | 1 | 4µs | 2 | 85µs | lock_db(1, $state->opt('q') ? undef : $state); # spent 83µs making 1 call to OpenBSD::PackageInfo::lock_db
# spent 2µs making 1 call to OpenBSD::State::opt |
| 73 | 1 | 4µs | $state->{locked} = 1; | ||
| 74 | } | ||||
| 75 | |||||
| 76 | sub banner | ||||
| 77 | { | ||||
| 78 | my ($state, @args) = @_; | ||||
| 79 | return if $state->opt('q'); | ||||
| 80 | $state->print("#1", $state->opt('l')) if $state->opt('l'); | ||||
| 81 | $state->say(@args); | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | sub header | ||||
| 85 | { | ||||
| 86 | my ($state, $handle) = @_; | ||||
| 87 | return if $state->{terse} || $state->opt('q'); | ||||
| 88 | my $url = $handle->url; | ||||
| 89 | return if $state->{header_done}{$url}; | ||||
| 90 | $state->{header_done}{$url} = 1; | ||||
| 91 | $state->banner("Information for #1\n", $url); | ||||
| 92 | } | ||||
| 93 | |||||
| 94 | sub footer | ||||
| 95 | { | ||||
| 96 | my ($state, $handle) = @_; | ||||
| 97 | return if $state->opt('q') || $state->{terse}; | ||||
| 98 | return unless $state->{header_done}{$handle->url}; | ||||
| 99 | if ($state->opt('l')) { | ||||
| 100 | $state->say("#1", $state->opt('l')); | ||||
| 101 | } else { | ||||
| 102 | $state->say; | ||||
| 103 | } | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | sub printfile | ||||
| 107 | { | ||||
| 108 | my ($state, $filename) = @_; | ||||
| 109 | |||||
| 110 | open my $fh, '<', $filename or return; | ||||
| 111 | while(<$fh>) { | ||||
| 112 | chomp; | ||||
| 113 | $state->say("#1", $_); | ||||
| 114 | } | ||||
| 115 | close $fh; | ||||
| 116 | $state->say; | ||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub printfile_sorted | ||||
| 120 | { | ||||
| 121 | my ($state, $filename) = @_; | ||||
| 122 | |||||
| 123 | open my $fh, '<', $filename or return; | ||||
| 124 | my @lines = (<$fh>); | ||||
| 125 | close $fh; | ||||
| 126 | foreach my $line (sort @lines) { | ||||
| 127 | chomp $line; | ||||
| 128 | $state->say("#1", $line); | ||||
| 129 | } | ||||
| 130 | $state->say; | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | sub print_description | ||||
| 134 | { | ||||
| 135 | my ($state, $dir) = @_; | ||||
| 136 | |||||
| 137 | open my $fh, '<', $dir.DESC or return; | ||||
| 138 | $_ = <$fh>; # zap COMMENT | ||||
| 139 | while(<$fh>) { | ||||
| 140 | chomp; | ||||
| 141 | $state->say("#1", $_); | ||||
| 142 | } | ||||
| 143 | close $fh; | ||||
| 144 | $state->say; | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | sub hasanyopt | ||||
| 148 | # spent 73µs (48+25) within OpenBSD::PkgInfo::State::hasanyopt which was called:
# once (48µs+25µs) by OpenBSD::PkgInfo::parse_and_run at line 593 | ||||
| 149 | 1 | 900ns | my ($self, $string) = @_; | ||
| 150 | 1 | 6µs | for my $i (split //, $string) { | ||
| 151 | 11 | 31µs | 11 | 25µs | if ($self->opt($i)) { # spent 25µs making 11 calls to OpenBSD::State::opt, avg 2µs/call |
| 152 | return 1; | ||||
| 153 | } | ||||
| 154 | } | ||||
| 155 | 1 | 4µs | return 0; | ||
| 156 | } | ||||
| 157 | |||||
| 158 | sub setopts | ||||
| 159 | # spent 7µs within OpenBSD::PkgInfo::State::setopts which was called:
# once (7µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 593 | ||||
| 160 | 1 | 800ns | my ($self, $string) = @_; | ||
| 161 | 1 | 5µs | for my $i (split //, $string) { | ||
| 162 | 2 | 3µs | $self->{opt}{$i} = 1; | ||
| 163 | } | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | sub log | ||||
| 167 | { | ||||
| 168 | my $self = shift; | ||||
| 169 | if (@_ == 0) { | ||||
| 170 | return $self; | ||||
| 171 | } else { | ||||
| 172 | $self->say(@_); | ||||
| 173 | } | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | package OpenBSD::PkgInfo; | ||||
| 177 | 2 | 30µs | 2 | 269µs | # spent 140µs (12+128) within OpenBSD::PkgInfo::BEGIN@177 which was called:
# once (12µs+128µs) by main::run at line 177 # spent 140µs making 1 call to OpenBSD::PkgInfo::BEGIN@177
# spent 128µs making 1 call to Exporter::import |
| 178 | 2 | 22µs | 1 | 6µs | # spent 6µs within OpenBSD::PkgInfo::BEGIN@178 which was called:
# once (6µs+0s) by main::run at line 178 # spent 6µs making 1 call to OpenBSD::PkgInfo::BEGIN@178 |
| 179 | 2 | 157µs | 2 | 750µs | # spent 715µs (582+133) within OpenBSD::PkgInfo::BEGIN@179 which was called:
# once (582µs+133µs) by main::run at line 179 # spent 715µs making 1 call to OpenBSD::PkgInfo::BEGIN@179
# spent 35µs making 1 call to Exporter::import |
| 180 | 2 | 2.67ms | 2 | 131µs | # spent 70µs (10+60) within OpenBSD::PkgInfo::BEGIN@180 which was called:
# once (10µs+60µs) by main::run at line 180 # spent 70µs making 1 call to OpenBSD::PkgInfo::BEGIN@180
# spent 60µs making 1 call to Exporter::import |
| 181 | |||||
| 182 | |||||
| 183 | 1 | 700ns | my $total_size = 0; | ||
| 184 | 1 | 700ns | my $pkgs = 0; | ||
| 185 | |||||
| 186 | sub find_pkg_in | ||||
| 187 | { | ||||
| 188 | 5 | 5µs | my ($self, $state, $repo, $pkgname, $code) = @_; | ||
| 189 | |||||
| 190 | 5 | 30µs | 5 | 73µs | if (OpenBSD::PackageName::is_stem($pkgname)) { # spent 73µs making 5 calls to OpenBSD::PackageName::is_stem, avg 15µs/call |
| 191 | require OpenBSD::Search; | ||||
| 192 | my $l = $repo->match_locations(OpenBSD::Search::Stem->new($pkgname)); | ||||
| 193 | if (@$l != 0) { | ||||
| 194 | for my $pkg (sort {$a->name cmp $b->name} @$l) { | ||||
| 195 | &$code($pkg->name, $pkg); | ||||
| 196 | $pkg->close_now; | ||||
| 197 | $pkg->wipe_info; | ||||
| 198 | } | ||||
| 199 | return 1; | ||||
| 200 | } | ||||
| 201 | } | ||||
| 202 | # okay, so we're actually a spec in disguise | ||||
| 203 | 5 | 25µs | 5 | 8µs | if ($pkgname =~ m/[\*\<\>\=]/) { # spent 8µs making 5 calls to OpenBSD::PkgInfo::CORE:match, avg 2µs/call |
| 204 | require OpenBSD::Search; | ||||
| 205 | my $s = OpenBSD::Search::PkgSpec->new($pkgname); | ||||
| 206 | if (!$s->is_valid) { | ||||
| 207 | $state->errsay("Invalid spec: #1", $pkgname); | ||||
| 208 | return 0; | ||||
| 209 | } | ||||
| 210 | my $r = $repo->match_locations($s); | ||||
| 211 | if (@$r == 0) { | ||||
| 212 | return 0; | ||||
| 213 | } else { | ||||
| 214 | for my $pkg (@$r) { | ||||
| 215 | &$code($pkg->name, $pkg); | ||||
| 216 | $pkg->close_now; | ||||
| 217 | $pkg->wipe_info; | ||||
| 218 | } | ||||
| 219 | return 1; | ||||
| 220 | } | ||||
| 221 | } else { | ||||
| 222 | 5 | 33µs | 5 | 500ms | my $pkg = $repo->find($pkgname); # spent 465ms making 2 calls to OpenBSD::PackageRepositoryFactory::find, avg 233ms/call
# spent 34.7ms making 3 calls to OpenBSD::PackageRepository::Installed::find, avg 11.6ms/call |
| 223 | 5 | 4µs | if (defined $pkg) { | ||
| 224 | 3 | 24µs | 3 | 667µs | &$code($pkgname, $pkg); # spent 667µs making 3 calls to OpenBSD::PkgInfo::__ANON__[OpenBSD/PkgInfo.pm:612], avg 222µs/call |
| 225 | 3 | 22µs | 3 | 289ms | $pkg->close_now; # spent 289ms making 3 calls to OpenBSD::PackageLocation::close_now, avg 96.3ms/call |
| 226 | 3 | 20µs | 3 | 7.46ms | $pkg->wipe_info; # spent 7.46ms making 3 calls to OpenBSD::PackageLocation::wipe_info, avg 2.49ms/call |
| 227 | 3 | 32µs | return 1; | ||
| 228 | } | ||||
| 229 | 2 | 8µs | return 0; | ||
| 230 | } | ||||
| 231 | } | ||||
| 232 | |||||
| 233 | sub find_pkg | ||||
| 234 | # spent 797ms (124µs+797) within OpenBSD::PkgInfo::find_pkg which was called 3 times, avg 266ms/call:
# 3 times (124µs+797ms) by OpenBSD::PkgInfo::parse_and_run at line 612, avg 266ms/call | ||||
| 235 | 3 | 11µs | my ($self, $state, $pkgname, $code) = @_; | ||
| 236 | |||||
| 237 | 3 | 73µs | 9 | 35.2ms | if ($self->find_pkg_in($state, $state->repo->installed, $pkgname, # spent 35.1ms making 3 calls to OpenBSD::PkgInfo::find_pkg_in, avg 11.7ms/call
# spent 79µs making 3 calls to OpenBSD::PackageRepositoryFactory::installed, avg 26µs/call
# spent 23µs making 3 calls to OpenBSD::State::repo, avg 8µs/call |
| 238 | $code)) { | ||||
| 239 | return 1; | ||||
| 240 | } | ||||
| 241 | 2 | 2µs | my $repo; | ||
| 242 | |||||
| 243 | 2 | 10µs | 2 | 2µs | if ($pkgname =~ m/[\/\:]/o) { # spent 2µs making 2 calls to OpenBSD::PkgInfo::CORE:match, avg 1µs/call |
| 244 | ($repo, $pkgname) = $state->repo->path_parse($pkgname); | ||||
| 245 | } else { | ||||
| 246 | 2 | 7µs | 2 | 7µs | $repo = $state->repo; # spent 7µs making 2 calls to OpenBSD::State::repo, avg 3µs/call |
| 247 | } | ||||
| 248 | |||||
| 249 | 2 | 31µs | 2 | 762ms | return $self->find_pkg_in($state, $repo, $pkgname, $code); # spent 762ms making 2 calls to OpenBSD::PkgInfo::find_pkg_in, avg 381ms/call |
| 250 | } | ||||
| 251 | |||||
| 252 | sub get_line | ||||
| 253 | { | ||||
| 254 | open my $fh, '<', shift or return ""; | ||||
| 255 | my $c = <$fh>; | ||||
| 256 | chomp($c); | ||||
| 257 | close $fh; | ||||
| 258 | return $c; | ||||
| 259 | } | ||||
| 260 | |||||
| 261 | sub get_comment | ||||
| 262 | { | ||||
| 263 | my $d = shift; | ||||
| 264 | return get_line($d.DESC); | ||||
| 265 | } | ||||
| 266 | |||||
| 267 | sub find_by_spec | ||||
| 268 | { | ||||
| 269 | my ($pat, $state) = @_; | ||||
| 270 | |||||
| 271 | require OpenBSD::Search; | ||||
| 272 | |||||
| 273 | my $s = OpenBSD::Search::PkgSpec->new($pat); | ||||
| 274 | if (!$s->is_valid) { | ||||
| 275 | $state->errsay("Invalid spec: #1", $pat); | ||||
| 276 | return (); | ||||
| 277 | } else { | ||||
| 278 | my $r = $state->repo->installed->match_locations($s); | ||||
| 279 | |||||
| 280 | return sort {$a->name cmp $b->name} @$r; | ||||
| 281 | } | ||||
| 282 | } | ||||
| 283 | |||||
| 284 | sub filter_files | ||||
| 285 | { | ||||
| 286 | my ($self, $state, $search, @args) = @_; | ||||
| 287 | require OpenBSD::PackingList; | ||||
| 288 | |||||
| 289 | my @k = (); | ||||
| 290 | for my $file (keys %$search) { | ||||
| 291 | my $k = $file; | ||||
| 292 | if ($file =~ m|^.*/(.*?)$|) { | ||||
| 293 | $k = $1; | ||||
| 294 | } | ||||
| 295 | push(@k, quotemeta($k)); | ||||
| 296 | } | ||||
| 297 | my $re = join('|', @k); | ||||
| 298 | |||||
| 299 | my @result = (); | ||||
| 300 | for my $arg (@args) { | ||||
| 301 | $self->find_pkg($state, $arg, | ||||
| 302 | sub { | ||||
| 303 | my ($pkgname, $handle) = @_; | ||||
| 304 | |||||
| 305 | if (-f $handle->info.CONTENTS) { | ||||
| 306 | my $maybe = 0; | ||||
| 307 | open(my $fh, '<', $handle->info.CONTENTS); | ||||
| 308 | while (<$fh>) { | ||||
| 309 | if (m/$re/) { | ||||
| 310 | $maybe = 1; | ||||
| 311 | last; | ||||
| 312 | } | ||||
| 313 | } | ||||
| 314 | close($fh); | ||||
| 315 | return if !$maybe; | ||||
| 316 | } | ||||
| 317 | my $plist = $handle->plist(\&OpenBSD::PackingList::FilesOnly); | ||||
| 318 | |||||
| 319 | $plist->hunt_file($search, $pkgname, \@result); | ||||
| 320 | }); | ||||
| 321 | } | ||||
| 322 | return @result; | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | sub manual_filter | ||||
| 326 | { | ||||
| 327 | my ($self, $state, @args) = @_; | ||||
| 328 | require OpenBSD::PackingList; | ||||
| 329 | |||||
| 330 | my @result = (); | ||||
| 331 | for my $arg (@args) { | ||||
| 332 | $self->find_pkg($state, $arg, | ||||
| 333 | sub { | ||||
| 334 | my ($pkgname, $handle) = @_; | ||||
| 335 | |||||
| 336 | my $plist = $handle->plist(\&OpenBSD::PackingList::ConflictOnly); | ||||
| 337 | |||||
| 338 | push(@result, $pkgname) if $plist->has('manual-installation'); | ||||
| 339 | }); | ||||
| 340 | } | ||||
| 341 | return @result; | ||||
| 342 | } | ||||
| 343 | |||||
| 344 | 1 | 500ns | my $path_info; | ||
| 345 | |||||
| 346 | sub add_to_path_info | ||||
| 347 | { | ||||
| 348 | my ($path, $pkgname) = @_; | ||||
| 349 | |||||
| 350 | push(@{$path_info->{$path}}, $pkgname); | ||||
| 351 | } | ||||
| 352 | |||||
| 353 | sub find_by_path | ||||
| 354 | { | ||||
| 355 | my $pat = shift; | ||||
| 356 | |||||
| 357 | if (!defined $path_info) { | ||||
| 358 | require OpenBSD::PackingList; | ||||
| 359 | |||||
| 360 | $path_info = {}; | ||||
| 361 | for my $pkg (installed_packages(1)) { | ||||
| 362 | my $plist = | ||||
| 363 | OpenBSD::PackingList->from_installation($pkg, | ||||
| 364 | \&OpenBSD::PackingList::ExtraInfoOnly); | ||||
| 365 | next if !defined $plist; | ||||
| 366 | if (defined $plist->fullpkgpath) { | ||||
| 367 | add_to_path_info($plist->fullpkgpath, | ||||
| 368 | $plist->pkgname); | ||||
| 369 | } | ||||
| 370 | if ($plist->has('pkgpath')) { | ||||
| 371 | for my $p (@{$plist->{pkgpath}}) { | ||||
| 372 | add_to_path_info($p->name, | ||||
| 373 | $plist->pkgname); | ||||
| 374 | } | ||||
| 375 | } | ||||
| 376 | } | ||||
| 377 | } | ||||
| 378 | if (defined $path_info->{$pat}) { | ||||
| 379 | return @{$path_info->{$pat}}; | ||||
| 380 | } else { | ||||
| 381 | return (); | ||||
| 382 | } | ||||
| 383 | } | ||||
| 384 | |||||
| 385 | sub print_info | ||||
| 386 | # spent 621µs (124+497) within OpenBSD::PkgInfo::print_info which was called 3 times, avg 207µs/call:
# 3 times (124µs+497µs) by OpenBSD::PkgInfo::__ANON__[/usr/libdata/perl5/OpenBSD/PkgInfo.pm:612] at line 611, avg 207µs/call | ||||
| 387 | 3 | 6µs | my ($self, $state, $pkg, $handle) = @_; | ||
| 388 | 3 | 3µs | unless (defined $handle) { | ||
| 389 | $state->errsay("Error printing info for #1: no info ?", $pkg); | ||||
| 390 | return; | ||||
| 391 | } | ||||
| 392 | 3 | 2µs | my $plist; | ||
| 393 | 3 | 56µs | 6 | 42µs | if ($state->opt('z')) { # spent 42µs making 6 calls to OpenBSD::State::opt, avg 7µs/call |
| 394 | $plist = $handle->plist(\&OpenBSD::PackingList::ExtraInfoOnly); | ||||
| 395 | # firmware don't belong | ||||
| 396 | if ($plist->has('firmware')) { | ||||
| 397 | return; | ||||
| 398 | } | ||||
| 399 | my $name = OpenBSD::PackageName->new_from_string($plist->pkgname); | ||||
| 400 | my $stem = $name->{stem}; | ||||
| 401 | my $compose = $stem."--".join('-', sort keys %{$name->{flavors}}); | ||||
| 402 | if ($plist->has('is-branch')) { | ||||
| 403 | if ($plist->fullpkgpath =~ m/\/([^\/]+?)(,.*)?$/) { | ||||
| 404 | $compose .= "%$1"; | ||||
| 405 | } | ||||
| 406 | } | ||||
| 407 | $state->say("#1", $compose); | ||||
| 408 | } elsif ($state->opt('I')) { | ||||
| 409 | 3 | 44µs | 9 | 456µs | if ($state->opt('Q')) { # spent 310µs making 3 calls to OpenBSD::State::say, avg 104µs/call
# spent 135µs making 3 calls to OpenBSD::PackageInfo::is_installed, avg 45µs/call
# spent 10µs making 3 calls to OpenBSD::State::opt, avg 3µs/call |
| 410 | $state->say( | ||||
| 411 | is_installed($pkg) ? "#1 (installed)" : "#1", $pkg); | ||||
| 412 | } else { | ||||
| 413 | if ($state->opt('q')) { | ||||
| 414 | $state->say("#1", $pkg); | ||||
| 415 | } else { | ||||
| 416 | my $l = 20 - length($pkg); | ||||
| 417 | $l = 1 if $l <= 0; | ||||
| 418 | $state->say("#1#2#3", $pkg, " "x$l, | ||||
| 419 | get_comment($handle->info)); | ||||
| 420 | } | ||||
| 421 | } | ||||
| 422 | } else { | ||||
| 423 | if ($state->opt('c')) { | ||||
| 424 | $state->header($handle); | ||||
| 425 | $state->banner("Comment:"); | ||||
| 426 | $state->say("#1\n", get_comment($handle->info)); | ||||
| 427 | } | ||||
| 428 | if ($state->opt('R') && -f $handle->info.REQUIRED_BY) { | ||||
| 429 | $state->header($handle); | ||||
| 430 | $state->banner("Required by:"); | ||||
| 431 | $state->printfile_sorted($handle->info.REQUIRED_BY); | ||||
| 432 | } | ||||
| 433 | if ($state->opt('d')) { | ||||
| 434 | $state->header($handle); | ||||
| 435 | $state->banner("Description:"); | ||||
| 436 | $state->print_description($handle->info); | ||||
| 437 | } | ||||
| 438 | if ($state->opt('M') && -f $handle->info.DISPLAY) { | ||||
| 439 | $state->header($handle); | ||||
| 440 | $state->banner("Install notice:"); | ||||
| 441 | $state->printfile($handle->info.DISPLAY); | ||||
| 442 | } | ||||
| 443 | if ($state->opt('U') && -f $handle->info.UNDISPLAY) { | ||||
| 444 | $state->header($handle); | ||||
| 445 | $state->banner("Deinstall notice:"); | ||||
| 446 | $state->printfile($handle->info.UNDISPLAY); | ||||
| 447 | } | ||||
| 448 | my $needplist = $state->hasanyopt('fsSC'); | ||||
| 449 | if ($needplist || $state->opt('L')) { | ||||
| 450 | require OpenBSD::PackingList; | ||||
| 451 | |||||
| 452 | if ($needplist) { | ||||
| 453 | $plist //= $handle->plist; | ||||
| 454 | } else { | ||||
| 455 | $plist //= $handle->plist(\&OpenBSD::PackingList::FilesOnly); | ||||
| 456 | } | ||||
| 457 | $state->fatal("bad packing-list for #1", $handle->url) | ||||
| 458 | unless defined $plist; | ||||
| 459 | } | ||||
| 460 | if ($state->opt('L')) { | ||||
| 461 | $state->header($handle); | ||||
| 462 | $state->banner("Files:"); | ||||
| 463 | $plist->dump_file($state->opt('K')); | ||||
| 464 | $state->say; | ||||
| 465 | } | ||||
| 466 | if ($state->opt('C')) { | ||||
| 467 | $state->header($handle); | ||||
| 468 | if ($plist->is_signed) { | ||||
| 469 | my $sig = $plist->get('digital-signature'); | ||||
| 470 | if ($sig->{key} eq 'x509') { | ||||
| 471 | require OpenBSD::x509; | ||||
| 472 | $state->banner("Certificate info:"); | ||||
| 473 | OpenBSD::x509::print_certificate_info($plist); | ||||
| 474 | } elsif ($sig->{key} eq 'signify' || | ||||
| 475 | $sig->{key} eq 'signify2') { | ||||
| 476 | $state->say("reportedly signed by #1", | ||||
| 477 | $plist->get('signer')->name); | ||||
| 478 | } | ||||
| 479 | } else { | ||||
| 480 | $state->banner("No digital signature"); | ||||
| 481 | } | ||||
| 482 | } | ||||
| 483 | if ($state->opt('s')) { | ||||
| 484 | $state->header($handle); | ||||
| 485 | my $size = 0; | ||||
| 486 | $plist->sum_up(\$size); | ||||
| 487 | $state->say( | ||||
| 488 | ($state->opt('q') ? "#1": "Size: #1"), $size); | ||||
| 489 | $total_size += $size; | ||||
| 490 | $pkgs++; | ||||
| 491 | } | ||||
| 492 | if ($state->opt('S')) { | ||||
| 493 | $state->header($handle); | ||||
| 494 | $state->say( | ||||
| 495 | ($state->opt('q') ? "#1": "Signature: #1"), | ||||
| 496 | $plist->signature->string); | ||||
| 497 | } | ||||
| 498 | if ($state->opt('P')) { | ||||
| 499 | require OpenBSD::PackingList; | ||||
| 500 | |||||
| 501 | my $plist = $handle->plist( | ||||
| 502 | \&OpenBSD::PackingList::ExtraInfoOnly); | ||||
| 503 | $state->header($handle); | ||||
| 504 | $state->banner("Pkgpath:"); | ||||
| 505 | if (defined $plist->fullpkgpath) { | ||||
| 506 | $state->say("#1", $plist->fullpkgpath); | ||||
| 507 | } else { | ||||
| 508 | $state->errsay("#1 has no FULLPKGPATH", $plist->pkgname); | ||||
| 509 | $state->say; | ||||
| 510 | } | ||||
| 511 | } | ||||
| 512 | |||||
| 513 | if ($state->opt('f')) { | ||||
| 514 | $state->header($handle); | ||||
| 515 | $state->banner("Packing-list:"); | ||||
| 516 | $plist->write(\*STDOUT); | ||||
| 517 | $state->say; | ||||
| 518 | } | ||||
| 519 | $state->footer($handle); | ||||
| 520 | } | ||||
| 521 | } | ||||
| 522 | |||||
| 523 | sub parse_and_run | ||||
| 524 | # spent 2.09s (1.87ms+2.09) within OpenBSD::PkgInfo::parse_and_run which was called:
# once (1.87ms+2.09s) by main::run at line 30 of /usr/sbin/pkg_info | ||||
| 525 | 1 | 1µs | my ($self, $cmd) = @_; | ||
| 526 | 1 | 600ns | my $exit_code = 0; | ||
| 527 | 1 | 700ns | my @sought_files; | ||
| 528 | 1 | 700ns | my $error_e = 0; | ||
| 529 | 1 | 5µs | 1 | 60µs | my $state = OpenBSD::PkgInfo::State->new($cmd); # spent 60µs making 1 call to OpenBSD::State::new |
| 530 | 1 | 700ns | my @extra; | ||
| 531 | $state->{opt} = | ||||
| 532 | { | ||||
| 533 | 'e' => | ||||
| 534 | sub { | ||||
| 535 | my $pat = shift; | ||||
| 536 | my @list; | ||||
| 537 | if ($pat =~ m/\//o) { | ||||
| 538 | $state->lock; | ||||
| 539 | @list = find_by_path($pat); | ||||
| 540 | push(@ARGV, @list); | ||||
| 541 | } else { | ||||
| 542 | @list = find_by_spec($pat, $state); | ||||
| 543 | push(@extra, @list); | ||||
| 544 | } | ||||
| 545 | if (@list == 0) { | ||||
| 546 | $exit_code = 1; | ||||
| 547 | $error_e = 1; | ||||
| 548 | } | ||||
| 549 | $state->{terse} = 1; | ||||
| 550 | }, | ||||
| 551 | 'E' => | ||||
| 552 | sub { | ||||
| 553 | require File::Spec; | ||||
| 554 | |||||
| 555 | push(@sought_files, File::Spec->rel2abs(shift)); | ||||
| 556 | |||||
| 557 | } | ||||
| 558 | 1 | 6µs | }; | ||
| 559 | 1 | 800ns | $state->{no_exports} = 1; | ||
| 560 | 1 | 4µs | 1 | 323µs | $state->handle_options('cCdfF:hIKLmPQ:qr:RsSUe:E:Ml:aAtz', # spent 323µs making 1 call to OpenBSD::State::handle_options |
| 561 | '[-AaCcdfIKLMmPqRSstUvz] [-D nolock][-E filename] [-e pkg-name] ', | ||||
| 562 | '[-l str] [-Q query] [-r pkgspec] [pkg-name ...]'); | ||||
| 563 | |||||
| 564 | 1 | 2µs | 1 | 3µs | if ($state->opt('r')) { # spent 3µs making 1 call to OpenBSD::State::opt |
| 565 | |||||
| 566 | require OpenBSD::PkgSpec; | ||||
| 567 | |||||
| 568 | my $pattern = $state->opt('r'); | ||||
| 569 | my $s = OpenBSD::PkgSpec->new($pattern); | ||||
| 570 | if (!$s->is_valid) { | ||||
| 571 | $state->errsay("Invalid pkgspec: #1", $pattern); | ||||
| 572 | return 1; | ||||
| 573 | } | ||||
| 574 | my @l = $s->match_ref(\@ARGV); | ||||
| 575 | unless ($state->opt('q')) { | ||||
| 576 | $state->say("Pkgspec #1 matched #2", $pattern, | ||||
| 577 | join(' ', @l)); | ||||
| 578 | } | ||||
| 579 | if (@l == 0) { | ||||
| 580 | $exit_code += 2; | ||||
| 581 | } | ||||
| 582 | if (@extra == 0) { | ||||
| 583 | return $exit_code; | ||||
| 584 | } else { | ||||
| 585 | @ARGV = (); | ||||
| 586 | } | ||||
| 587 | } | ||||
| 588 | |||||
| 589 | 1 | 3µs | 1 | 103µs | $state->lock; # spent 103µs making 1 call to OpenBSD::PkgInfo::State::lock |
| 590 | |||||
| 591 | 1 | 2µs | my $nonames = @ARGV == 0 && @extra == 0; | ||
| 592 | |||||
| 593 | 1 | 6µs | 2 | 80µs | unless ($state->hasanyopt('cMUdfILRsSP') || $state->{terse}) { # spent 73µs making 1 call to OpenBSD::PkgInfo::State::hasanyopt
# spent 7µs making 1 call to OpenBSD::PkgInfo::State::setopts |
| 594 | if ($nonames) { | ||||
| 595 | $state->setopts('Ia'); | ||||
| 596 | } else { | ||||
| 597 | $state->setopts('cdMR'); | ||||
| 598 | } | ||||
| 599 | } | ||||
| 600 | |||||
| 601 | 1 | 2µs | 1 | 3µs | if ($state->opt('Q')) { # spent 3µs making 1 call to OpenBSD::State::opt |
| 602 | 1 | 117µs | require OpenBSD::Search; | ||
| 603 | |||||
| 604 | 1 | 8µs | 1 | 5µs | print "PKG_PATH=$ENV{PKG_PATH}\n" if $state->verbose; # spent 5µs making 1 call to OpenBSD::State::verbose |
| 605 | 1 | 7µs | 2 | 34µs | my $partial = OpenBSD::Search::PartialStem->new($state->opt('Q')); # spent 30µs making 1 call to OpenBSD::Search::Stem::new
# spent 4µs making 1 call to OpenBSD::State::opt |
| 606 | 1 | 10µs | 2 | 1.29s | my $r = $state->repo->match_locations($partial); # spent 1.29s making 1 call to OpenBSD::PackageRepositoryFactory::match_locations
# spent 4µs making 1 call to OpenBSD::State::repo |
| 607 | |||||
| 608 | 4 | 71µs | 4 | 59µs | for my $p (sort map {$_->name} @$r) { # spent 45µs making 1 call to OpenBSD::PkgInfo::CORE:sort
# spent 14µs making 3 calls to OpenBSD::PackageLocation::name, avg 5µs/call |
| 609 | $self->find_pkg($state, $p, | ||||
| 610 | # spent 667µs (46+621) within OpenBSD::PkgInfo::__ANON__[/usr/libdata/perl5/OpenBSD/PkgInfo.pm:612] which was called 3 times, avg 222µs/call:
# 3 times (46µs+621µs) by OpenBSD::PkgInfo::find_pkg_in at line 224, avg 222µs/call | ||||
| 611 | 3 | 51µs | 3 | 621µs | $self->print_info($state, @_); # spent 621µs making 3 calls to OpenBSD::PkgInfo::print_info, avg 207µs/call |
| 612 | 3 | 91µs | 3 | 797ms | }); # spent 797ms making 3 calls to OpenBSD::PkgInfo::find_pkg, avg 266ms/call |
| 613 | } | ||||
| 614 | |||||
| 615 | 1 | 76µs | return 0; | ||
| 616 | } | ||||
| 617 | |||||
| 618 | if ($state->verbose) { | ||||
| 619 | $state->setopts('cdfMURsS'); | ||||
| 620 | } | ||||
| 621 | |||||
| 622 | if ($state->opt('K') && !$state->opt('L')) { | ||||
| 623 | $state->usage("-K only makes sense with -L"); | ||||
| 624 | } | ||||
| 625 | |||||
| 626 | my $all = $state->opt('a') || $state->opt('A'); | ||||
| 627 | |||||
| 628 | if ($nonames && !$all) { | ||||
| 629 | $state->usage("Missing package name(s)") unless $state->{terse} || $state->opt('q'); | ||||
| 630 | } | ||||
| 631 | |||||
| 632 | if (!$nonames && $state->hasanyopt('aAtm')) { | ||||
| 633 | $state->usage("Can't specify package name(s) with [-aAtm]"); | ||||
| 634 | } | ||||
| 635 | |||||
| 636 | |||||
| 637 | if ($nonames && !$error_e) { | ||||
| 638 | @ARGV = sort(installed_packages($state->opt('A') ? 0 : 1)); | ||||
| 639 | if ($state->opt('t')) { | ||||
| 640 | require OpenBSD::RequiredBy; | ||||
| 641 | @ARGV = grep { OpenBSD::RequiredBy->new($_)->list == 0 } @ARGV; | ||||
| 642 | } | ||||
| 643 | } | ||||
| 644 | |||||
| 645 | if (@sought_files) { | ||||
| 646 | my %hash = map { ($_, []) } @sought_files; | ||||
| 647 | @ARGV = $self->filter_files($state, \%hash, @ARGV); | ||||
| 648 | for my $f (@sought_files) { | ||||
| 649 | my $l = $hash{$f}; | ||||
| 650 | if (@$l) { | ||||
| 651 | $state->say("#1: #2", $f, join(',', @$l)) | ||||
| 652 | unless $state->opt('q'); | ||||
| 653 | } else { | ||||
| 654 | $exit_code = 1; | ||||
| 655 | } | ||||
| 656 | } | ||||
| 657 | } | ||||
| 658 | |||||
| 659 | if ($state->opt('m')) { | ||||
| 660 | @ARGV = $self->manual_filter($state, @ARGV); | ||||
| 661 | } | ||||
| 662 | |||||
| 663 | for my $pkg (@ARGV) { | ||||
| 664 | if ($state->{terse}) { | ||||
| 665 | $state->banner('#1', $pkg); | ||||
| 666 | } | ||||
| 667 | if (!$self->find_pkg($state, $pkg, | ||||
| 668 | sub { | ||||
| 669 | $self->print_info($state, @_); | ||||
| 670 | })) { | ||||
| 671 | $exit_code = 1; | ||||
| 672 | } | ||||
| 673 | } | ||||
| 674 | for my $extra (@extra) { | ||||
| 675 | if ($state->{terse}) { | ||||
| 676 | $state->banner('#1', $extra->url); | ||||
| 677 | } | ||||
| 678 | $self->print_info($state, $extra->url, $extra); | ||||
| 679 | } | ||||
| 680 | |||||
| 681 | if ($pkgs > 1) { | ||||
| 682 | $state->say("Total size: #1", $total_size); | ||||
| 683 | } | ||||
| 684 | return $exit_code; | ||||
| 685 | } | ||||
| 686 | |||||
| 687 | 1 | 6µs | 1; | ||
sub OpenBSD::PkgInfo::CORE:match; # opcode | |||||
# spent 45µs within OpenBSD::PkgInfo::CORE:sort which was called:
# once (45µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 608 | |||||
# spent 23µs within main::CORE:match which was called 2 times, avg 12µs/call:
# 2 times (23µs+0s) by main::RUNTIME at line 46 of /usr/sbin/pkg_info, avg 12µs/call | |||||
# spent 38µs within main::CORE:pack which was called:
# once (38µs+0s) by IO::Uncompress::Gunzip::BEGIN@16 at line 145 of IO/Compress/Gzip/Constants.pm | |||||
# spent 66µs within main::CORE:regcomp which was called 2 times, avg 33µs/call:
# 2 times (66µs+0s) by main::RUNTIME at line 46 of /usr/sbin/pkg_info, avg 33µs/call |