[PATCH 3/8] Sbuild::ChrootInfoSchroot: Run schroot --info only once at startup
Roger Leigh
rleigh at debian.org
Wed Sep 16 21:21:02 UTC 2009
Rather than running "schroot --list", followed by "schroot --info"
for each chroot found by '--list', just run "schroot --info --all-chroots".
Add function get_info_from_stream(), split from get_info().
get_info_all() repeatedly passes the output of '--info --all-chroots'
to this function to get the information for all chroots in a single
attempt.
This siginificantly speeds up startup, especially in the case where
many chroots exist.
---
lib/Sbuild/ChrootInfoSchroot.pm | 54 +++++++++++++++++++++++---------------
1 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/lib/Sbuild/ChrootInfoSchroot.pm b/lib/Sbuild/ChrootInfoSchroot.pm
index 97d839c..441e645 100644
--- a/lib/Sbuild/ChrootInfoSchroot.pm
+++ b/lib/Sbuild/ChrootInfoSchroot.pm
@@ -45,24 +45,25 @@ sub new {
return $self;
}
-sub get_info {
+sub get_info_from_stream {
my $self = shift;
- my $chroot = shift;
+ my $stream = shift;
- my $chroot_type = "";
- my %tmp = ('Priority' => 0,
- 'Location' => "",
+ my $chroot_type = '';
+ my %tmp = ('Name' => '',
+ 'Priority' => 0,
+ 'Location' => '',
'Session Purged' => 0);
- local %ENV;
+ while (<$stream>) {
+ chomp;
- $ENV{'LC_ALL'} = 'C';
- $ENV{'LANGUAGE'} = 'C';
+ last if ! $_;
- open CHROOT_DATA, '-|', $self->get_conf('SCHROOT'), '--info', '--chroot', $chroot
- or die 'Can\'t run ' . $self->get_conf('SCHROOT') . ' to get chroot data';
- while (<CHROOT_DATA>) {
- chomp;
+ if (/^\s*Name:?\s+(.*)$/ &&
+ $tmp{'Name'} eq "") {
+ $tmp{'Name'} = $1;
+ }
if (/^\s*Type:?\s+(.*)$/) {
$chroot_type = $1;
}
@@ -88,10 +89,8 @@ sub get_info {
}
}
- close CHROOT_DATA or die "Can't close schroot pipe getting chroot data";
-
if ($self->get_conf('DEBUG')) {
- print STDERR "Found schroot chroot: $chroot\n";
+ print STDERR "Found schroot chroot: $tmp{'Name'}\n";
foreach (sort keys %tmp) {
print STDERR " $_ $tmp{$_}\n";
}
@@ -100,6 +99,22 @@ sub get_info {
return \%tmp;
}
+sub get_info {
+ my $self = shift;
+ my $chroot = shift;
+
+ my $chroot_type = "";
+
+ open CHROOT_DATA, '-|', $self->get_conf('SCHROOT'), '--info', '--chroot', $chroot
+ or die 'Can\'t run ' . $self->get_conf('SCHROOT') . ' to get chroot data';
+
+ my $tmp = $self->get_info_from_stream(\*CHROOT_DATA);
+
+ close CHROOT_DATA or die "Can't close schroot pipe getting chroot data";
+
+ return $tmp;
+}
+
sub get_info_all {
my $self = shift;
@@ -111,14 +126,11 @@ sub get_info_all {
$ENV{'LC_ALL'} = 'C';
$ENV{'LANGUAGE'} = 'C';
- open CHROOTS, '-|', $self->get_conf('SCHROOT'), '--list'
+ open CHROOTS, '-|', $self->get_conf('SCHROOT'), '--info', '--all-chroots'
or die 'Can\'t run ' . $self->get_conf('SCHROOT');
while (<CHROOTS>) {
- chomp;
- my $chroot = $_;
- print STDERR "Getting info for $chroot chroot\n"
- if $self->get_conf('DEBUG');
- $chroots->{$chroot} = $self->get_info($chroot);
+ my $tmp = $self->get_info_from_stream(\*CHROOTS);
+ $chroots->{$tmp->{'Name'}} = $tmp;
}
close CHROOTS or die "Can't close schroot pipe";
--
1.6.3.3
--qMm9M+Fa2AknHoGS
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0004-debian-Close-546624.patch"
More information about the Buildd-tools-devel
mailing list