← 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/State.pm
StatementsExecuted 1025 statements in 18.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1368227.2ms27.2msOpenBSD::State::::opt OpenBSD::State::opt
11116.3ms17.9msOpenBSD::State::::BEGIN@86 OpenBSD::State::BEGIN@86
1114.76ms5.53msOpenBSD::State::::BEGIN@88 OpenBSD::State::BEGIN@88
1113.05ms3.16msOpenBSD::State::::BEGIN@87 OpenBSD::State::BEGIN@87
40111.42ms2.21msOpenBSD::State::::f OpenBSD::State::f
40111.29ms6.20msOpenBSD::State::::say OpenBSD::State::say
111940µs77.4msOpenBSD::State::::locator OpenBSD::State::locator
4011938µs1.86msOpenBSD::State::::_fhprint OpenBSD::State::_fhprint
4011835µs4.91msOpenBSD::State::::fhsay OpenBSD::State::fhsay
4011550µs550µsOpenBSD::State::::CORE:print OpenBSD::State::CORE:print (opcode)
4011430µs430µsOpenBSD::State::::CORE:subst OpenBSD::State::CORE:subst (opcode)
4011375µs375µsOpenBSD::State::::sync_display OpenBSD::State::sync_display
16011361µs361µsOpenBSD::State::::CORE:substcont OpenBSD::State::CORE:substcont (opcode)
111110µs585µsOpenBSD::State::::handle_options OpenBSD::State::handle_options
11181µs93µsOpenBSD::State::::init OpenBSD::State::init
11160µs110µsOpenBSD::State::::__ANON__[:137] OpenBSD::State::__ANON__[:137]
11152µs61µsmain::::BEGIN@19.3 main::BEGIN@19.3
32240µs62µsOpenBSD::State::::defines OpenBSD::State::defines
11133µs87µsOpenBSD::State::::BEGIN@300 OpenBSD::State::BEGIN@300
11128µs69µsOpenBSD::State::::BEGIN@301 OpenBSD::State::BEGIN@301
11127µs2.15sOpenBSD::PackageRepositoryFactory::::match_locationsOpenBSD::PackageRepositoryFactory::match_locations
11127µs27µsOpenBSD::State::::CORE:open OpenBSD::State::CORE:open (opcode)
11125µs119µsOpenBSD::State::::new OpenBSD::State::new
11124µs42µsmain::::BEGIN@20.4 main::BEGIN@20.4
11122µs423µsOpenBSD::State::::do_options OpenBSD::State::do_options
11119µs19µsOpenBSD::State::::CORE:readline OpenBSD::State::CORE:readline (opcode)
11119µs77.5msOpenBSD::PackageRepositoryFactory::::locatorOpenBSD::PackageRepositoryFactory::locator
55113µs13µsOpenBSD::State::::CORE:match OpenBSD::State::CORE:match (opcode)
11110µs360µsOpenBSD::State::::__ANON__[:287] OpenBSD::State::__ANON__[:287]
1119µs9µsOpenBSD::State::::usage_is OpenBSD::State::usage_is
1118µs368µsOpenBSD::State::::__ANON__[:269] OpenBSD::State::__ANON__[:269]
1118µs8µsOpenBSD::State::::verbose OpenBSD::State::verbose
1117µs7µsOpenBSD::PackageRepositoryFactory::::newOpenBSD::PackageRepositoryFactory::new
1114µs4µsOpenBSD::State::::repo OpenBSD::State::repo
0000s0sOpenBSD::PackageRepositoryFactory::::findOpenBSD::PackageRepositoryFactory::find
0000s0sOpenBSD::PackageRepositoryFactory::::grabPlistOpenBSD::PackageRepositoryFactory::grabPlist
0000s0sOpenBSD::PackageRepositoryFactory::::installedOpenBSD::PackageRepositoryFactory::installed
0000s0sOpenBSD::PackageRepositoryFactory::::pathOpenBSD::PackageRepositoryFactory::path
0000s0sOpenBSD::PackageRepositoryFactory::::path_parseOpenBSD::PackageRepositoryFactory::path_parse
0000s0sOpenBSD::PackageRepositoryFactory::::reinitializeOpenBSD::PackageRepositoryFactory::reinitialize
0000s0sOpenBSD::State::::__ANON__[:271] OpenBSD::State::__ANON__[:271]
0000s0sOpenBSD::State::::__ANON__[:280] OpenBSD::State::__ANON__[:280]
0000s0sOpenBSD::State::::__ANON__[:283] OpenBSD::State::__ANON__[:283]
0000s0sOpenBSD::State::::__ANON__[:347] OpenBSD::State::__ANON__[:347]
0000s0sOpenBSD::State::::__ANON__[:351] OpenBSD::State::__ANON__[:351]
0000s0sOpenBSD::State::::__ANON__[:366] OpenBSD::State::__ANON__[:366]
0000s0sOpenBSD::State::::__ANON__[:436] OpenBSD::State::__ANON__[:436]
0000s0sOpenBSD::State::::__ANON__[:441] OpenBSD::State::__ANON__[:441]
0000s0sOpenBSD::State::::_errprint OpenBSD::State::_errprint
0000s0sOpenBSD::State::::_fatal OpenBSD::State::_fatal
0000s0sOpenBSD::State::::_print OpenBSD::State::_print
0000s0sOpenBSD::State::::_system OpenBSD::State::_system
0000s0sOpenBSD::State::::child_error OpenBSD::State::child_error
0000s0sOpenBSD::State::::copy OpenBSD::State::copy
0000s0sOpenBSD::State::::copy_file OpenBSD::State::copy_file
0000s0sOpenBSD::State::::errprint OpenBSD::State::errprint
0000s0sOpenBSD::State::::errsay OpenBSD::State::errsay
0000s0sOpenBSD::State::::fatal OpenBSD::State::fatal
0000s0sOpenBSD::State::::fhprint OpenBSD::State::fhprint
0000s0sOpenBSD::State::::fillup_names OpenBSD::State::fillup_names
0000s0sOpenBSD::State::::find_signal OpenBSD::State::find_signal
0000s0sOpenBSD::State::::find_window_size OpenBSD::State::find_window_size
0000s0sOpenBSD::State::::height OpenBSD::State::height
0000s0sOpenBSD::State::::print OpenBSD::State::print
0000s0sOpenBSD::State::::system OpenBSD::State::system
0000s0sOpenBSD::State::::unlink OpenBSD::State::unlink
0000s0sOpenBSD::State::::usage OpenBSD::State::usage
0000s0sOpenBSD::State::::verbose_system OpenBSD::State::verbose_system
0000s0sOpenBSD::State::::width OpenBSD::State::width
Call graph for these subroutines as a Graphviz dot language file.
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
19285µs271µ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
use strict;
# spent 61µs making 1 call to main::BEGIN@19.3 # spent 9µs making 1 call to strict::import
2021.25ms261µ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
use warnings;
# spent 42µs making 1 call to main::BEGIN@20.4 # spent 18µs making 1 call to warnings::import
21
22package OpenBSD::PackageRepositoryFactory;
23sub new
24
# spent 7µs within OpenBSD::PackageRepositoryFactory::new which was called: # once (7µs+0s) by OpenBSD::State::init at line 112
{
2511µs my ($class, $state) = @_;
26137µs bless {state => $state}, $class;
27}
28
29sub 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
{
311900ns my $self = shift;
32117µs177.4ms return $self->{state}->locator;
# spent 77.4ms making 1 call to OpenBSD::State::locator
33}
34
35sub installed
36{
37 my ($self, $all) = @_;
38 require OpenBSD::PackageRepository::Installed;
39
40 return OpenBSD::PackageRepository::Installed->new($all, $self->{state});
41}
42
43sub path_parse
44{
45 my ($self, $pkgname) = @_;
46
47 return $self->locator->path_parse($pkgname, $self->{state});
48}
49
50sub find
51{
52 my ($self, $pkg) = @_;
53
54 return $self->locator->find($pkg, $self->{state});
55}
56
57sub reinitialize
58{
59}
60
61sub 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
{
631900ns my $self = shift;
64
65125µs22.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
68sub grabPlist
69{
70 my ($self, $url, $code) = @_;
71
72 return $self->locator->grabPlist($url, $code, $self->{state});
73}
74
75sub 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.
85package OpenBSD::State;
862528µs218.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
use Carp;
# spent 17.9ms making 1 call to OpenBSD::State::BEGIN@86 # spent 325µs making 1 call to Exporter::import
872470µs13.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
use OpenBSD::Subst;
# spent 3.16ms making 1 call to OpenBSD::State::BEGIN@87
8824.69ms25.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
use OpenBSD::Error;
# spent 5.53ms making 1 call to OpenBSD::State::BEGIN@88 # spent 218µs making 1 call to Exporter::import
8913µsrequire Exporter;
90123µsour @ISA = qw(Exporter);
9112µsour @EXPORT = ();
92
93sub 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
{
951285µs require OpenBSD::PackageLocator;
9618µs return "OpenBSD::PackageLocator";
97}
98
99sub 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
{
10112µs my $class = shift;
10211µs my $cmd = shift;
10314µs my $o = bless {cmd => $cmd}, $class;
104110µs193µs $o->init(@_);
# spent 93µs making 1 call to OpenBSD::State::init
10519µs return $o;
106}
107
108sub 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
{
11011µs my $self = shift;
111127µs15µs $self->{subst} = OpenBSD::Subst->new;
# spent 5µs making 1 call to OpenBSD::Subst::new
11218µs17µs $self->{repo} = OpenBSD::PackageRepositoryFactory->new($self);
# spent 7µs making 1 call to OpenBSD::PackageRepositoryFactory::new
11319µs $self->{export_level} = 1;
114}
115
116sub 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
{
11811µs my $self = shift;
119113µs return $self->{repo};
120}
121
122sub sync_display
12340240µ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
126OpenBSD::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
sub {
1281800ns my $self = shift;
12912µs require OpenBSD::Paths;
130142µs228µ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
131126µs119µs while (<$fh>) {
# spent 19µs making 1 call to OpenBSD::State::CORE:readline
13211µs chomp;
13316µs11µs next if m/^\s*\#/;
# spent 1µs making 1 call to OpenBSD::State::CORE:match
13415µs12µs next if m/^\s*$/;
# spent 2µs making 1 call to OpenBSD::State::CORE:match
135131µs return "$_/%c/packages/%a/";
136 }
137117µs135µs });
# spent 35µs making 1 call to OpenBSD::Auto::cache
138
139sub 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
{
14113µs my ($self, @usage) = @_;
14219µs $self->{usage} = \@usage;
143}
144
145sub 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
{
14712µs my $self = shift;
148114µs return $self->{v};
149}
150
151sub 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
{
153136315µs my ($self, $k) = @_;
154136681µs return $self->{opt}{$k};
155}
156
157sub 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
172sub 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
{
1744041µs my $self = shift;
1754048µs if (@_ == 0) {
176 return undef;
177 }
17840256µs my ($fmt, @l) = @_;
179 # make it so that #0 is #
1804090µs unshift(@l, '#');
181401.40ms200792µ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
18240282µs return $fmt;
183}
184
185sub _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
195sub fatal
196{
197 my $self = shift;
198 $self->_fatal($self->f(@_));
199}
200
201sub _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
{
2034045µs my $self = shift;
2044035µs my $fh = shift;
20540450µs40375µs $self->sync_display;
# spent 375µs making 40 calls to OpenBSD::State::sync_display, avg 9µs/call
206401.07ms40550µs print $fh @_;
# spent 550µs making 40 calls to OpenBSD::State::CORE:print, avg 14µs/call
207}
208sub _print
209{
210 my $self = shift;
211 $self->_fhprint(\*STDOUT, @_);
212}
213
214sub _errprint
215{
216 my $self = shift;
217 $self->_fhprint(\*STDERR, @_);
218}
219
220sub fhprint
221{
222 my $self = shift;
223 my $fh = shift;
224 $self->_fhprint($fh, $self->f(@_));
225}
226
227sub 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
{
2294038µs my $self = shift;
2304039µs my $fh = shift;
23140333µs if (@_ == 0) {
232 $self->_fhprint($fh, "\n");
233 } else {
23440691µs804.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
238sub print
239{
240 my $self = shift;
241 $self->fhprint(\*STDOUT, @_);
242}
243
244sub 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
{
2464045µs my $self = shift;
24740343µs404.91ms $self->fhsay(\*STDOUT, @_);
# spent 4.91ms making 40 calls to OpenBSD::State::fhsay, avg 123µs/call
248}
249
250sub errprint
251{
252 my $self = shift;
253 $self->fhprint(\*STDERR, @_);
254}
255
256sub errsay
257{
258 my $self = shift;
259 $self->fhsay(\*STDERR, @_);
260}
261
262sub 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
{
26412µ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
try {
26818µs1360µs &$sub;
# spent 360µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:287]
269 } catchall {
270 $state->usage("#1", $_);
271119µs2401µs };
# spent 395µs making 1 call to OpenBSD::Error::try # spent 6µs making 1 call to OpenBSD::Error::catchall
272}
273
274sub 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
{
27613µs my ($state, $opt_string, @usage) = @_;
27712µs require OpenBSD::Getopt;
278
279116µs14µs $state->{opt}{v} = 0 unless $opt_string =~ m/v/;
# spent 4µs making 1 call to OpenBSD::State::CORE:match
280112µs15µ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);
283112µs12µs } unless $opt_string =~ m/D/;
# spent 2µs making 1 call to OpenBSD::State::CORE:match
284110µs19µ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
$state->do_options(sub {
286112µs1349µs OpenBSD::Getopt::getopts($opt_string.'hvD:', $state->{opt});
# spent 349µs making 1 call to OpenBSD::Getopt::getopts
287126µs1423µs });
# spent 423µs making 1 call to OpenBSD::State::do_options
28818µs15µs $state->{v} = $state->opt('v');
# spent 5µs making 1 call to OpenBSD::State::opt
289
290110µs228µ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 {
29512µs $state->{signature_style} //= 'new';
296 }
297
29817µs return if $state->{no_exports};
299 # XXX
3002140µs2140µ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
no strict "refs";
# spent 87µs making 1 call to OpenBSD::State::BEGIN@300 # spent 54µs making 1 call to strict::unimport
30124.27ms2110µ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
no strict "vars";
# 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
310sub 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
{
31238µs my ($self, $k) = @_;
313336µs322µs return $self->{subst}->value($k);
# spent 22µs making 3 calls to OpenBSD::Subst::value, avg 7µs/call
314}
315
316sub width
317{
318 my $self = shift;
319 if (!defined $self->{width}) {
320 $self->find_window_size;
321 }
322 return $self->{width};
323}
324
325sub height
326{
327 my $self = shift;
328 if (!defined $self->{height}) {
329 $self->find_window_size;
330 }
331 return $self->{height};
332}
333
334sub 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
354OpenBSD::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 }
366110µs121µs });
# spent 21µs making 1 call to OpenBSD::Auto::cache
367
36812µsmy @signal_name = ();
369sub 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
398sub 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
409sub 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
427sub _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
455sub 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
472sub 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
492sub 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
504sub 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
518sub 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
530125µs1;
 
# 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
sub OpenBSD::State::CORE:match; # opcode
# 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
sub OpenBSD::State::CORE:open; # opcode
# 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
sub OpenBSD::State::CORE:print; # opcode
# 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
sub OpenBSD::State::CORE:readline; # opcode
# 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
sub OpenBSD::State::CORE:subst; # opcode
# 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
sub OpenBSD::State::CORE:substcont; # opcode