]> xenbits.xensource.com Git - people/liuw/osstest.git/commitdiff
duration_estimator: Be able to estimate job duration up to a particular step
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 10 Aug 2016 16:10:39 +0000 (17:10 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 11 Aug 2016 16:04:04 +0000 (17:04 +0100)
If this is passed, we are interested only in the duration up to and
including the specified test step.  (If the specified test step is not
present or didn't have a recorded finish, we look at the whole job.)

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Osstest/Executive.pm

index 10fdc8de395c41a42715ab5cfa131e8714bd4a36..7e31b35a01880398f068e38ced22c5de66e790cd 100644 (file)
@@ -1012,16 +1012,21 @@ END
 
 #---------- duration estimator ----------
 
-sub duration_estimator ($$;$) {
-    my ($branch, $blessing, $debug) = @_;
+sub duration_estimator ($$;$$) {
+    my ($branch, $blessing, $debug, $will_uptoincl_testid) = @_;
     # returns a function which you call like this
-    #    $durest->($job, $hostidname, $onhost)
+    #    $durest->($job, $hostidname, $onhost [, $uptoincl_testid])
     # and returns one of
     #    ($seconds, $samehostlaststarttime, $samehostlaststatus)
     #    ($seconds, undef, undef)
     #    ()
     # $debug should be something like sub { print DEBUG "@_\n"; }.
     # Pass '' for $hostidname and $onhost for asking about on any host
+    #
+    # $uptincl_testid must be passed iff $will_uptoincl_testid, in
+    # which case the duration up to and including that step will be
+    # estimated (and only jobs which contained that step will be
+    # considered).
 
     my $recentflights_q= $dbh_tests->prepare(<<END);
             SELECT f.flight AS flight,
@@ -1068,11 +1073,20 @@ END
               FROM tsteps
              WHERE step != 'ts-hosts-allocate'
 END
+
+    if ($will_uptoincl_testid) {
+       $duration_duration_qtxt .= <<END;
+               AND finished <=
+                     (SELECT finished
+                        FROM tsteps
+                       WHERE tsteps.testid = ?)
+END
+    }
        
     my $duration_duration_q = $dbh_tests->prepare($duration_duration_qtxt);
 
     return sub {
-        my ($job, $hostidname, $onhost) = @_;
+        my ($job, $hostidname, $onhost, $uptoincl_testid) = @_;
 
         my $dbg= $debug ? sub {
             $debug->("DUR $branch $blessing $job $hostidname $onhost @_");
@@ -1108,6 +1122,7 @@ END
         my $duration_max= 0;
         foreach my $ref (@$refs) {
            my @d_d_args = ($ref->{flight}, $job);
+           push @d_d_args, $uptoincl_testid if $will_uptoincl_testid;
             $duration_duration_q->execute(@d_d_args);
             my ($duration) = $duration_duration_q->fetchrow_array();
             $duration_duration_q->finish();