metrics: Capture usage times less than 5 minutes.

Since we only call UpdateStats on a fixed interval, we'll report
situations where a user uses their device for less than that fixed
interval as zero usage. This is misleading, so shorten just the initial
update interval to capture more cases where a user uses their device for
only a brief period.

BUG=chromium:1161319
TEST=deploy to DUT, verify first update happens after 1 minute

Fixed:chromium:1161319
Change-Id: I42243f0b64c8f5264cad99a025d1dccb7d5c0c09
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2601503
Commit-Queue: Miriam Zimmerman <mutexlox@chromium.org>
Tested-by: Miriam Zimmerman <mutexlox@chromium.org>
Reviewed-by: Michael Irani <michaelirani@google.com>
diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc
index a4c2e0a..9e94ecf 100644
--- a/metrics/metrics_daemon.cc
+++ b/metrics/metrics_daemon.cc
@@ -69,8 +69,12 @@
 const int kDaysPerWeek = 7;
 const int kSecondsPerWeek = kSecondsPerDay * kDaysPerWeek;
 
+// Initial interval until the first call to UpdateStats(), The initial update
+// happens sooner than subsequent updates to capture short usage times. (e.g.
+// situations where a user uses their device for 1-2 minutes only).
+const uint32_t kInitialUpdateStatsIntervalMs = 60'000;  // one minute
 // Interval between calls to UpdateStats().
-const uint32_t kUpdateStatsIntervalMs = 300000;
+const uint32_t kUpdateStatsIntervalMs = 300'000;  // five minutes
 
 // Maximum amount of system memory that will be reported without overflow.
 const int kMaximumMemorySizeInKB = 128 * 1024 * 1024;
@@ -491,7 +495,7 @@
       FROM_HERE,
       base::Bind(&MetricsDaemon::HandleUpdateStatsTimeout,
                  GET_THIS_FOR_POSTTASK()),
-      base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs));
+      base::TimeDelta::FromMilliseconds(kInitialUpdateStatsIntervalMs));
 
   // Emit a "0" value on start, to provide a baseline for this metric.
   SendLinearSample(kMetricCroutonStarted, 0, 2, 3);