| Filename | /usr/libdata/perl5/OpenBSD/Search.pm |
| Statements | Executed 37 statements in 1.91ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 2 | 1 | 1 | 78µs | 12.0s | OpenBSD::Search::match_locations |
| 2 | 1 | 1 | 75µs | 12.0s | OpenBSD::Search::PartialStem::match |
| 1 | 1 | 1 | 18µs | 22µs | OpenBSD::PkgInfo::BEGIN@18 |
| 1 | 1 | 1 | 18µs | 28µs | OpenBSD::Search::Stem::new |
| 1 | 1 | 1 | 10µs | 17µs | OpenBSD::PkgInfo::BEGIN@19 |
| 1 | 1 | 1 | 8µs | 9µs | OpenBSD::Search::Stem::_new |
| 2 | 2 | 1 | 2µs | 2µs | OpenBSD::Search::Stem::CORE:match (opcode) |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Exact::spec_class |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::__ANON__[:217] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::__ANON__[:261] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::__ANON__[:288] |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::filter_locations |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::keep_most_recent |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::match_partialpath |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::more_recent_than |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::FilterLocation::new |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PartialStem::_keep |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::add_pkgpath_hint |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::filter |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::filter_libs |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::filter_locations |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::is_valid |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::match_locations |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::new |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::PkgSpec::spec_class |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Stem::_keep |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Stem::add_stem |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Stem::filter |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Stem::match |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::Search::Stem::split |
| 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 | |||||
| 18 | 2 | 32µs | 2 | 26µ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 # spent 22µs making 1 call to OpenBSD::PkgInfo::BEGIN@18
# spent 4µs making 1 call to strict::import |
| 19 | 2 | 1.67ms | 2 | 24µ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 # spent 17µs making 1 call to OpenBSD::PkgInfo::BEGIN@19
# spent 8µs making 1 call to warnings::import |
| 20 | |||||
| 21 | package OpenBSD::Search; | ||||
| 22 | sub 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 | ||||
| 24 | 2 | 2µs | my ($self, $o) = @_; | ||
| 25 | 2 | 3µs | require OpenBSD::PackageLocation; | ||
| 26 | |||||
| 27 | 5 | 54µs | 5 | 12.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 |
| 28 | 2 | 16µs | return \@l; | ||
| 29 | } | ||||
| 30 | |||||
| 31 | package OpenBSD::Search::PkgSpec; | ||||
| 32 | 1 | 7µs | our @ISA=(qw(OpenBSD::Search)); | ||
| 33 | |||||
| 34 | sub filter | ||||
| 35 | { | ||||
| 36 | my ($self, @list) = @_; | ||||
| 37 | return $self->{spec}->match_ref(\@list); | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | sub filter_libs | ||||
| 41 | { | ||||
| 42 | my ($self, @list) = @_; | ||||
| 43 | return $self->{spec}->match_libs_ref(\@list); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | sub match_locations | ||||
| 47 | { | ||||
| 48 | my ($self, $o) = @_; | ||||
| 49 | return $self->{spec}->match_locations($o->locations_list); | ||||
| 50 | } | ||||
| 51 | |||||
| 52 | sub filter_locations | ||||
| 53 | { | ||||
| 54 | my ($self, $l) = @_; | ||||
| 55 | return $self->{spec}->match_locations($l); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | sub 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 | |||||
| 67 | sub add_pkgpath_hint | ||||
| 68 | { | ||||
| 69 | my ($self, $pkgpath) = @_; | ||||
| 70 | $self->{pkgpath} = $pkgpath; | ||||
| 71 | return $self; | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub spec_class | ||||
| 75 | { "OpenBSD::PkgSpec" } | ||||
| 76 | |||||
| 77 | sub is_valid | ||||
| 78 | { | ||||
| 79 | my $self = shift; | ||||
| 80 | return $self->{spec}->is_valid; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | package OpenBSD::Search::Exact; | ||||
| 84 | 1 | 4µs | our @ISA=(qw(OpenBSD::Search::PkgSpec)); | ||
| 85 | sub spec_class | ||||
| 86 | { "OpenBSD::PkgSpec::Exact" } | ||||
| 87 | |||||
| 88 | package OpenBSD::Search::Stem; | ||||
| 89 | 1 | 3µs | our @ISA=(qw(OpenBSD::Search)); | ||
| 90 | |||||
| 91 | sub 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 | ||||
| 93 | 1 | 1µs | my ($class, $stem) = @_; | ||
| 94 | 1 | 10µs | 1 | 2µ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 { | ||||
| 98 | 1 | 8µs | 1 | 9µs | return $class->_new($stem); # spent 9µs making 1 call to OpenBSD::Search::Stem::_new |
| 99 | } | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | sub _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 | ||||
| 104 | 1 | 1µs | my ($class, $stem) = @_; | ||
| 105 | |||||
| 106 | 1 | 5µs | 1 | 900ns | 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 | } | ||||
| 110 | 1 | 6µs | return bless {"$stem" => 1}, $class; | ||
| 111 | } | ||||
| 112 | |||||
| 113 | sub split | ||||
| 114 | { | ||||
| 115 | my ($class, $pkgname) = @_; | ||||
| 116 | require OpenBSD::PackageName; | ||||
| 117 | |||||
| 118 | return $class->new(OpenBSD::PackageName::splitstem($pkgname)); | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | sub add_stem | ||||
| 122 | { | ||||
| 123 | my ($self, $extra) = @_; | ||||
| 124 | $self->{$extra} = 1; | ||||
| 125 | |||||
| 126 | } | ||||
| 127 | |||||
| 128 | sub 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 | |||||
| 139 | sub _keep | ||||
| 140 | { | ||||
| 141 | my ($self, $stem) = @_; | ||||
| 142 | return defined $self->{$stem}; | ||||
| 143 | } | ||||
| 144 | |||||
| 145 | sub 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 | |||||
| 158 | package OpenBSD::Search::PartialStem; | ||||
| 159 | 1 | 3µs | our @ISA=(qw(OpenBSD::Search::Stem)); | ||
| 160 | |||||
| 161 | sub 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 | ||||
| 163 | 2 | 2µs | my ($self, $o) = @_; | ||
| 164 | 2 | 2µs | my @r = (); | ||
| 165 | 2 | 12µs | for my $k (keys %$self) { | ||
| 166 | 2 | 41µs | 4 | 12.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 | } | ||||
| 168 | 2 | 22µs | return @r; | ||
| 169 | } | ||||
| 170 | |||||
| 171 | sub _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 | |||||
| 182 | package OpenBSD::Search::FilterLocation; | ||||
| 183 | 1 | 3µs | our @ISA=(qw(OpenBSD::Search)); | ||
| 184 | sub new | ||||
| 185 | { | ||||
| 186 | my ($class, $code) = @_; | ||||
| 187 | |||||
| 188 | return bless {code => $code}, $class; | ||||
| 189 | } | ||||
| 190 | |||||
| 191 | sub filter_locations | ||||
| 192 | { | ||||
| 193 | my ($self, $l) = @_; | ||||
| 194 | return &{$self->{code}}($l); | ||||
| 195 | } | ||||
| 196 | |||||
| 197 | sub 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( | ||||
| 205 | sub { | ||||
| 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 | |||||
| 220 | sub keep_most_recent | ||||
| 221 | { | ||||
| 222 | my $class = shift; | ||||
| 223 | return $class->new( | ||||
| 224 | sub { | ||||
| 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 | |||||
| 265 | sub match_partialpath | ||||
| 266 | { | ||||
| 267 | my ($class, $subdir) = @_; | ||||
| 268 | return $class->new( | ||||
| 269 | sub { | ||||
| 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 | |||||
| 292 | 1 | 6µs | 1; | ||
sub OpenBSD::Search::Stem::CORE:match; # opcode |