From: Ian Jackson Subject: [OSSTEST PATCH 21/25] sg-report-host-history: Aggregate runvars query for all hosts Date: Wed, 17 Jun 2015 17:45:17 +0100 Message-ID: <1434559521-8751-22-git-send-email-ian.jackson@eu.citrix.com> References: <1434559521-8751-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z5GTM-0004fk-Mm for xen-devel@lists.xenproject.org; Wed, 17 Jun 2015 16:45:56 +0000 In-Reply-To: <1434559521-8751-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org This is much faster. It might short-change unpopular hosts rather; hence the change of the limit fudge factor from 2 to 3. Signed-off-by: Ian Jackson --- sg-report-host-history | 96 +++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/sg-report-host-history b/sg-report-host-history index b3ef63e..bab636e 100755 --- a/sg-report-host-history +++ b/sg-report-host-history @@ -23,6 +23,7 @@ use DBI; use Osstest; use IO::Handle; use HTML::Entities; +use POSIX; use Osstest::Executive qw(:DEFAULT :colours); @@ -103,6 +104,50 @@ sub jobquery ($$) { return $q->fetchrow_hashref(); } +our %hosts; + +sub mainquery () { + our $valcond = join " OR ", map { "val = ?" } keys %hosts; + our @params = keys %hosts; + + our $runvarq //= db_prepare(<execute(@params); + + print DEBUG "FIRST PASS\n"; + while (my $jr= $runvarq->fetchrow_hashref()) { + print DEBUG "JOB $jr->{flight}.$jr->{job} "; + + my $endedrow = jobquery($endedq, $jr); + if (!$endedrow) { + print DEBUG "no-finished\n"; + next; + } + print DEBUG join " ", map { $endedrow->{$_} } sort keys %$endedrow; + print DEBUG ".\n"; + + push @{ $hosts{$jr->{val}} }, { %$jr, %$endedrow }; + } +} + sub reporthost ($) { my ($hostname) = @_; @@ -128,24 +173,6 @@ sub reporthost ($) { print H "\n"; - our $runvarq //= db_prepare(<execute($hostname); - - print DEBUG "FIRST PASS\n"; - while (my $jr= $runvarq->fetchrow_hashref()) { - print DEBUG "JOB $jr->{flight}.$jr->{job} "; - - my $endedrow = jobquery($endedq, $jr); - if (!$endedrow) { - print DEBUG "no-finished\n"; - next; - } - print DEBUG join " ", map { $endedrow->{$_} } sort keys %$endedrow; - print DEBUG ".\n"; + @rows = @{ $hosts{$hostname} }; - push @rows, { %$jr, %$endedrow }; - } - - print DEBUG "FOUND ", (scalar @rows), " ROWS\n"; + print DEBUG "FOUND ", (scalar @rows), " ROWS for $hostname\n"; @rows = sort { $b->{finished} <=> $a->{finished} } @rows; $#rows = $limit-1 if @rows > $limit; @@ -251,8 +261,6 @@ $dbh_tests->do("SET LOCAL enable_seqscan=false"); # of the runvars table, rather than walking backwards through the # flights until it has what we've told it is enough. -our %hosts; - foreach my $host (@ARGV) { if ($host =~ m/^flight:/) { my $flight=$'; #'; @@ -265,16 +273,22 @@ foreach my $host (@ARGV) { END $hostsinflightq->execute($flight); while (my $row = $hostsinflightq->fetchrow_hashref()) { - $hosts{$row->{val}}++; + $hosts{$row->{val}} = [ ]; } }); } elsif ($host !~ m/:/) { - $hosts{$host}++; + $hosts{$host} = [ ]; } else { die "$host ?"; } } +exit 0 unless %hosts; + +db_retry($dbh_tests, [qw(flights)], sub { + mainquery(); +}); + foreach my $host (sort keys %hosts) { db_retry($dbh_tests, [qw(flights)], sub { reporthost $host; -- 1.7.10.4