Bug 1328398 - Add telemetry to measure service worker launch time. r=bkelly datareview=francois
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.
MozReview-Commit-ID: 3w5MNyhQNnd
--- 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());
+
+ // A probe to measure sw launch time for telemetry.
+ 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."
},