Bug 1514392 - Use fallback process start time, even if inconsistent r=wlach,chutten
authorJan-Erik Rediger <jrediger@mozilla.com>
Thu, 14 Feb 2019 16:02:12 +0000
changeset 459160 085bd7c16f996a385a15984170e8f75af51f58f6
parent 459159 f2b5a9d987e8ea8a38bebd32f68d5cb04247580f
child 459161 8d5ede86ee6e538ef5154a64d8bc20eff4e057e0
push id35556
push userdvarga@mozilla.com
push dateFri, 15 Feb 2019 01:38:24 +0000
treeherdermozilla-central@b29c87add05f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswlach, chutten
bugs1514392
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1514392 - Use fallback process start time, even if inconsistent r=wlach,chutten Differential Revision: https://phabricator.services.mozilla.com/D19645
toolkit/components/telemetry/Scalars.yaml
toolkit/components/telemetry/app/TelemetryUtils.jsm
toolkit/components/telemetry/core/TelemetryCommon.cpp
toolkit/components/telemetry/docs/data/main-ping.rst
toolkit/components/telemetry/pings/TelemetrySession.jsm
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -1801,16 +1801,30 @@ telemetry:
     expires: "70"
     kind: uint
     notification_emails:
       - chutten@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
 
+  process_creation_timestamp_inconsistent:
+    bug_numbers:
+      - 1514392
+    description: >
+      The number of times ProcessCreation saw an inconsistent value.
+    expires: "72"
+    kind: uint
+    notification_emails:
+      - jrediger@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+      - 'content'
+
 telemetry.discarded:
   accumulations:
     bug_numbers:
       - 1369041
     description: >
       Number of discarded accumulations to histograms in child processes
     expires: "never"
     kind: uint
--- a/toolkit/components/telemetry/app/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/app/TelemetryUtils.jsm
@@ -212,21 +212,17 @@ var TelemetryUtils = {
       + ":" + padNumber(Math.abs(tzOffset % 60), 2);
   },
 
   /**
    * @returns {number} The monotonic time since the process start
    * or (non-monotonic) Date value if this fails back.
    */
   monotonicNow() {
-    try {
-      return Services.telemetry.msSinceProcessStart();
-    } catch (ex) {
-      return Date.now();
-    }
+    return Services.telemetry.msSinceProcessStart();
   },
 
   /**
    * Set the Telemetry core recording flag for Unified Telemetry.
    */
   setTelemetryRecordingFlags() {
     // Enable extended Telemetry on pre-release channels and disable it
     // on Release/ESR.
--- a/toolkit/components/telemetry/core/TelemetryCommon.cpp
+++ b/toolkit/components/telemetry/core/TelemetryCommon.cpp
@@ -9,16 +9,17 @@
 #include <cstring>
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Preferences.h"
 #include "nsIConsoleService.h"
 #include "nsITelemetry.h"
 #include "nsThreadUtils.h"
 #include "nsVersionComparator.h"
 #include "TelemetryProcessData.h"
+#include "Telemetry.h"
 
 namespace mozilla {
 namespace Telemetry {
 namespace Common {
 
 bool IsExpiredVersion(const char* aExpiration) {
   MOZ_ASSERT(aExpiration);
   // Note: We intentionally don't construct a static Version object here as we
@@ -78,21 +79,25 @@ bool CanRecordInProcess(RecordedProcessT
   return CanRecordInProcess(processes, GetGeckoProcessType(processId));
 }
 
 bool CanRecordProduct(SupportedProduct aProducts) {
   return !!(aProducts & GetCurrentProduct());
 }
 
 nsresult MsSinceProcessStart(double* aResult) {
-  bool error;
-  *aResult = (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation(&error))
-                 .ToMilliseconds();
-  if (error) {
-    return NS_ERROR_NOT_AVAILABLE;
+  bool isInconsistent = false;
+  *aResult =
+      (TimeStamp::NowLoRes() - TimeStamp::ProcessCreation(&isInconsistent))
+          .ToMilliseconds();
+
+  if (isInconsistent) {
+    Telemetry::ScalarAdd(
+        Telemetry::ScalarID::TELEMETRY_PROCESS_CREATION_TIMESTAMP_INCONSISTENT,
+        1);
   }
   return NS_OK;
 }
 
 void LogToBrowserConsole(uint32_t aLogLevel, const nsAString& aMsg) {
   if (!NS_IsMainThread()) {
     nsString msg(aMsg);
     nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
--- a/toolkit/components/telemetry/docs/data/main-ping.rst
+++ b/toolkit/components/telemetry/docs/data/main-ping.rst
@@ -81,33 +81,29 @@ info
 ----
 
 sessionLength
 ~~~~~~~~~~~~~
 The length of the current session so far in seconds.
 This uses a monotonic clock, so this may mismatch with other measurements that
 are not monotonic like calculations based on ``Date.now()``.
 
-If the monotonic clock failed, this will be ``-1``.
-
 Note that this currently does not behave consistently over our supported platforms:
 
 * On Windows this uses ``GetTickCount64()``, which does increase over sleep periods
 * On macOS this uses ``mach_absolute_time()``, which does not increase over sleep periods
 * On POSIX/Linux this uses ``clock_gettime(CLOCK_MONOTONIC, &ts)``, which should not increase over sleep time
 
 See `bug 1204823 <https://bugzilla.mozilla.org/show_bug.cgi?id=1204823>`_ for details.
 
 subsessionLength
 ~~~~~~~~~~~~~~~~
 The length of this subsession in seconds.
 This uses a monotonic clock, so this may mismatch with other measurements that are not monotonic (e.g. based on ``Date.now()``).
 
-If ``sessionLength`` is ``-1``, the monotonic clock is not working.
-
 Also see the remarks for ``sessionLength`` on platform consistency.
 
 processes
 ---------
 This section contains per-process data.
 
 Structure:
 
--- a/toolkit/components/telemetry/pings/TelemetrySession.jsm
+++ b/toolkit/components/telemetry/pings/TelemetrySession.jsm
@@ -83,31 +83,22 @@ XPCOMUtils.defineLazyServiceGetters(this
 });
 
 function generateUUID() {
   let str = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString();
   // strip {}
   return str.substring(1, str.length - 1);
 }
 
-function getMsSinceProcessStart() {
-  try {
-    return Telemetry.msSinceProcessStart();
-  } catch (ex) {
-    // If this fails return a special value.
-    return -1;
-  }
-}
-
 /**
  * This is a policy object used to override behavior for testing.
  */
 var Policy = {
   now: () => new Date(),
-  monotonicNow: getMsSinceProcessStart,
+  monotonicNow: Utils.monotonicNow,
   generateSessionUUID: () => generateUUID(),
   generateSubsessionUUID: () => generateUUID(),
   setSchedulerTickTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
   clearSchedulerTickTimeout: id => clearTimeout(id),
   prioEncode: (batchID, prioParams) => PrioEncoder.encode(batchID, prioParams),
 };
 
 /**