Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly draft
authorTom Tung <shes050117@gmail.com>
Thu, 17 Aug 2017 18:32:36 +0800
changeset 648182 f44abe1c97ceeb9832117d07c34d8b8cc81e3199
parent 646284 2cc320aac603e3bc736d18a69e35a112704355b6
child 726739 7f0617e5bc11ec498d1f6bc892207f6398ed5760
push id74659
push userttung@mozilla.com
push dateThu, 17 Aug 2017 10:33:48 +0000
reviewersbkelly
bugs1328398
milestone57.0a1
Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly MozReview-Commit-ID: 3w5MNyhQNnd
dom/workers/ServiceWorkerPrivate.cpp
netwerk/base/nsINetworkInterceptController.idl
netwerk/protocol/http/InterceptedChannel.h
toolkit/components/telemetry/Histograms.json
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -1504,17 +1504,23 @@ public:
   }
 
   bool
   WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
   {
     MOZ_ASSERT(aWorkerPrivate);
 
     if (mMarkLaunchServiceWorkerEnd) {
-      mInterceptedChannel->SetLaunchServiceWorkerEnd(TimeStamp::Now());
+      TimeStamp launchStartTime = TimeStamp();
+      mInterceptedChannel->GetLaunchServiceWorkerStart(&launchStartTime);
+
+      TimeStamp launchEndTime = TimeStamp::Now();
+      mInterceptedChannel->SetLaunchServiceWorkerEnd(launchEndTime);
+      Telemetry::AccumulateTimeDelta(Telemetry::SERVICE_WORKER_LAUNCH_TIME,
+                                     launchStartTime, launchEndTime);
     }
 
     mInterceptedChannel->SetDispatchFetchEventEnd(TimeStamp::Now());
     return DispatchFetchEvent(aCx, aWorkerPrivate);
   }
 
   nsresult
   Cancel() override
--- a/netwerk/base/nsINetworkInterceptController.idl
+++ b/netwerk/base/nsINetworkInterceptController.idl
@@ -103,16 +103,19 @@ interface nsIInterceptedChannel : nsISup
 
     /**
      * Save the timestamps of various service worker interception phases.
      */
     [noscript]
     void SetLaunchServiceWorkerStart(in TimeStamp aTimeStamp);
 
     [noscript]
+    void GetLaunchServiceWorkerStart(out TimeStamp aTimeStamp);
+
+    [noscript]
     void SetLaunchServiceWorkerEnd(in TimeStamp aTimeStamp);
 
     [noscript]
     void SetDispatchFetchEventStart(in TimeStamp aTimeStamp);
 
     [noscript]
     void SetDispatchFetchEventEnd(in TimeStamp aTimeStamp);
 
--- a/netwerk/protocol/http/InterceptedChannel.h
+++ b/netwerk/protocol/http/InterceptedChannel.h
@@ -80,16 +80,24 @@ public:
   NS_IMETHODIMP
   SetLaunchServiceWorkerStart(TimeStamp aTimeStamp) override
   {
     mLaunchServiceWorkerStart = aTimeStamp;
     return NS_OK;
   }
 
   NS_IMETHODIMP
+  GetLaunchServiceWorkerStart(TimeStamp* aTimeStamp) override
+  {
+    MOZ_DIAGNOSTIC_ASSERT(aTimeStamp);
+    *aTimeStamp = mLaunchServiceWorkerStart;
+    return NS_OK;
+  }
+
+  NS_IMETHODIMP
   SetLaunchServiceWorkerEnd(TimeStamp aTimeStamp) override
   {
     mLaunchServiceWorkerEnd = aTimeStamp;
     return NS_OK;
   }
 
   NS_IMETHODIMP
   SetDispatchFetchEventStart(TimeStamp aTimeStamp) override
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -11150,16 +11150,27 @@
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 3,
     "description": "A value of 0 is sent when the security UI changes on pages loaded outside of Private Browsing mode, a value of 1 is sent when users manually disable TP on that page, and 2 is sent when users manually re-enable TP on that page.",
     "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
     "bug_numbers": [1058133]
   },
+  "SERVICE_WORKER_LAUNCH_TIME": {
+    "record_in_processes": ["main", "content"],
+    "expires_in_version": "61",
+    "bug_numbers": [1328398],
+    "kind": "exponential",
+    "high": 5000,
+    "n_buckets": 25,
+    "releaseChannelCollection": "opt-out",
+    "alert_emails": ["sw-telemetry@mozilla.com", "ttung@mozilla.com"],
+    "description": "Time (ms) for a service worker to start up."
+  },
   "SERVICE_WORKER_REGISTRATION_LOADING": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 5000,
     "n_buckets": 20,
     "description": "Tracking how ServiceWorkerRegistrar loads data before the first content is shown. File bugs in Core::DOM in case of a Telemetry regression."
   },