[PATCH 2/3] testbot: Allow restricting the activity analysis to the recent past.

Francois Gouget fgouget at codeweavers.com
Mon Jan 22 22:33:59 CST 2018


GetActivity() now takes the number of seconds of recent activity to
analyze and uses it to limit the number of records and record groups
that are retrieved from the database. This can greatly speed up the
analysis.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
 testbot/lib/WineTestBot/Activity.pm | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/testbot/lib/WineTestBot/Activity.pm b/testbot/lib/WineTestBot/Activity.pm
index 58169aee..ba1dbb6f 100644
--- a/testbot/lib/WineTestBot/Activity.pm
+++ b/testbot/lib/WineTestBot/Activity.pm
@@ -43,8 +43,8 @@ require Exporter;
 
 =item C<GetActivity()>
 
-Loads the records for the specified VMs and processes them to build a structure
-describing the TestBot activity.
+Loads the records for the specified VMs going back the specified number of
+seconds and processes them to build a structure describing the TestBot activity.
 
 Returns a list of the activity records, sorted from the oldest to the newest.
 Each entry contains a structure grouping all the state and event information
@@ -90,19 +90,31 @@ that were processed.
 =back
 =cut
 
-sub GetActivity($)
+sub GetActivity($;$)
 {
-  my ($VMs) = @_;
+  my ($VMs, $Seconds) = @_;
   my ($ActivityHash, $Activity, $Counters) = ({}, [], {});
 
   ### First load all the RecordGroups
   my $RecordGroups = CreateRecordGroups();
+  if ($Seconds)
+  {
+    $RecordGroups->AddFilter("Timestamp", [time() - $Seconds], ">=");
+  }
+  my $MinId;
   $Counters->{recordgroups} = $RecordGroups->GetItemsCount();
   foreach my $RecordGroup (sort CompareRecordGroups @{$RecordGroups->GetItems()})
   {
     my $Group = { start => $RecordGroup->Timestamp };
     $ActivityHash->{$RecordGroup->Id} = $Group;
     push @$Activity, $Group;
+    $MinId = $RecordGroup->Id if (!defined $MinId or $RecordGroup->Id < $MinId);
+  }
+  if (!defined $MinId)
+  {
+    # No activity was found in the specified period
+    $Counters->{records} = 0;
+    return ($Activity, $Counters);
   }
 
   ### And then load all the Records in one go
@@ -111,6 +123,7 @@ sub GetActivity($)
 
   my $Jobs = CreateJobs();
   my $Records = CreateRecords();
+  $Records->AddFilter("RecordGroupId", [$MinId], ">=");
   $Counters->{records} = $Records->GetItemsCount();
   foreach my $Record (@{$Records->GetItems()})
   {
-- 
2.15.1




More information about the wine-devel mailing list