← 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/Search.pm
StatementsExecuted 37 statements in 1.91ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
21178µs12.0sOpenBSD::Search::::match_locations OpenBSD::Search::match_locations
21175µs12.0sOpenBSD::Search::PartialStem::::match OpenBSD::Search::PartialStem::match
11118µs22µsOpenBSD::PkgInfo::::BEGIN@18 OpenBSD::PkgInfo::BEGIN@18
11118µs28µsOpenBSD::Search::Stem::::new OpenBSD::Search::Stem::new
11110µs17µsOpenBSD::PkgInfo::::BEGIN@19 OpenBSD::PkgInfo::BEGIN@19
1118µs9µsOpenBSD::Search::Stem::::_new OpenBSD::Search::Stem::_new
2212µs2µsOpenBSD::Search::Stem::::CORE:match OpenBSD::Search::Stem::CORE:match (opcode)
0000s0sOpenBSD::Search::Exact::::spec_class OpenBSD::Search::Exact::spec_class
0000s0sOpenBSD::Search::FilterLocation::::__ANON__[:217]OpenBSD::Search::FilterLocation::__ANON__[:217]
0000s0sOpenBSD::Search::FilterLocation::::__ANON__[:261]OpenBSD::Search::FilterLocation::__ANON__[:261]
0000s0sOpenBSD::Search::FilterLocation::::__ANON__[:288]OpenBSD::Search::FilterLocation::__ANON__[:288]
0000s0sOpenBSD::Search::FilterLocation::::filter_locationsOpenBSD::Search::FilterLocation::filter_locations
0000s0sOpenBSD::Search::FilterLocation::::keep_most_recentOpenBSD::Search::FilterLocation::keep_most_recent
0000s0sOpenBSD::Search::FilterLocation::::match_partialpathOpenBSD::Search::FilterLocation::match_partialpath
0000s0sOpenBSD::Search::FilterLocation::::more_recent_thanOpenBSD::Search::FilterLocation::more_recent_than
0000s0sOpenBSD::Search::FilterLocation::::newOpenBSD::Search::FilterLocation::new
0000s0sOpenBSD::Search::PartialStem::::_keep OpenBSD::Search::PartialStem::_keep
0000s0sOpenBSD::Search::PkgSpec::::add_pkgpath_hint OpenBSD::Search::PkgSpec::add_pkgpath_hint
0000s0sOpenBSD::Search::PkgSpec::::filter OpenBSD::Search::PkgSpec::filter
0000s0sOpenBSD::Search::PkgSpec::::filter_libs OpenBSD::Search::PkgSpec::filter_libs
0000s0sOpenBSD::Search::PkgSpec::::filter_locations OpenBSD::Search::PkgSpec::filter_locations
0000s0sOpenBSD::Search::PkgSpec::::is_valid OpenBSD::Search::PkgSpec::is_valid
0000s0sOpenBSD::Search::PkgSpec::::match_locations OpenBSD::Search::PkgSpec::match_locations
0000s0sOpenBSD::Search::PkgSpec::::new OpenBSD::Search::PkgSpec::new
0000s0sOpenBSD::Search::PkgSpec::::spec_class OpenBSD::Search::PkgSpec::spec_class
0000s0sOpenBSD::Search::Stem::::_keep OpenBSD::Search::Stem::_keep
0000s0sOpenBSD::Search::Stem::::add_stem OpenBSD::Search::Stem::add_stem
0000s0sOpenBSD::Search::Stem::::filter OpenBSD::Search::Stem::filter
0000s0sOpenBSD::Search::Stem::::match OpenBSD::Search::Stem::match
0000s0sOpenBSD::Search::Stem::::split OpenBSD::Search::Stem::split
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: Search.pm,v 1.29 2016/06/14 15:41:31 espie Exp $
3#
4# Copyright (c) 2007 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
18232µs226µs
# spent 22µs (18+4) within OpenBSD::PkgInfo::BEGIN@18 which was called: # once (18µs+4µs) by OpenBSD::PkgInfo::parse_and_run at line 18
use strict;
# spent 22µs making 1 call to OpenBSD::PkgInfo::BEGIN@18 # spent 4µs making 1 call to strict::import
1921.67ms224µs
# spent 17µs (10+7) within OpenBSD::PkgInfo::BEGIN@19 which was called: # once (10µs+7µs) by OpenBSD::PkgInfo::parse_and_run at line 19
use warnings;
# spent 17µs making 1 call to OpenBSD::PkgInfo::BEGIN@19 # spent 8µs making 1 call to warnings::import
20
21package OpenBSD::Search;
22sub match_locations
23
# spent 12.0s (78µs+12.0) within OpenBSD::Search::match_locations which was called 2 times, avg 5.98s/call: # 2 times (78µs+12.0s) by OpenBSD::PackageRepositoryBase::match_locations at line 111 of OpenBSD/PackageRepository/Installed.pm, avg 5.98s/call
{
2422µs my ($self, $o) = @_;
2523µs require OpenBSD::PackageLocation;
26
27554µs512.0s my @l = map {$o->new_location($_)} $self->match($o);
# spent 12.0s making 2 calls to OpenBSD::Search::PartialStem::match, avg 5.98s/call # spent 168µs making 3 calls to OpenBSD::PackageRepositoryBase::new_location, avg 56µs/call
28216µs return \@l;
29}
30
31package OpenBSD::Search::PkgSpec;
3217µsour @ISA=(qw(OpenBSD::Search));
33
34sub filter
35{
36 my ($self, @list) = @_;
37 return $self->{spec}->match_ref(\@list);
38}
39
40sub filter_libs
41{
42 my ($self, @list) = @_;
43 return $self->{spec}->match_libs_ref(\@list);
44}
45
46sub match_locations
47{
48 my ($self, $o) = @_;
49 return $self->{spec}->match_locations($o->locations_list);
50}
51
52sub filter_locations
53{
54 my ($self, $l) = @_;
55 return $self->{spec}->match_locations($l);
56}
57
58sub new
59{
60 my ($class, $pattern, $with_partial) = @_;
61 require OpenBSD::PkgSpec;
62
63 bless { spec => $class->spec_class->new($pattern, $with_partial)},
64 $class;
65}
66
67sub add_pkgpath_hint
68{
69 my ($self, $pkgpath) = @_;
70 $self->{pkgpath} = $pkgpath;
71 return $self;
72}
73
74sub spec_class
75{ "OpenBSD::PkgSpec" }
76
77sub is_valid
78{
79 my $self = shift;
80 return $self->{spec}->is_valid;
81}
82
83package OpenBSD::Search::Exact;
8414µsour @ISA=(qw(OpenBSD::Search::PkgSpec));
85sub spec_class
86{ "OpenBSD::PkgSpec::Exact" }
87
88package OpenBSD::Search::Stem;
8913µsour @ISA=(qw(OpenBSD::Search));
90
91sub new
92
# spent 28µs (18+11) within OpenBSD::Search::Stem::new which was called: # once (18µs+11µs) by OpenBSD::PkgInfo::parse_and_run at line 600 of OpenBSD/PkgInfo.pm
{
9311µs my ($class, $stem) = @_;
94110µs12µs if ($stem =~ m/^(.*)\%(.*)/) {
# spent 2µs making 1 call to OpenBSD::Search::Stem::CORE:match
95 return ($class->_new($1),
96 OpenBSD::Search::FilterLocation->match_partialpath($2));
97 } else {
9818µs19µs return $class->_new($stem);
# spent 9µs making 1 call to OpenBSD::Search::Stem::_new
99 }
100}
101
102sub _new
103
# spent 9µs (8+900ns) within OpenBSD::Search::Stem::_new which was called: # once (8µs+900ns) by OpenBSD::Search::Stem::new at line 98
{
10411µs my ($class, $stem) = @_;
105
10615µs1900ns if ($stem =~ m/^(.*)\-\-(.*)/) {
# spent 900ns making 1 call to OpenBSD::Search::Stem::CORE:match
107 # XXX
108 return OpenBSD::Search::Exact->new("$1-*-$2");
109 }
11016µs return bless {"$stem" => 1}, $class;
111}
112
113sub split
114{
115 my ($class, $pkgname) = @_;
116 require OpenBSD::PackageName;
117
118 return $class->new(OpenBSD::PackageName::splitstem($pkgname));
119}
120
121sub add_stem
122{
123 my ($self, $extra) = @_;
124 $self->{$extra} = 1;
125
126}
127
128sub match
129{
130 my ($self, $o) = @_;
131
132 my @r = ();
133 for my $k (keys %$self) {
134 push(@r, $o->stemlist->find($k));
135 }
136 return @r;
137}
138
139sub _keep
140{
141 my ($self, $stem) = @_;
142 return defined $self->{$stem};
143}
144
145sub filter
146{
147 my ($self, @l) = @_;
148 my @result = ();
149 require OpenBSD::PackageName;
150 for my $pkg (@l) {
151 if ($self->_keep(OpenBSD::PackageName::splitstem($pkg))) {
152 push(@result, $pkg);
153 }
154 }
155 return @result;
156}
157
158package OpenBSD::Search::PartialStem;
15913µsour @ISA=(qw(OpenBSD::Search::Stem));
160
161sub match
162
# spent 12.0s (75µs+12.0) within OpenBSD::Search::PartialStem::match which was called 2 times, avg 5.98s/call: # 2 times (75µs+12.0s) by OpenBSD::Search::match_locations at line 27, avg 5.98s/call
{
16322µs my ($self, $o) = @_;
16422µs my @r = ();
165212µs for my $k (keys %$self) {
166241µs412.0s push(@r, $o->stemlist->find_partial($k));
# spent 11.9s making 2 calls to OpenBSD::PackageRepository::stemlist, avg 5.94s/call # spent 66.8ms making 2 calls to OpenBSD::PackageLocator::_compiled_stemlist::find_partial, avg 33.4ms/call
167 }
168222µs return @r;
169}
170
171sub _keep
172{
173 my ($self, $stem) = @_;
174 for my $partial (keys %$self) {
175 if ($stem =~ /\Q$partial\E/) {
176 return 1;
177 }
178 }
179 return 0;
180}
181
182package OpenBSD::Search::FilterLocation;
18313µsour @ISA=(qw(OpenBSD::Search));
184sub new
185{
186 my ($class, $code) = @_;
187
188 return bless {code => $code}, $class;
189}
190
191sub filter_locations
192{
193 my ($self, $l) = @_;
194 return &{$self->{code}}($l);
195}
196
197sub more_recent_than
198{
199 my ($class, $name, $rfound) = @_;
200 require OpenBSD::PackageName;
201
202 my $f = OpenBSD::PackageName->from_string($name);
203
204 return $class->new(
205sub {
206 my $l = shift;
207 my $r = [];
208 for my $e (@$l) {
209 if ($f->{version}->compare($e->pkgname->{version}) <= 0) {
210 push(@$r, $e);
211 }
212 if (ref $rfound) {
213 $$rfound = 1;
214 }
215 }
216 return $r;
217 });
218}
219
220sub keep_most_recent
221{
222 my $class = shift;
223 return $class->new(
224sub {
225 my $l = shift;
226 # no need to filter
227 return $l if @$l <= 1;
228
229 require OpenBSD::PackageName;
230 my $h = {};
231 # we have to prove we have to keep it
232 while (my $e = pop @$l) {
233 my $stem = $e->pkgname->{stem};
234 my $keep = 1;
235 # so let's compare with every element in $h with the same stem
236 for my $f (@{$h->{$e->pkgname->{stem}}}) {
237 # if this is not the same flavors,
238 # we don't filter
239 if ($f->pkgname->flavor_string ne $e->pkgname->flavor_string) {
240 next;
241 }
242 # okay, now we need to prove there's a common pkgpath
243 if (!$e->update_info->match_pkgpath($f->update_info)) {
244 next;
245 }
246
247 if ($f->pkgname->{version}->compare($e->pkgname->{version}) < 0) {
248 $f = $e;
249 }
250 $keep = 0;
251 last;
252
253 }
254 if ($keep) {
255 push(@{$h->{$e->pkgname->{stem}}}, $e);
256 }
257 }
258 my $largest = [];
259 push @$largest, map {@$_} values %$h;
260 return $largest;
261}
262 );
263}
264
265sub match_partialpath
266{
267 my ($class, $subdir) = @_;
268 return $class->new(
269sub {
270 my $l = shift;
271 if (@$l == 0) {
272 return $l;
273 }
274 my @l2 = ();
275 for my $loc (@$l) {
276 if (!$loc) {
277 next;
278 }
279 my $p2 = $loc->update_info;
280 if (!$p2) {
281 next;
282 }
283 if ($p2->pkgpath->partial_match($subdir)) {
284 push(@l2, $loc);
285 }
286 }
287 return \@l2;
288}
289 );
290}
291
29216µs1;
 
# spent 2µs within OpenBSD::Search::Stem::CORE:match which was called 2 times, avg 1µs/call: # once (2µs+0s) by OpenBSD::Search::Stem::new at line 94 # once (900ns+0s) by OpenBSD::Search::Stem::_new at line 106
sub OpenBSD::Search::Stem::CORE:match; # opcode