| Filename | /usr/libdata/perl5/OpenBSD/PackageInfo.pm |
| Statements | Executed 282 statements in 59.7ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 95.9ms | 96.1ms | OpenBSD::PackageInfo::BEGIN@30 |
| 1 | 1 | 1 | 39.2ms | 40.9ms | OpenBSD::PackageInfo::BEGIN@31 |
| 1 | 1 | 1 | 28.5ms | 28.7ms | OpenBSD::PackageInfo::lock_db |
| 119 | 2 | 1 | 19.8ms | 19.8ms | OpenBSD::PackageInfo::is_info_name |
| 1 | 1 | 1 | 7.66ms | 7.78ms | OpenBSD::PackageInfo::BEGIN@29 |
| 1 | 1 | 1 | 1.13ms | 46.0ms | OpenBSD::PackageInfo::BEGIN@39 |
| 1 | 1 | 1 | 80µs | 91µs | OpenBSD::PkgInfo::State::BEGIN@18 |
| 1 | 1 | 1 | 28µs | 51µs | OpenBSD::PkgInfo::State::BEGIN@19 |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::_init_list |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::add_installed |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::borked_package |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::delete_installed |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::info_names |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::installed_contents |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::installed_info |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::installed_name |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::installed_packages |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::installed_stems |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::is_installed |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::libs_package |
| 0 | 0 | 0 | 0s | 0s | OpenBSD::PackageInfo::unlock_db |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # ex:ts=8 sw=4: | ||||
| 2 | # $OpenBSD: PackageInfo.pm,v 1.60 2014/01/11 11:51:01 espie Exp $ | ||||
| 3 | # | ||||
| 4 | # Copyright (c) 2003-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 | 2 | 117µs | 2 | 102µs | # spent 91µs (80+11) within OpenBSD::PkgInfo::State::BEGIN@18 which was called:
# once (80µs+11µs) by OpenBSD::PkgInfo::State::BEGIN@65 at line 18 # spent 91µs making 1 call to OpenBSD::PkgInfo::State::BEGIN@18
# spent 11µs making 1 call to strict::import |
| 19 | 2 | 270µs | 2 | 73µs | # spent 51µs (28+23) within OpenBSD::PkgInfo::State::BEGIN@19 which was called:
# once (28µs+23µs) by OpenBSD::PkgInfo::State::BEGIN@65 at line 19 # spent 51µs making 1 call to OpenBSD::PkgInfo::State::BEGIN@19
# spent 23µs making 1 call to warnings::import |
| 20 | |||||
| 21 | package OpenBSD::PackageInfo; | ||||
| 22 | 1 | 2µs | require Exporter; | ||
| 23 | 1 | 16µs | our @ISA=qw(Exporter); | ||
| 24 | 1 | 6µs | our @EXPORT=qw(installed_packages installed_info installed_name info_names is_info_name installed_stems | ||
| 25 | lock_db unlock_db | ||||
| 26 | add_installed delete_installed is_installed borked_package | ||||
| 27 | CONTENTS DESC REQUIRED_BY REQUIRING DISPLAY UNDISPLAY); | ||||
| 28 | |||||
| 29 | 2 | 484µs | 1 | 7.78ms | # spent 7.78ms (7.66+116µs) within OpenBSD::PackageInfo::BEGIN@29 which was called:
# once (7.66ms+116µs) by OpenBSD::PkgInfo::State::BEGIN@65 at line 29 # spent 7.78ms making 1 call to OpenBSD::PackageInfo::BEGIN@29 |
| 30 | 2 | 413µs | 1 | 96.1ms | # spent 96.1ms (95.9+124µs) within OpenBSD::PackageInfo::BEGIN@30 which was called:
# once (95.9ms+124µs) by OpenBSD::PkgInfo::State::BEGIN@65 at line 30 # spent 96.1ms making 1 call to OpenBSD::PackageInfo::BEGIN@30 |
| 31 | # spent 40.9ms (39.2+1.70) within OpenBSD::PackageInfo::BEGIN@31 which was called:
# once (39.2ms+1.70ms) by OpenBSD::PkgInfo::State::BEGIN@65 at line 37 | ||||
| 32 | 1 | 7.15ms | CONTENTS => '+CONTENTS', | ||
| 33 | DESC => '+DESC', | ||||
| 34 | REQUIRED_BY => '+REQUIRED_BY', | ||||
| 35 | REQUIRING => '+REQUIRING', | ||||
| 36 | DISPLAY => '+DISPLAY', | ||||
| 37 | 1 | 64µs | 2 | 41.3ms | UNDISPLAY => '+UNDISPLAY'}; # spent 40.9ms making 1 call to OpenBSD::PackageInfo::BEGIN@31
# spent 421µs making 1 call to constant::import |
| 38 | |||||
| 39 | 2 | 11.9ms | 2 | 80.5ms | # spent 46.0ms (1.13+44.9) within OpenBSD::PackageInfo::BEGIN@39 which was called:
# once (1.13ms+44.9ms) by OpenBSD::PkgInfo::State::BEGIN@65 at line 39 # spent 46.0ms making 1 call to OpenBSD::PackageInfo::BEGIN@39
# spent 34.5ms making 1 call to Exporter::import |
| 40 | 1 | 28µs | 1 | 5µs | my $pkg_db = $ENV{"PKG_DBDIR"} || OpenBSD::Paths->pkgdb; # spent 5µs making 1 call to OpenBSD::Paths::pkgdb |
| 41 | |||||
| 42 | 1 | 900ns | my ($list, $stemlist); | ||
| 43 | |||||
| 44 | 1 | 3µs | our @info = (CONTENTS, DESC, REQUIRED_BY, REQUIRING, DISPLAY, UNDISPLAY); | ||
| 45 | |||||
| 46 | 1 | 2µs | our %info = (); | ||
| 47 | 1 | 2µs | for my $i (@info) { | ||
| 48 | 6 | 5µs | my $j = $i; | ||
| 49 | 6 | 41µs | 6 | 16µs | $j =~ s/\+/F/o; # spent 16µs making 6 calls to OpenBSD::PackageInfo::CORE:subst, avg 3µs/call |
| 50 | 6 | 228µs | $info{$i} = $j; | ||
| 51 | } | ||||
| 52 | |||||
| 53 | sub _init_list | ||||
| 54 | { | ||||
| 55 | $list = {}; | ||||
| 56 | $stemlist = OpenBSD::PackageName::compile_stemlist(); | ||||
| 57 | |||||
| 58 | opendir(my $dir, $pkg_db) or die "Bad pkg_db: $!"; | ||||
| 59 | while (my $e = readdir($dir)) { | ||||
| 60 | next if $e eq '.' or $e eq '..'; | ||||
| 61 | add_installed($e); | ||||
| 62 | } | ||||
| 63 | close($dir); | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | sub add_installed | ||||
| 67 | { | ||||
| 68 | if (!defined $list) { | ||||
| 69 | _init_list(); | ||||
| 70 | } | ||||
| 71 | for my $p (@_) { | ||||
| 72 | $list->{$p} = 1; | ||||
| 73 | $stemlist->add($p); | ||||
| 74 | } | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | sub delete_installed | ||||
| 78 | { | ||||
| 79 | if (!defined $list) { | ||||
| 80 | _init_list(); | ||||
| 81 | } | ||||
| 82 | for my $p (@_) { | ||||
| 83 | delete $list->{$p}; | ||||
| 84 | $stemlist->delete($p); | ||||
| 85 | |||||
| 86 | } | ||||
| 87 | } | ||||
| 88 | |||||
| 89 | sub installed_stems | ||||
| 90 | { | ||||
| 91 | if (!defined $list) { | ||||
| 92 | _init_list(); | ||||
| 93 | } | ||||
| 94 | return $stemlist; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | sub installed_packages | ||||
| 98 | { | ||||
| 99 | if (!defined $list) { | ||||
| 100 | _init_list(); | ||||
| 101 | } | ||||
| 102 | if ($_[0]) { | ||||
| 103 | return grep { !/^\./o } keys %$list; | ||||
| 104 | } else { | ||||
| 105 | return keys %$list; | ||||
| 106 | } | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | sub installed_info | ||||
| 110 | { | ||||
| 111 | my $name = shift; | ||||
| 112 | |||||
| 113 | # XXX remove the o if we allow pkg_db to change dynamically | ||||
| 114 | if ($name =~ m|^\Q$pkg_db\E/?|o) { | ||||
| 115 | return "$name/"; | ||||
| 116 | } else { | ||||
| 117 | return "$pkg_db/$name/"; | ||||
| 118 | } | ||||
| 119 | } | ||||
| 120 | |||||
| 121 | sub installed_contents | ||||
| 122 | { | ||||
| 123 | my $name = shift; | ||||
| 124 | return installed_info($name).CONTENTS; | ||||
| 125 | } | ||||
| 126 | |||||
| 127 | sub borked_package | ||||
| 128 | { | ||||
| 129 | my $pkgname = shift; | ||||
| 130 | $pkgname = "partial-$pkgname" unless $pkgname =~ m/^partial\-/; | ||||
| 131 | unless (-e "$pkg_db/$pkgname") { | ||||
| 132 | return $pkgname; | ||||
| 133 | } | ||||
| 134 | my $i = 1; | ||||
| 135 | |||||
| 136 | while (-e "$pkg_db/$pkgname.$i") { | ||||
| 137 | $i++; | ||||
| 138 | } | ||||
| 139 | return "$pkgname.$i"; | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | sub libs_package | ||||
| 143 | { | ||||
| 144 | my $pkgname = shift; | ||||
| 145 | $pkgname =~ s/^\.libs\d*\-//; | ||||
| 146 | unless (-e "$pkg_db/.libs-$pkgname") { | ||||
| 147 | return ".libs-$pkgname"; | ||||
| 148 | } | ||||
| 149 | my $i = 1; | ||||
| 150 | |||||
| 151 | while (-e "$pkg_db/.libs$i-$pkgname") { | ||||
| 152 | $i++; | ||||
| 153 | } | ||||
| 154 | return ".libs$i-$pkgname"; | ||||
| 155 | } | ||||
| 156 | |||||
| 157 | sub is_installed | ||||
| 158 | { | ||||
| 159 | my $name = installed_name(shift); | ||||
| 160 | if (!defined $list) { | ||||
| 161 | installed_packages(); | ||||
| 162 | } | ||||
| 163 | return defined $list->{$name}; | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | sub installed_name | ||||
| 167 | { | ||||
| 168 | require File::Spec; | ||||
| 169 | my $name = File::Spec->canonpath(shift); | ||||
| 170 | $name =~ s|/$||o; | ||||
| 171 | # XXX remove the o if we allow pkg_db to change dynamically | ||||
| 172 | $name =~ s|^\Q$pkg_db\E/?||o; | ||||
| 173 | $name =~ s|/\+CONTENTS$||o; | ||||
| 174 | return $name; | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | sub info_names() | ||||
| 178 | { | ||||
| 179 | return @info; | ||||
| 180 | } | ||||
| 181 | |||||
| 182 | sub is_info_name | ||||
| 183 | # spent 19.8ms within OpenBSD::PackageInfo::is_info_name which was called 119 times, avg 167µs/call:
# 79 times (375µs+0s) by OpenBSD::PackageLocation::grab_info at line 166 of OpenBSD/PackageLocation.pm, avg 5µs/call
# 40 times (19.5ms+0s) by OpenBSD::PackageLocation::find_contents at line 116 of OpenBSD/PackageLocation.pm, avg 486µs/call | ||||
| 184 | 119 | 144µs | my $name = shift; | ||
| 185 | 119 | 10.1ms | return $info{$name}; | ||
| 186 | } | ||||
| 187 | |||||
| 188 | 1 | 600ns | my $dlock; | ||
| 189 | |||||
| 190 | sub lock_db($;$) | ||||
| 191 | # spent 28.7ms (28.5+223µs) within OpenBSD::PackageInfo::lock_db which was called:
# once (28.5ms+223µs) by OpenBSD::PkgInfo::State::lock at line 72 of OpenBSD/PkgInfo.pm | ||||
| 192 | 1 | 900ns | my ($shared, $state) = @_; | ||
| 193 | 1 | 1µs | my $mode = $shared ? LOCK_SH : LOCK_EX; | ||
| 194 | 1 | 28.6ms | 1 | 190µs | open($dlock, '<', $pkg_db) or return; # spent 190µs making 1 call to OpenBSD::PackageInfo::CORE:open |
| 195 | 1 | 64µs | 1 | 33µs | if (flock($dlock, $mode | LOCK_NB)) { # spent 33µs making 1 call to OpenBSD::PackageInfo::CORE:flock |
| 196 | return; | ||||
| 197 | } | ||||
| 198 | $state->errprint("Package database already locked... awaiting release... ") | ||||
| 199 | if defined $state; | ||||
| 200 | while (!flock($dlock, $mode)) { | ||||
| 201 | } | ||||
| 202 | $state->errsay("done!") if defined $state; | ||||
| 203 | return; | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | sub unlock_db() | ||||
| 207 | { | ||||
| 208 | if (defined $dlock) { | ||||
| 209 | flock($dlock, LOCK_UN); | ||||
| 210 | close($dlock); | ||||
| 211 | } | ||||
| 212 | } | ||||
| 213 | |||||
| 214 | 1 | 20µs | 1; |