← Index
NYTProf Performance Profile   « line view »
For /usr/sbin/pkg_info
  Run on Fri Aug 4 10:15:59 2017
Reported on Fri Aug 4 10:16:18 2017

Filename/usr/libdata/perl5/OpenBSD/State.pm
StatementsExecuted 156 statements in 3.94ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.31ms4.73msOpenBSD::State::::BEGIN@86 OpenBSD::State::BEGIN@86
1111.29ms1.51msOpenBSD::State::::BEGIN@88 OpenBSD::State::BEGIN@88
111808µs845µsOpenBSD::State::::BEGIN@87 OpenBSD::State::BEGIN@87
111725µs12.5msOpenBSD::State::::locator OpenBSD::State::locator
11169µs116µsOpenBSD::State::::__ANON__[:137] OpenBSD::State::__ANON__[:137]
31166µs66µsOpenBSD::State::::CORE:print OpenBSD::State::CORE:print (opcode)
31165µs90µsOpenBSD::State::::f OpenBSD::State::f
11159µs319µsOpenBSD::State::::handle_options OpenBSD::State::handle_options
31154µs266µsOpenBSD::State::::fhsay OpenBSD::State::fhsay
31140µs122µsOpenBSD::State::::_fhprint OpenBSD::State::_fhprint
166240µs40µsOpenBSD::State::::opt OpenBSD::State::opt
32237µs58µsOpenBSD::State::::defines OpenBSD::State::defines
11133µs41µsOpenBSD::State::::init OpenBSD::State::init
31130µs296µsOpenBSD::State::::say OpenBSD::State::say
11127µs12.0sOpenBSD::PackageRepositoryFactory::::match_locationsOpenBSD::PackageRepositoryFactory::match_locations
11124µs24µsOpenBSD::State::::CORE:open OpenBSD::State::CORE:open (opcode)
11118µs18µsOpenBSD::State::::CORE:readline OpenBSD::State::CORE:readline (opcode)
31116µs16µsOpenBSD::State::::sync_display OpenBSD::State::sync_display
11116µs12.5msOpenBSD::PackageRepositoryFactory::::locatorOpenBSD::PackageRepositoryFactory::locator
11116µs19µsmain::::BEGIN@19.3 main::BEGIN@19.3
11115µs56µsOpenBSD::State::::new OpenBSD::State::new
31114µs14µsOpenBSD::State::::CORE:subst OpenBSD::State::CORE:subst (opcode)
11114µs228µsOpenBSD::State::::do_options OpenBSD::State::do_options
11111µs27µsOpenBSD::State::::BEGIN@301 OpenBSD::State::BEGIN@301
61111µs11µsOpenBSD::State::::CORE:substcont OpenBSD::State::CORE:substcont (opcode)
11110µs30µsOpenBSD::State::::BEGIN@300 OpenBSD::State::BEGIN@300
1119µs16µsmain::::BEGIN@20.4 main::BEGIN@20.4
5517µs7µsOpenBSD::State::::CORE:match OpenBSD::State::CORE:match (opcode)
1117µs187µsOpenBSD::State::::__ANON__[:287] OpenBSD::State::__ANON__[:287]
1116µs193µsOpenBSD::State::::__ANON__[:269] OpenBSD::State::__ANON__[:269]
1115µs5µsOpenBSD::PackageRepositoryFactory::::newOpenBSD::PackageRepositoryFactory::new
1115µs5µsOpenBSD::State::::repo OpenBSD::State::repo
1114µs4µsOpenBSD::State::::usage_is OpenBSD::State::usage_is
1114µs4µsOpenBSD::State::::verbose OpenBSD::State::verbose
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
19232µs222µs
# spent 19µs (16+3) within main::BEGIN@19.3 which was called: # once (16µs+3µs) by main::BEGIN@22 at line 19
use strict;
# spent 19µs making 1 call to main::BEGIN@19.3 # spent 3µs making 1 call to strict::import
202339µs222µs
# spent 16µs (9+7) within main::BEGIN@20.4 which was called: # once (9µs+7µs) by main::BEGIN@22 at line 20
use warnings;
# spent 16µs making 1 call to main::BEGIN@20.4 # spent 6µs making 1 call to warnings::import
21
22package OpenBSD::PackageRepositoryFactory;
23sub new
24
# spent 5µs within OpenBSD::PackageRepositoryFactory::new which was called: # once (5µs+0s) by OpenBSD::State::init at line 112
{
2511µs my ($class, $state) = @_;
2616µs bless {state => $state}, $class;
27}
28
29sub locator
30
# spent 12.5ms (16µs+12.5) within OpenBSD::PackageRepositoryFactory::locator which was called: # once (16µs+12.5ms) by OpenBSD::PackageRepositoryFactory::match_locations at line 65
{
311900ns my $self = shift;
32113µs112.5ms return $self->{state}->locator;
# spent 12.5ms 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 12.0s (27µs+12.0) within OpenBSD::PackageRepositoryFactory::match_locations which was called: # once (27µs+12.0s) by OpenBSD::PkgInfo::parse_and_run at line 601 of OpenBSD/PkgInfo.pm
{
631800ns my $self = shift;
64
65125µs212.0s return $self->locator->match_locations(@_, $self->{state});
# spent 12.0s making 1 call to OpenBSD::PackageLocator::match_locations # spent 12.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;
862158µs24.81ms
# spent 4.73ms (4.31+411µs) within OpenBSD::State::BEGIN@86 which was called: # once (4.31ms+411µs) by main::BEGIN@22 at line 86
use Carp;
# spent 4.73ms making 1 call to OpenBSD::State::BEGIN@86 # spent 80µs making 1 call to Exporter::import
872125µs1845µs
# spent 845µs (808+37) within OpenBSD::State::BEGIN@87 which was called: # once (808µs+37µs) by main::BEGIN@22 at line 87
use OpenBSD::Subst;
# spent 845µs making 1 call to OpenBSD::State::BEGIN@87
8821.20ms21.58ms
# spent 1.51ms (1.29+220µs) within OpenBSD::State::BEGIN@88 which was called: # once (1.29ms+220µs) by main::BEGIN@22 at line 88
use OpenBSD::Error;
# spent 1.51ms making 1 call to OpenBSD::State::BEGIN@88 # spent 68µs making 1 call to Exporter::import
8911µsrequire Exporter;
9016µsour @ISA = qw(Exporter);
911900nsour @EXPORT = ();
92
93sub locator
94
# spent 12.5ms (725µs+11.7) within OpenBSD::State::locator which was called: # once (725µs+11.7ms) by OpenBSD::PackageRepositoryFactory::locator at line 32
{
951117µs require OpenBSD::PackageLocator;
9617µs return "OpenBSD::PackageLocator";
97}
98
99sub new
100
# spent 56µs (15+41) within OpenBSD::State::new which was called: # once (15µs+41µs) by OpenBSD::PkgInfo::parse_and_run at line 524 of OpenBSD/PkgInfo.pm
{
10111µs my $class = shift;
1021800ns my $cmd = shift;
10312µs my $o = bless {cmd => $cmd}, $class;
10416µs141µs $o->init(@_);
# spent 41µs making 1 call to OpenBSD::State::init
10514µs return $o;
106}
107
108sub init
109
# spent 41µs (33+8) within OpenBSD::State::init which was called: # once (33µs+8µs) by OpenBSD::State::new at line 104
{
1101800ns my $self = shift;
111119µs13µs $self->{subst} = OpenBSD::Subst->new;
# spent 3µs making 1 call to OpenBSD::Subst::new
11215µs15µs $self->{repo} = OpenBSD::PackageRepositoryFactory->new($self);
# spent 5µs making 1 call to OpenBSD::PackageRepositoryFactory::new
11315µs $self->{export_level} = 1;
114}
115
116sub repo
117
# spent 5µs within OpenBSD::State::repo which was called: # once (5µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 601 of OpenBSD/PkgInfo.pm
{
1181900ns my $self = shift;
119111µs return $self->{repo};
120}
121
122sub sync_display
123310µs
# spent 16µs within OpenBSD::State::sync_display which was called 3 times, avg 5µs/call: # 3 times (16µs+0s) by OpenBSD::State::_fhprint at line 205, avg 5µs/call
{
124}
125
126OpenBSD::Auto::cache(installpath,
127
# spent 116µs (69+47) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] which was called: # once (69µs+47µs) by OpenBSD::Auto::__ANON__[/usr/libdata/perl5/OpenBSD/Error.pm:28] at line 27 of OpenBSD/Error.pm
sub {
1281800ns my $self = shift;
12911µs require OpenBSD::Paths;
130146µs226µs open(my $fh, '<', OpenBSD::Paths->installurl) or return undef;
# spent 24µs making 1 call to OpenBSD::State::CORE:open # spent 1µs making 1 call to OpenBSD::Paths::installurl
131129µs118µs while (<$fh>) {
# spent 18µs making 1 call to OpenBSD::State::CORE:readline
13211µs chomp;
13315µ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
135130µs return "$_/%c/packages/%a/";
136 }
13716µs111µs });
# spent 11µs making 1 call to OpenBSD::Auto::cache
138
139sub usage_is
140
# spent 4µs within OpenBSD::State::usage_is which was called: # once (4µs+0s) by OpenBSD::State::handle_options at line 284
{
14111µs my ($self, @usage) = @_;
14214µs $self->{usage} = \@usage;
143}
144
145sub verbose
146
# spent 4µs within OpenBSD::State::verbose which was called: # once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 599 of OpenBSD/PkgInfo.pm
{
14711µs my $self = shift;
14817µs return $self->{v};
149}
150
151sub opt
152
# spent 40µs within OpenBSD::State::opt which was called 16 times, avg 2µs/call: # 11 times (25µs+0s) by OpenBSD::PkgInfo::State::hasanyopt at line 151 of OpenBSD/PkgInfo.pm, avg 2µs/call # once (4µs+0s) by OpenBSD::State::handle_options at line 288 # once (4µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 600 of OpenBSD/PkgInfo.pm # once (3µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 559 of OpenBSD/PkgInfo.pm # once (2µs+0s) by OpenBSD::PkgInfo::parse_and_run at line 596 of OpenBSD/PkgInfo.pm # once (2µs+0s) by OpenBSD::PkgInfo::State::lock at line 72 of OpenBSD/PkgInfo.pm
{
1531612µs my ($self, $k) = @_;
1541646µ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 90µs (65+25) within OpenBSD::State::f which was called 3 times, avg 30µs/call: # 3 times (65µs+25µs) by OpenBSD::State::fhsay at line 234, avg 30µs/call
{
17432µs my $self = shift;
17533µs if (@_ == 0) {
176 return undef;
177 }
178313µs my ($fmt, @l) = @_;
179 # make it so that #0 is #
18035µs unshift(@l, '#');
181357µs925µs $fmt =~ s,\#(\d+),($l[$1] // "<Undefined #$1>"),ge;
# spent 14µs making 3 calls to OpenBSD::State::CORE:subst, avg 5µs/call # spent 11µs making 6 calls to OpenBSD::State::CORE:substcont, avg 2µs/call
182314µ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 122µs (40+82) within OpenBSD::State::_fhprint which was called 3 times, avg 41µs/call: # 3 times (40µs+82µs) by OpenBSD::State::fhsay at line 234, avg 41µs/call
{
20333µs my $self = shift;
20432µs my $fh = shift;
205323µs316µs $self->sync_display;
# spent 16µs making 3 calls to OpenBSD::State::sync_display, avg 5µs/call
206397µs366µs print $fh @_;
# spent 66µs making 3 calls to OpenBSD::State::CORE:print, avg 22µ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 266µs (54+212) within OpenBSD::State::fhsay which was called 3 times, avg 89µs/call: # 3 times (54µs+212µs) by OpenBSD::State::say at line 247, avg 89µs/call
{
22932µs my $self = shift;
23032µs my $fh = shift;
231313µs if (@_ == 0) {
232 $self->_fhprint($fh, "\n");
233 } else {
234322µs6212µs $self->_fhprint($fh, $self->f(@_), "\n");
# spent 122µs making 3 calls to OpenBSD::State::_fhprint, avg 41µs/call # spent 90µs making 3 calls to OpenBSD::State::f, avg 30µs/call
235 }
236}
237
238sub print
239{
240 my $self = shift;
241 $self->fhprint(\*STDOUT, @_);
242}
243
244sub say
245
# spent 296µs (30+266) within OpenBSD::State::say which was called 3 times, avg 99µs/call: # 3 times (30µs+266µs) by OpenBSD::PkgInfo::parse_and_run at line 604 of OpenBSD/PkgInfo.pm, avg 99µs/call
{
24632µs my $self = shift;
247321µs3266µs $self->fhsay(\*STDOUT, @_);
# spent 266µs making 3 calls to OpenBSD::State::fhsay, avg 89µ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 228µs (14+214) within OpenBSD::State::do_options which was called: # once (14µs+214µs) by OpenBSD::State::handle_options at line 287
{
2641900ns my ($state, $sub) = @_;
265 # this could be nicer...
266
267
# spent 193µs (6+187) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] which was called: # once (6µs+187µs) by OpenBSD::Error::try at line 175 of OpenBSD/Error.pm
try {
26815µs1187µs &$sub;
# spent 187µs making 1 call to OpenBSD::State::__ANON__[OpenBSD/State.pm:287]
269 } catchall {
270 $state->usage("#1", $_);
271112µs2214µs };
# spent 211µs making 1 call to OpenBSD::Error::try # spent 3µs making 1 call to OpenBSD::Error::catchall
272}
273
274sub handle_options
275
# spent 319µs (59+260) within OpenBSD::State::handle_options which was called: # once (59µs+260µs) by OpenBSD::PkgInfo::parse_and_run at line 555 of OpenBSD/PkgInfo.pm
{
27612µs my ($state, $opt_string, @usage) = @_;
27711µs require OpenBSD::Getopt;
278
27918µs12µs $state->{opt}{v} = 0 unless $opt_string =~ m/v/;
# spent 2µs making 1 call to OpenBSD::State::CORE:match
28015µs12µs $state->{opt}{h} = sub { $state->usage; } unless $opt_string =~ m/h/;
# spent 2µs making 1 call to OpenBSD::State::CORE:match
281 $state->{opt}{D} = sub {
282 $state->{subst}->parse_option(shift);
28316µs1800ns } unless $opt_string =~ m/D/;
# spent 800ns making 1 call to OpenBSD::State::CORE:match
28415µs14µs $state->usage_is(@usage);
# spent 4µs making 1 call to OpenBSD::State::usage_is
285
# spent 187µs (7+181) within OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:287] which was called: # once (7µs+181µs) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:269] at line 268
$state->do_options(sub {
28617µs1181µs OpenBSD::Getopt::getopts($opt_string.'hvD:', $state->{opt});
# spent 181µs making 1 call to OpenBSD::Getopt::getopts
287114µs1228µs });
# spent 228µs making 1 call to OpenBSD::State::do_options
28815µs14µs $state->{v} = $state->opt('v');
# spent 4µs making 1 call to OpenBSD::State::opt
289
29018µs220µs if ($state->defines('unsigned')) {
# spent 20µs making 2 calls to OpenBSD::State::defines, avg 10µs/call
291 $state->{signature_style} //= 'unsigned';
292 } elsif ($state->defines('oldsign')) {
293 $state->fatal('old style signature no longer supported');
294 } else {
29511µs $state->{signature_style} //= 'new';
296 }
297
29815µs return if $state->{no_exports};
299 # XXX
300231µs250µs
# spent 30µs (10+20) within OpenBSD::State::BEGIN@300 which was called: # once (10µs+20µs) by main::BEGIN@22 at line 300
no strict "refs";
# spent 30µs making 1 call to OpenBSD::State::BEGIN@300 # spent 20µs making 1 call to strict::unimport
30121.20ms243µs
# spent 27µs (11+16) within OpenBSD::State::BEGIN@301 which was called: # once (11µs+16µs) by main::BEGIN@22 at line 301
no strict "vars";
# spent 27µs making 1 call to OpenBSD::State::BEGIN@301 # spent 16µ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 58µs (37+21) within OpenBSD::State::defines which was called 3 times, avg 19µs/call: # 2 times (13µs+7µs) by OpenBSD::State::handle_options at line 290, avg 10µs/call # once (24µs+14µs) by OpenBSD::PackageRepositoryBase::parse_url at line 73 of OpenBSD/PackageRepository/Installed.pm
{
31238µs my ($self, $k) = @_;
313334µs321µs return $self->{subst}->value($k);
# spent 21µ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 }
36614µs17µs });
# spent 7µs making 1 call to OpenBSD::Auto::cache
367
3681800nsmy @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
53017µs1;
 
# spent 7µs within OpenBSD::State::CORE:match which was called 5 times, avg 1µs/call: # once (2µs+0s) by OpenBSD::State::handle_options at line 279 # once (2µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 134 # once (2µs+0s) by OpenBSD::State::handle_options at line 280 # once (1µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 133 # once (800ns+0s) by OpenBSD::State::handle_options at line 283
sub OpenBSD::State::CORE:match; # opcode
# spent 24µs within OpenBSD::State::CORE:open which was called: # once (24µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 130
sub OpenBSD::State::CORE:open; # opcode
# spent 66µs within OpenBSD::State::CORE:print which was called 3 times, avg 22µs/call: # 3 times (66µs+0s) by OpenBSD::State::_fhprint at line 206, avg 22µs/call
sub OpenBSD::State::CORE:print; # opcode
# spent 18µs within OpenBSD::State::CORE:readline which was called: # once (18µs+0s) by OpenBSD::State::__ANON__[/usr/libdata/perl5/OpenBSD/State.pm:137] at line 131
sub OpenBSD::State::CORE:readline; # opcode
# spent 14µs within OpenBSD::State::CORE:subst which was called 3 times, avg 5µs/call: # 3 times (14µs+0s) by OpenBSD::State::f at line 181, avg 5µs/call
sub OpenBSD::State::CORE:subst; # opcode
# spent 11µs within OpenBSD::State::CORE:substcont which was called 6 times, avg 2µs/call: # 6 times (11µs+0s) by OpenBSD::State::f at line 181, avg 2µs/call
sub OpenBSD::State::CORE:substcont; # opcode