Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly, r?bsmedberg draft
authorTom Tung <shes050117@gmail.com>
Thu, 17 Aug 2017 18:32:36 +0800
changeset 650249 9a9ec2b5498fc4d6c16ec47f442daa6f21015302
parent 650247 50fd4bb9897fb179ceeca364b04469c19900cc60
child 727331 d96df9207d1d7633670a8dc73fff79513f9fb128
push id75305
push userttung@mozilla.com
push dateTue, 22 Aug 2017 02:57:18 +0000
reviewersbkelly, bsmedberg
bugs1328398
milestone57.0a1
Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly, r?bsmedberg This patch is mainly to add a probe to measure sw launch time. To do this, this patch records the sw launch time when the sw is just spwaned and it's ready to handle the incoming fetch event. (Note: we won't measure the case that the sw has already spwaned) 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
@@ -1505,16 +1505,25 @@ public:
 
   bool
   WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
   {
     MOZ_ASSERT(aWorkerPrivate);
 
     if (mMarkLaunchServiceWorkerEnd) {
       mInterceptedChannel->SetLaunchServiceWorkerEnd(TimeStamp::Now());
+
+      // Telemetry probe to measure sw launch time.
+      TimeStamp launchStartTime = TimeStamp();
+      mInterceptedChannel->GetLaunchServiceWorkerStart(&launchStartTime);
+
+      TimeStamp launchEndTime = TimeStamp();
+      mInterceptedChannel->GetLaunchServiceWorkerEnd(&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
@@ -102,19 +102,27 @@ interface nsIInterceptedChannel : nsISup
     readonly attribute nsIConsoleReportCollector consoleReportCollector;
 
     /**
      * Save the timestamps of various service worker interception phases.
      */
     [noscript]
     void SetLaunchServiceWorkerStart(in TimeStamp aTimeStamp);
 
+    // A hack to get sw launch start time for telemetry.
+    [noscript]
+    void GetLaunchServiceWorkerStart(out TimeStamp aTimeStamp);
+
     [noscript]
     void SetLaunchServiceWorkerEnd(in TimeStamp aTimeStamp);
 
+    // A hack to get sw launch end time for telemetry.
+    [noscript]
+    void GetLaunchServiceWorkerEnd(out TimeStamp aTimeStamp);
+
     [noscript]
     void SetDispatchFetchEventStart(in TimeStamp aTimeStamp);
 
     [noscript]
     void SetDispatchFetchEventEnd(in TimeStamp aTimeStamp);
 
     [noscript]
     void SetHandleFetchEventStart(in TimeStamp aTimeStamp);
--- a/netwerk/protocol/http/InterceptedChannel.h
+++ b/netwerk/protocol/http/InterceptedChannel.h
@@ -80,23 +80,39 @@ 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
+  GetLaunchServiceWorkerEnd(TimeStamp* aTimeStamp) override
+  {
+    MOZ_DIAGNOSTIC_ASSERT(aTimeStamp);
+    *aTimeStamp = mLaunchServiceWorkerEnd;
+    return NS_OK;
+  }
+
+  NS_IMETHODIMP
   SetDispatchFetchEventStart(TimeStamp aTimeStamp) override
   {
     mDispatchFetchEventStart = aTimeStamp;
     return NS_OK;
   }
 
   NS_IMETHODIMP
   SetDispatchFetchEventEnd(TimeStamp aTimeStamp) override
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -11028,16 +11028,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": "never",
+    "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."
   },