Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly, f?bsmedberg draft
authorTom Tung <shes050117@gmail.com>
Thu, 17 Aug 2017 18:32:36 +0800
changeset 650248 9bf9368c50e1460309429e7615519b9a5af2a118
parent 650247 50fd4bb9897fb179ceeca364b04469c19900cc60
child 727330 16eb2280bfcabe0e4283077656ba1bb19c478232
push id75304
push userttung@mozilla.com
push dateTue, 22 Aug 2017 02:40:58 +0000
reviewersbkelly
bugs1328398
milestone57.0a1
Bug 1328398 - Add telemetry to measure service worker launch time. r?bkelly, f?bsmedberg This patch is mainly to add a probe to measure sw launch time. To do this, we record the sw launch time when the sw is spwaned and it's ready to handle the fetch event. 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
@@ -1706,16 +1715,25 @@ ServiceWorkerPrivate::SendFetchEvent(nsI
   nsresult rv = SpawnWorkerIfNeeded(FetchEvent,
                                     failRunnable,
                                     &newWorkerCreated,
                                     aLoadGroup);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!newWorkerCreated) {
     aChannel->SetLaunchServiceWorkerEnd(TimeStamp::Now());
+
+    // Telemetry probe to measure sw launch time.
+    TimeStamp launchStartTime = TimeStamp();
+    aChannel->GetLaunchServiceWorkerStart(&launchStartTime);
+
+    TimeStamp launchEndTime = TimeStamp();
+    aChannel->GetLaunchServiceWorkerEnd(&launchEndTime);
+    Telemetry::AccumulateTimeDelta(Telemetry::SERVICE_WORKER_LAUNCH_TIME,
+                                   launchStartTime, launchEndTime);
   }
 
   nsMainThreadPtrHandle<nsIInterceptedChannel> handle(
     new nsMainThreadPtrHolder<nsIInterceptedChannel>(
       "nsIInterceptedChannel", aChannel, false));
 
   nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> regInfo(
     new nsMainThreadPtrHolder<ServiceWorkerRegistrationInfo>(
--- 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."
   },