← Index
NYTProf Performance Profile   « line view »
For /usr/sbin/pkg_info
  Run on Mon Aug 7 09:39:31 2017
Reported on Mon Aug 7 09:40:20 2017

Filename/usr/libdata/perl5/OpenBSD/PkgInfo.pm
StatementsExecuted 952 statements in 130ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11139.8ms15.4sOpenBSD::PkgInfo::::parse_and_run OpenBSD::PkgInfo::parse_and_run
11112.7ms204msOpenBSD::PkgInfo::State::::BEGIN@65 OpenBSD::PkgInfo::State::BEGIN@65
11110.6ms37.5msmain::::BEGIN@22 main::BEGIN@22
40116.70ms10.6msOpenBSD::PkgInfo::::get_line OpenBSD::PkgInfo::get_line
40112.64ms12.0sOpenBSD::PkgInfo::::print_info OpenBSD::PkgInfo::print_info
40112.52ms2.52msOpenBSD::PkgInfo::::CORE:close OpenBSD::PkgInfo::CORE:close (opcode)
1112.31ms3.22msOpenBSD::PkgInfo::::BEGIN@179 OpenBSD::PkgInfo::BEGIN@179
40111.16ms11.8msOpenBSD::PkgInfo::::get_comment OpenBSD::PkgInfo::get_comment
111929µs1.64msOpenBSD::PkgInfo::::CORE:sort OpenBSD::PkgInfo::CORE:sort (opcode)
4011720µs720µsOpenBSD::PkgInfo::::CORE:readline OpenBSD::PkgInfo::CORE:readline (opcode)
4011686µs686µsOpenBSD::PkgInfo::::CORE:open OpenBSD::PkgInfo::CORE:open (opcode)
11165µs65µsmain::::CORE:regcomp main::CORE:regcomp (opcode)
11164µs93µsOpenBSD::PkgInfo::State::::hasanyopt OpenBSD::PkgInfo::State::hasanyopt
11160µs71µsmain::::BEGIN@19.1 main::BEGIN@19.1
11139µs39µsmain::::CORE:pack main::CORE:pack (opcode)
11136µs36µsmain::::CORE:match main::CORE:match (opcode)
11129µs28.7msOpenBSD::PkgInfo::State::::lock OpenBSD::PkgInfo::State::lock
11128µs49µsmain::::BEGIN@20.2 main::BEGIN@20.2
11124µs24µsOpenBSD::PkgInfo::State::::setopts OpenBSD::PkgInfo::State::setopts
11123µs229µsOpenBSD::PkgInfo::::BEGIN@177 OpenBSD::PkgInfo::BEGIN@177
11114µs94µsOpenBSD::PkgInfo::::BEGIN@180 OpenBSD::PkgInfo::BEGIN@180
11110µs10µsOpenBSD::PkgInfo::::BEGIN@178 OpenBSD::PkgInfo::BEGIN@178
0000s0sOpenBSD::PackingElement::FileBase::::dump_file OpenBSD::PackingElement::FileBase::dump_file
0000s0sOpenBSD::PackingElement::FileObject::::hunt_fileOpenBSD::PackingElement::FileObject::hunt_file
0000s0sOpenBSD::PackingElement::::dump_file OpenBSD::PackingElement::dump_file
0000s0sOpenBSD::PackingElement::::hunt_file OpenBSD::PackingElement::hunt_file
0000s0sOpenBSD::PackingElement::::sum_up OpenBSD::PackingElement::sum_up
0000s0sOpenBSD::PkgInfo::State::::banner OpenBSD::PkgInfo::State::banner
0000s0sOpenBSD::PkgInfo::State::::footer OpenBSD::PkgInfo::State::footer
0000s0sOpenBSD::PkgInfo::State::::header OpenBSD::PkgInfo::State::header
0000s0sOpenBSD::PkgInfo::State::::log OpenBSD::PkgInfo::State::log
0000s0sOpenBSD::PkgInfo::State::::print_description OpenBSD::PkgInfo::State::print_description
0000s0sOpenBSD::PkgInfo::State::::printfile OpenBSD::PkgInfo::State::printfile
0000s0sOpenBSD::PkgInfo::State::::printfile_sorted OpenBSD::PkgInfo::State::printfile_sorted
0000s0sOpenBSD::PkgInfo::::__ANON__[:320] OpenBSD::PkgInfo::__ANON__[:320]
0000s0sOpenBSD::PkgInfo::::__ANON__[:339] OpenBSD::PkgInfo::__ANON__[:339]
0000s0sOpenBSD::PkgInfo::::__ANON__[:547] OpenBSD::PkgInfo::__ANON__[:547]
0000s0sOpenBSD::PkgInfo::::__ANON__[:554] OpenBSD::PkgInfo::__ANON__[:554]
0000s0sOpenBSD::PkgInfo::::__ANON__[:666] OpenBSD::PkgInfo::__ANON__[:666]
0000s0sOpenBSD::PkgInfo::::add_to_path_info OpenBSD::PkgInfo::add_to_path_info
0000s0sOpenBSD::PkgInfo::::filter_files OpenBSD::PkgInfo::filter_files
0000s0sOpenBSD::PkgInfo::::find_by_path OpenBSD::PkgInfo::find_by_path
0000s0sOpenBSD::PkgInfo::::find_by_spec OpenBSD::PkgInfo::find_by_spec
0000s0sOpenBSD::PkgInfo::::find_pkg OpenBSD::PkgInfo::find_pkg
0000s0sOpenBSD::PkgInfo::::find_pkg_in OpenBSD::PkgInfo::find_pkg_in
0000s0sOpenBSD::PkgInfo::::manual_filter OpenBSD::PkgInfo::manual_filter
0000s0smain::::RUNTIME main::RUNTIME
Call graph for these subroutines as a Graphviz dot language file.
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.46 2017/08/04 23:35:40 abieber 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
19298µs282µs
# spent 71µs (60+11) within main::BEGIN@19.1 which was called: # once (60µs+11µs) by main::run at line 19
use strict;
# spent 71µs making 1 call to main::BEGIN@19.1 # spent 11µs making 1 call to strict::import
20281µs271µs
# spent 49µs (28+22) within main::BEGIN@20.2 which was called: # once (28µs+22µs) by main::run at line 20
use warnings;
# spent 49µs making 1 call to main::BEGIN@20.2 # spent 22µs making 1 call to warnings::import
21
2221.07ms237.6ms
# spent 37.5ms (10.6+26.9) within main::BEGIN@22 which was called: # once (10.6ms+26.9ms) by main::run at line 22
use OpenBSD::State;
# spent 37.5ms making 1 call to main::BEGIN@22 # spent 66µs making 1 call to Exporter::import
23
24package OpenBSD::PackingElement;
25sub dump_file
26{
27}
28
29sub hunt_file
30{
31}
32
33sub sum_up
34{
35 my ($self, $rsize) = @_;
36 if (defined $self->{size}) {
37 $$rsize += $self->{size};
38 }
39}
40
41package OpenBSD::PackingElement::FileBase;
42sub dump_file
43{
44 my ($item, $opt_K) = @_;
45 if ($opt_K) {
46 print '@', $item->keyword, " ";
47 }
48 print $item->fullname, "\n";
49}
50
51package OpenBSD::PackingElement::FileObject;
52sub 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
62package OpenBSD::PkgInfo::State;
63120µsour @ISA = qw(OpenBSD::State);
64
65230.2ms2204ms
# spent 204ms (12.7+191) within OpenBSD::PkgInfo::State::BEGIN@65 which was called: # once (12.7ms+191ms) by main::run at line 65
use OpenBSD::PackageInfo;
# spent 204ms making 1 call to OpenBSD::PkgInfo::State::BEGIN@65 # spent 205µs making 1 call to Exporter::import
66
67sub lock
68
# spent 28.7ms (29µs+28.7) within OpenBSD::PkgInfo::State::lock which was called: # once (29µs+28.7ms) by OpenBSD::PkgInfo::parse_and_run at line 586
{
6911µs my $state = shift;
7011µs return if $state->{locked};
7114µs13µs return if $state->{subst}->value('nolock');
# spent 3µs making 1 call to OpenBSD::Subst::value
7218µs228.7ms lock_db(1, $state->opt('q') ? undef : $state);
# spent 28.7ms making 1 call to OpenBSD::PackageInfo::lock_db # spent 3µs making 1 call to OpenBSD::State::opt
73110µs $state->{locked} = 1;
74}
75
76sub 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
84sub 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
94sub 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
106sub 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
119sub 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
133sub 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
147sub hasanyopt
148
# spent 93µs (64+30) within OpenBSD::PkgInfo::State::hasanyopt which was called: # once (64µs+30µs) by OpenBSD::PkgInfo::parse_and_run at line 590
{
14912µs my ($self, $string) = @_;
150112µs for my $i (split //, $string) {
1511134µs1130µs if ($self->opt($i)) {
# spent 30µs making 11 calls to OpenBSD::State::opt, avg 3µs/call
152 return 1;
153 }
154 }
15516µs return 0;
156}
157
158sub setopts
159
# spent 24µs within OpenBSD::PkgInfo::State::setopts which was called: # once (24µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 590
{
16011µs my ($self, $string) = @_;
16116µs for my $i (split //, $string) {
162218µs $self->{opt}{$i} = 1;
163 }
164}
165
166sub log
167{
168 my $self = shift;
169 if (@_ == 0) {
170 return $self;
171 } else {
172 $self->say(@_);
173 }
174}
175
176package OpenBSD::PkgInfo;
177269µs2434µs
# spent 229µs (23+206) within OpenBSD::PkgInfo::BEGIN@177 which was called: # once (23µs+206µs) by main::run at line 177
use OpenBSD::PackageInfo;
# spent 229µs making 1 call to OpenBSD::PkgInfo::BEGIN@177 # spent 206µs making 1 call to Exporter::import
178278µs110µs
# spent 10µs within OpenBSD::PkgInfo::BEGIN@178 which was called: # once (10µs+0s) by main::run at line 178
use OpenBSD::PackageName;
# spent 10µs making 1 call to OpenBSD::PkgInfo::BEGIN@178
17921.02ms23.28ms
# spent 3.22ms (2.31+906µs) within OpenBSD::PkgInfo::BEGIN@179 which was called: # once (2.31ms+906µs) by main::run at line 179
use OpenBSD::Getopt;
# spent 3.22ms making 1 call to OpenBSD::PkgInfo::BEGIN@179 # spent 58µs making 1 call to Exporter::import
180253.3ms2174µs
# spent 94µs (14+80) within OpenBSD::PkgInfo::BEGIN@180 which was called: # once (14µs+80µs) by main::run at line 180
use OpenBSD::Error;
# spent 94µs making 1 call to OpenBSD::PkgInfo::BEGIN@180 # spent 80µs making 1 call to Exporter::import
181
182
18311µsmy $total_size = 0;
1841700nsmy $pkgs = 0;
185
186sub find_pkg_in
187{
188 my ($self, $state, $repo, $pkgname, $code) = @_;
189
190 if (OpenBSD::PackageName::is_stem($pkgname)) {
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 if ($pkgname =~ m/[\*\<\>\=]/) {
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 my $pkg = $repo->find($pkgname);
223 if (defined $pkg) {
224 &$code($pkgname, $pkg);
225 $pkg->close_now;
226 $pkg->wipe_info;
227 return 1;
228 }
229 return 0;
230 }
231}
232
233sub find_pkg
234{
235 my ($self, $state, $pkgname, $code) = @_;
236
237 if ($self->find_pkg_in($state, $state->repo->installed, $pkgname,
238 $code)) {
239 return 1;
240 }
241 my $repo;
242
243 if ($pkgname =~ m/[\/\:]/o) {
244 ($repo, $pkgname) = $state->repo->path_parse($pkgname);
245 } else {
246 $repo = $state->repo;
247 }
248
249 return $self->find_pkg_in($state, $repo, $pkgname, $code);
250}
251
252sub get_line
253
# spent 10.6ms (6.70+3.92) within OpenBSD::PkgInfo::get_line which was called 40 times, avg 266µs/call: # 40 times (6.70ms+3.92ms) by OpenBSD::PkgInfo::get_comment at line 264, avg 266µs/call
{
254406.74ms40686µs open my $fh, '<', shift or return "";
# spent 686µs making 40 calls to OpenBSD::PkgInfo::CORE:open, avg 17µs/call
25540898µs40720µs my $c = <$fh>;
# spent 720µs making 40 calls to OpenBSD::PkgInfo::CORE:readline, avg 18µs/call
2564058µs chomp($c);
257402.67ms402.52ms close $fh;
# spent 2.52ms making 40 calls to OpenBSD::PkgInfo::CORE:close, avg 63µs/call
25840292µs return $c;
259}
260
261sub get_comment
262
# spent 11.8ms (1.16+10.6) within OpenBSD::PkgInfo::get_comment which was called 40 times, avg 295µs/call: # 40 times (1.16ms+10.6ms) by OpenBSD::PkgInfo::print_info at line 416, avg 295µs/call
{
2634044µs my $d = shift;
26440327µs4010.6ms return get_line($d.DESC);
# spent 10.6ms making 40 calls to OpenBSD::PkgInfo::get_line, avg 266µs/call
265}
266
267sub 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
284sub 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
325sub 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
3441800nsmy $path_info;
345
346sub add_to_path_info
347{
348 my ($path, $pkgname) = @_;
349
350 push(@{$path_info->{$path}}, $pkgname);
351}
352
353sub 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
385sub print_info
386
# spent 12.0s (2.64ms+12.0) within OpenBSD::PkgInfo::print_info which was called 40 times, avg 300ms/call: # 40 times (2.64ms+12.0s) by OpenBSD::PkgInfo::parse_and_run at line 606, avg 300ms/call
{
3874070µs my ($self, $state, $pkg, $handle) = @_;
3884044µs unless (defined $handle) {
389 $state->errsay("Error printing info for #1: no info ?", $pkg);
390 return;
391 }
3924039µs my $plist;
3934027.5ms8027.0ms if ($state->opt('z')) {
# spent 27.0ms making 80 calls to OpenBSD::State::opt, avg 337µ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')) {
40940164µs40132µs if ($state->opt('q')) {
# spent 132µs making 40 calls to OpenBSD::State::opt, avg 3µs/call
410 $state->say("#1#2", $pkg,
411 $state->opt('Q') && is_installed($pkg) ?
412 " (installed)" : "");
413 } else {
4144072µs my $l = 20 - length($pkg);
4154044µs $l = 1 if $l <= 0;
416402.09ms12012.0s $state->say("#1#2#3", $pkg, " "x$l,
# spent 12.0s making 40 calls to OpenBSD::PackageLocation::info, avg 299ms/call # spent 11.8ms making 40 calls to OpenBSD::PkgInfo::get_comment, avg 295µs/call # spent 6.20ms making 40 calls to OpenBSD::State::say, avg 155µs/call
417 get_comment($handle->info));
418 }
419 } else {
420 if ($state->opt('c')) {
421 $state->header($handle);
422 $state->banner("Comment:");
423 $state->say("#1\n", get_comment($handle->info));
424 }
425 if ($state->opt('R') && -f $handle->info.REQUIRED_BY) {
426 $state->header($handle);
427 $state->banner("Required by:");
428 $state->printfile_sorted($handle->info.REQUIRED_BY);
429 }
430 if ($state->opt('d')) {
431 $state->header($handle);
432 $state->banner("Description:");
433 $state->print_description($handle->info);
434 }
435 if ($state->opt('M') && -f $handle->info.DISPLAY) {
436 $state->header($handle);
437 $state->banner("Install notice:");
438 $state->printfile($handle->info.DISPLAY);
439 }
440 if ($state->opt('U') && -f $handle->info.UNDISPLAY) {
441 $state->header($handle);
442 $state->banner("Deinstall notice:");
443 $state->printfile($handle->info.UNDISPLAY);
444 }
445 my $needplist = $state->hasanyopt('fsSC');
446 if ($needplist || $state->opt('L')) {
447 require OpenBSD::PackingList;
448
449 if ($needplist) {
450 $plist //= $handle->plist;
451 } else {
452 $plist //= $handle->plist(\&OpenBSD::PackingList::FilesOnly);
453 }
454 $state->fatal("bad packing-list for #1", $handle->url)
455 unless defined $plist;
456 }
457 if ($state->opt('L')) {
458 $state->header($handle);
459 $state->banner("Files:");
460 $plist->dump_file($state->opt('K'));
461 $state->say;
462 }
463 if ($state->opt('C')) {
464 $state->header($handle);
465 if ($plist->is_signed) {
466 my $sig = $plist->get('digital-signature');
467 if ($sig->{key} eq 'x509') {
468 require OpenBSD::x509;
469 $state->banner("Certificate info:");
470 OpenBSD::x509::print_certificate_info($plist);
471 } elsif ($sig->{key} eq 'signify' ||
472 $sig->{key} eq 'signify2') {
473 $state->say("reportedly signed by #1",
474 $plist->get('signer')->name);
475 }
476 } else {
477 $state->banner("No digital signature");
478 }
479 }
480 if ($state->opt('s')) {
481 $state->header($handle);
482 my $size = 0;
483 $plist->sum_up(\$size);
484 $state->say(
485 ($state->opt('q') ? "#1": "Size: #1"), $size);
486 $total_size += $size;
487 $pkgs++;
488 }
489 if ($state->opt('S')) {
490 $state->header($handle);
491 $state->say(
492 ($state->opt('q') ? "#1": "Signature: #1"),
493 $plist->signature->string);
494 }
495 if ($state->opt('P')) {
496 require OpenBSD::PackingList;
497
498 my $plist = $handle->plist(
499 \&OpenBSD::PackingList::ExtraInfoOnly);
500 $state->header($handle);
501 $state->banner("Pkgpath:");
502 if (defined $plist->fullpkgpath) {
503 $state->say("#1", $plist->fullpkgpath);
504 } else {
505 $state->errsay("#1 has no FULLPKGPATH", $plist->pkgname);
506 $state->say;
507 }
508 }
509
510 if ($state->opt('f')) {
511 $state->header($handle);
512 $state->banner("Packing-list:");
513 $plist->write(\*STDOUT);
514 $state->say;
515 }
516 $state->footer($handle);
517 }
518}
519
520sub parse_and_run
521
# spent 15.4s (39.8ms+15.3) within OpenBSD::PkgInfo::parse_and_run which was called: # once (39.8ms+15.3s) by main::run at line 30 of /usr/sbin/pkg_info
{
52212µs my ($self, $cmd) = @_;
5231800ns my $exit_code = 0;
5241900ns my @sought_files;
5251700ns my $error_e = 0;
526110µs1119µs my $state = OpenBSD::PkgInfo::State->new($cmd);
# spent 119µs making 1 call to OpenBSD::State::new
5271800ns my @extra;
528 $state->{opt} =
529 {
530 'e' =>
531 sub {
532 my $pat = shift;
533 my @list;
534 if ($pat =~ m/\//o) {
535 $state->lock;
536 @list = find_by_path($pat);
537 push(@ARGV, @list);
538 } else {
539 @list = find_by_spec($pat, $state);
540 push(@extra, @list);
541 }
542 if (@list == 0) {
543 $exit_code = 1;
544 $error_e = 1;
545 }
546 $state->{terse} = 1;
547 },
548 'E' =>
549 sub {
550 require File::Spec;
551
552 push(@sought_files, File::Spec->rel2abs(shift));
553
554 }
555113µs };
5561900ns $state->{no_exports} = 1;
55719µs1585µs $state->handle_options('cCdfF:hIKLmPQ:qr:RsSUe:E:Ml:aAtz',
# spent 585µs making 1 call to OpenBSD::State::handle_options
558 '[-AaCcdfIKLMmPqRSstUvz] [-D nolock][-E filename] [-e pkg-name] ',
559 '[-l str] [-Q query] [-r pkgspec] [pkg-name ...]');
560
56114µs14µs if ($state->opt('r')) {
# spent 4µs making 1 call to OpenBSD::State::opt
562
563 require OpenBSD::PkgSpec;
564
565 my $pattern = $state->opt('r');
566 my $s = OpenBSD::PkgSpec->new($pattern);
567 if (!$s->is_valid) {
568 $state->errsay("Invalid pkgspec: #1", $pattern);
569 return 1;
570 }
571 my @l = $s->match_ref(\@ARGV);
572 unless ($state->opt('q')) {
573 $state->say("Pkgspec #1 matched #2", $pattern,
574 join(' ', @l));
575 }
576 if (@l == 0) {
577 $exit_code += 2;
578 }
579 if (@extra == 0) {
580 return $exit_code;
581 } else {
582 @ARGV = ();
583 }
584 }
585
58614µs128.7ms $state->lock;
# spent 28.7ms making 1 call to OpenBSD::PkgInfo::State::lock
587
58814µs my $nonames = @ARGV == 0 && @extra == 0;
589
590110µs2117µs unless ($state->hasanyopt('cMUdfILRsSP') || $state->{terse}) {
# spent 93µs making 1 call to OpenBSD::PkgInfo::State::hasanyopt # spent 24µs making 1 call to OpenBSD::PkgInfo::State::setopts
591 if ($nonames) {
592 $state->setopts('Ia');
593 } else {
594 $state->setopts('cdMR');
595 }
596 }
597
59813µs13µs if ($state->opt('Q')) {
# spent 3µs making 1 call to OpenBSD::State::opt
5991230µs require OpenBSD::Search;
600
601114µs18µs $state->say("PKG_PATH=#1", $ENV{PKG_PATH}) if $state->verbose;
# spent 8µs making 1 call to OpenBSD::State::verbose
60219µs245µs my $partial = OpenBSD::Search::PartialStem->new($state->opt('Q'));
# spent 39µs making 1 call to OpenBSD::Search::Stem::new # spent 6µs making 1 call to OpenBSD::State::opt
603112µs22.15s my $r = $state->repo->match_locations($partial);
# spent 2.15s making 1 call to OpenBSD::PackageRepositoryFactory::match_locations # spent 4µs making 1 call to OpenBSD::State::repo
604
605169692µs3372.36ms for my $pkg (sort {$a->name cmp $b->name} @$r) {
# spent 1.64ms making 1 call to OpenBSD::PkgInfo::CORE:sort # spent 715µs making 336 calls to OpenBSD::PackageLocation::name, avg 2µs/call
606401.16ms8012.0s $self->print_info($state, $pkg->name, $pkg);
# spent 12.0s making 40 calls to OpenBSD::PkgInfo::print_info, avg 300ms/call # spent 227µs making 40 calls to OpenBSD::PackageLocation::name, avg 6µs/call
60740308µs401.08s $pkg->close_now;
# spent 1.08s making 40 calls to OpenBSD::PackageLocation::close_now, avg 27.0ms/call
60840383µs4054.9ms $pkg->wipe_info;
# spent 54.9ms making 40 calls to OpenBSD::PackageLocation::wipe_info, avg 1.37ms/call
609 }
610
6111180µs return 0;
612 }
613
614 if ($state->verbose) {
615 $state->setopts('cdfMURsS');
616 }
617
618 if ($state->opt('K') && !$state->opt('L')) {
619 $state->usage("-K only makes sense with -L");
620 }
621
622 my $all = $state->opt('a') || $state->opt('A');
623
624 if ($nonames && !$all) {
625 $state->usage("Missing package name(s)") unless $state->{terse} || $state->opt('q');
626 }
627
628 if (!$nonames && $state->hasanyopt('aAtm')) {
629 $state->usage("Can't specify package name(s) with [-aAtm]");
630 }
631
632
633 if ($nonames && !$error_e) {
634 @ARGV = sort(installed_packages($state->opt('A') ? 0 : 1));
635 if ($state->opt('t')) {
636 require OpenBSD::RequiredBy;
637 @ARGV = grep { OpenBSD::RequiredBy->new($_)->list == 0 } @ARGV;
638 }
639 }
640
641 if (@sought_files) {
642 my %hash = map { ($_, []) } @sought_files;
643 @ARGV = $self->filter_files($state, \%hash, @ARGV);
644 for my $f (@sought_files) {
645 my $l = $hash{$f};
646 if (@$l) {
647 $state->say("#1: #2", $f, join(',', @$l))
648 unless $state->opt('q');
649 } else {
650 $exit_code = 1;
651 }
652 }
653 }
654
655 if ($state->opt('m')) {
656 @ARGV = $self->manual_filter($state, @ARGV);
657 }
658
659 for my $pkg (@ARGV) {
660 if ($state->{terse}) {
661 $state->banner('#1', $pkg);
662 }
663 if (!$self->find_pkg($state, $pkg,
664 sub {
665 $self->print_info($state, @_);
666 })) {
667 $exit_code = 1;
668 }
669 }
670 for my $extra (@extra) {
671 if ($state->{terse}) {
672 $state->banner('#1', $extra->url);
673 }
674 $self->print_info($state, $extra->url, $extra);
675 }
676
677 if ($pkgs > 1) {
678 $state->say("Total size: #1", $total_size);
679 }
680 return $exit_code;
681}
682
683112µs1;
 
# spent 2.52ms within OpenBSD::PkgInfo::CORE:close which was called 40 times, avg 63µs/call: # 40 times (2.52ms+0s) by OpenBSD::PkgInfo::get_line at line 257, avg 63µs/call
sub OpenBSD::PkgInfo::CORE:close; # opcode
# spent 686µs within OpenBSD::PkgInfo::CORE:open which was called 40 times, avg 17µs/call: # 40 times (686µs+0s) by OpenBSD::PkgInfo::get_line at line 254, avg 17µs/call
sub OpenBSD::PkgInfo::CORE:open; # opcode
# spent 720µs within OpenBSD::PkgInfo::CORE:readline which was called 40 times, avg 18µs/call: # 40 times (720µs+0s) by OpenBSD::PkgInfo::get_line at line 255, avg 18µs/call
sub OpenBSD::PkgInfo::CORE:readline; # opcode
# spent 1.64ms (929µs+715µs) within OpenBSD::PkgInfo::CORE:sort which was called: # once (929µs+715µs) by OpenBSD::PkgInfo::parse_and_run at line 605
sub OpenBSD::PkgInfo::CORE:sort; # opcode
# spent 36µs within main::CORE:match which was called: # once (36µs+0s) by main::RUNTIME at line 46 of /usr/sbin/pkg_info
sub main::CORE:match; # opcode
# spent 39µs within main::CORE:pack which was called: # once (39µs+0s) by IO::Uncompress::Gunzip::BEGIN@16 at line 145 of IO/Compress/Gzip/Constants.pm
sub main::CORE:pack; # opcode
# spent 65µs within main::CORE:regcomp which was called: # once (65µs+0s) by main::RUNTIME at line 46 of /usr/sbin/pkg_info
sub main::CORE:regcomp; # opcode