bug 1431868 Handle AutoTimer users passing us future values for start. r?Dexter draft
authorChris H-C <chutten@mozilla.com>
Tue, 23 Jan 2018 14:30:13 -0500
changeset 723784 d6ba83e0d3ec2d30c9765960dc8f9b3a28542396
parent 723720 94057f351ba94b31e1b5a56fefdfe9d8e43d0e5d
child 746942 3a45ef4f7a7f76912bdd1741f516e45e48587134
push id96520
push userbmo:chutten@mozilla.com
push dateTue, 23 Jan 2018 19:32:44 +0000
reviewersDexter
bugs1431868
milestone60.0a1
bug 1431868 Handle AutoTimer users passing us future values for start. r?Dexter UBSan found some cases where people are setting the Telemetry AutoTimer values of `start` that are in the future. Not a problem if the value for `end` is further in the future... which it isn't always. Let's normalize those cases to 0, shall we? MozReview-Commit-ID: 7AdTMf2rss6
toolkit/components/telemetry/Telemetry.h
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -179,30 +179,46 @@ struct AccumulateDelta_impl
   static void compute(HistogramID id, TimeStamp start, TimeStamp end = TimeStamp::Now());
   static void compute(HistogramID id, const nsCString& key, TimeStamp start, TimeStamp end = TimeStamp::Now());
 };
 
 template<>
 struct AccumulateDelta_impl<Millisecond>
 {
   static void compute(HistogramID id, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
+    if (start > end) {
+      Accumulate(id, 0);
+      return;
+    }
     Accumulate(id, static_cast<uint32_t>((end - start).ToMilliseconds()));
   }
   static void compute(HistogramID id, const nsCString& key, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
+    if (start > end) {
+      Accumulate(id, key, 0);
+      return;
+    }
     Accumulate(id, key, static_cast<uint32_t>((end - start).ToMilliseconds()));
   }
 };
 
 template<>
 struct AccumulateDelta_impl<Microsecond>
 {
   static void compute(HistogramID id, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
+    if (start > end) {
+      Accumulate(id, 0);
+      return;
+    }
     Accumulate(id, static_cast<uint32_t>((end - start).ToMicroseconds()));
   }
   static void compute(HistogramID id, const nsCString& key, TimeStamp start, TimeStamp end = TimeStamp::Now()) {
+    if (start > end) {
+      Accumulate(id, key, 0);
+      return;
+    }
     Accumulate(id, key, static_cast<uint32_t>((end - start).ToMicroseconds()));
   }
 };
 
 
 template<HistogramID id, TimerResolution res = Millisecond>
 class MOZ_RAII AutoTimer {
 public: