Bug 1423623 - Add telemetry for alternate data stream on service worker synthesized channels. r=bkelly, data-r=francois
authorEden Chuang <echuang@mozilla.com>
Fri, 15 Dec 2017 14:35:44 +0800
changeset 448870 5a50adabbb1171a696f4c24abd976492e8f84ed8
parent 448869 1f7837e3840d2e1738200c22f8be3b3118fe84b1
child 448871 c6297aca62a422e4a8988a9a8b186e22d737aa99
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1423623
milestone59.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 1423623 - Add telemetry for alternate data stream on service worker synthesized channels. r=bkelly, data-r=francois 1. Create a new telemetry scalar SW_ALTERNATIVE_BODY_USED_COUNT to count the number of the alternative body used in service worker synthesized channels. 2. To report values of fetching related time of InterceptChannel according to the detail subresource type. Now subresource/script, subresource/other, subresource/image and subresource/stylesheet are provided, and keep using subresource for other types.
dom/workers/ServiceWorkerEvents.cpp
netwerk/base/nsINetworkInterceptController.idl
netwerk/protocol/http/InterceptedChannel.cpp
netwerk/protocol/http/InterceptedHttpChannel.cpp
toolkit/components/telemetry/Scalars.yaml
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -353,16 +353,18 @@ public:
     }
 
      nsCOMPtr<nsIInputStream> body;
     if (preferredAltDataType.Equals(altDataType)) {
       body = mInternalResponse->TakeAlternativeBody();
     }
     if (!body) {
       mInternalResponse->GetUnfilteredBody(getter_AddRefs(body));
+    } else {
+      Telemetry::ScalarAdd(Telemetry::ScalarID::SW_ALTERNATIVE_BODY_USED_COUNT, 1);
     }
 
     RefPtr<BodyCopyHandle> copyHandle;
     copyHandle = new BodyCopyHandle(Move(mClosure));
 
     rv = mChannel->StartSynthesizedResponse(body, copyHandle, cacheInfoChannel,
                                             mResponseURLSpec,
                                             mInternalResponse->IsRedirected());
--- a/netwerk/base/nsINetworkInterceptController.idl
+++ b/netwerk/base/nsINetworkInterceptController.idl
@@ -9,17 +9,20 @@
 interface nsICacheInfoChannel;
 interface nsIChannel;
 interface nsIConsoleReportCollector;
 interface nsIInputStream;
 interface nsIOutputStream;
 interface nsIURI;
 
 %{C++
+#include "nsContentUtils.h"
+#include "nsIChannel.h"
 #include "nsIConsoleReportCollector.h"
+#include "nsILoadInfo.h"
 namespace mozilla {
 class TimeStamp;
 
 namespace dom {
 class ChannelInfo;
 }
 }
 %}
@@ -179,16 +182,52 @@ interface nsIInterceptedChannel : nsISup
 %{C++
     already_AddRefed<nsIConsoleReportCollector>
     GetConsoleReportCollector()
     {
       nsCOMPtr<nsIConsoleReportCollector> reporter;
       GetConsoleReportCollector(getter_AddRefs(reporter));
       return reporter.forget();
     }
+
+    void
+    GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey)
+    {
+      if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) {
+        nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+        if (loadInfo) {
+          switch(loadInfo->InternalContentPolicyType()) {
+            case nsIContentPolicy::TYPE_SCRIPT:
+            case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
+            case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
+            case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS: {
+              aKey = NS_LITERAL_CSTRING("subresource-script");
+              break;
+            }
+            case nsIContentPolicy::TYPE_IMAGE:
+            case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
+            case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
+            case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON: {
+              aKey = NS_LITERAL_CSTRING("subresource-image");
+              break;
+            }
+            case nsIContentPolicy::TYPE_STYLESHEET:
+            case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
+            case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD: {
+              aKey = NS_LITERAL_CSTRING("subresource-stylesheet");
+              break;
+            }
+            default: {
+              aKey = NS_LITERAL_CSTRING("subresource-other");
+              break;
+            }
+          }
+        }
+      }
+    }
 %}
 
     /**
      * Allow the ServiceWorkerManager to set an RAII-style object on the
      * intercepted channel that should be released once the channel is
      * torn down.
      */
     [noscript]
--- a/netwerk/protocol/http/InterceptedChannel.cpp
+++ b/netwerk/protocol/http/InterceptedChannel.cpp
@@ -164,39 +164,58 @@ InterceptedChannelBase::SaveTimeStamps()
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   nsCOMPtr<nsIChannel> channel;
   GetChannel(getter_AddRefs(channel));
   if (NS_WARN_IF(!channel)) {
     return NS_ERROR_FAILURE;
   }
 
-  nsCString navigationOrSubresource = nsContentUtils::IsNonSubresourceRequest(channel) ?
+  bool isNonSubresourceRequest = nsContentUtils::IsNonSubresourceRequest(channel);
+  nsCString navigationOrSubresource = isNonSubresourceRequest ?
     NS_LITERAL_CSTRING("navigation") : NS_LITERAL_CSTRING("subresource");
 
+  nsAutoCString subresourceKey(EmptyCString());
+  GetSubresourceTimeStampKey(channel, subresourceKey);
+
   // We may have null timestamps if the fetch dispatch runnable was cancelled
   // and we defaulted to resuming the request.
   if (!mFinishResponseStart.IsNull() && !mFinishResponseEnd.IsNull()) {
     MOZ_ASSERT(mSynthesizedOrReset != Invalid);
 
     Telemetry::HistogramID id = (mSynthesizedOrReset == Synthesized) ?
       Telemetry::SERVICE_WORKER_FETCH_EVENT_FINISH_SYNTHESIZED_RESPONSE_MS :
       Telemetry::SERVICE_WORKER_FETCH_EVENT_CHANNEL_RESET_MS;
     Telemetry::Accumulate(id, navigationOrSubresource,
       static_cast<uint32_t>((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds()));
+    if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+      Telemetry::Accumulate(id, subresourceKey,
+        static_cast<uint32_t>((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds()));
+    }
   }
 
   Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS,
     navigationOrSubresource,
     static_cast<uint32_t>((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds()));
 
+  if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+    Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS,
+      subresourceKey,
+      static_cast<uint32_t>((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds()));
+  }
+
   if (!mFinishResponseEnd.IsNull()) {
     Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS,
       navigationOrSubresource,
       static_cast<uint32_t>((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds()));
+    if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+      Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS,
+        subresourceKey,
+        static_cast<uint32_t>((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds()));
+    }
   }
 
   return rv;
 }
 
 /* static */
 already_AddRefed<nsIURI>
 InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
--- a/netwerk/protocol/http/InterceptedHttpChannel.cpp
+++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp
@@ -939,37 +939,56 @@ InterceptedHttpChannel::SetChannelResetE
   mSynthesizedOrReset = Reset;
   mFinishResponseEnd = aTimeStamp;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedHttpChannel::SaveTimeStamps(void)
 {
-  nsCString navigationOrSubresource = nsContentUtils::IsNonSubresourceRequest(this) ?
+  bool isNonSubresourceRequest = nsContentUtils::IsNonSubresourceRequest(this);
+  nsCString navigationOrSubresource = isNonSubresourceRequest ?
     NS_LITERAL_CSTRING("navigation") : NS_LITERAL_CSTRING("subresource");
 
+  nsAutoCString subresourceKey(EmptyCString());
+  GetSubresourceTimeStampKey(this, subresourceKey);
+
   // We may have null timestamps if the fetch dispatch runnable was cancelled
   // and we defaulted to resuming the request.
   if (!mFinishResponseStart.IsNull() && !mFinishResponseEnd.IsNull()) {
     Telemetry::HistogramID id = (mSynthesizedOrReset == Synthesized) ?
       Telemetry::SERVICE_WORKER_FETCH_EVENT_FINISH_SYNTHESIZED_RESPONSE_MS :
       Telemetry::SERVICE_WORKER_FETCH_EVENT_CHANNEL_RESET_MS;
     Telemetry::Accumulate(id, navigationOrSubresource,
       static_cast<uint32_t>((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds()));
+    if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+      Telemetry::Accumulate(id, subresourceKey,
+        static_cast<uint32_t>((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds()));
+    }
   }
 
   Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS,
     navigationOrSubresource,
     static_cast<uint32_t>((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds()));
 
+  if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+    Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS,
+      subresourceKey,
+      static_cast<uint32_t>((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds()));
+  }
+
   if (!mFinishResponseEnd.IsNull()) {
     Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS,
       navigationOrSubresource,
       static_cast<uint32_t>((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds()));
+    if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) {
+      Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS,
+        subresourceKey,
+        static_cast<uint32_t>((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds()));
+    }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedHttpChannel::SetReleaseHandle(nsISupports* aHandle)
 {
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -1354,16 +1354,31 @@ sw:
     notification_emails:
       - sw-telemetry@mozilla.com
       - ttung@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
       - 'content'
 
+  alternative_body_used_count:
+    bug_numbers:
+      - 1423623
+    description: >
+      The count of number of synthesize response using alternative body.
+    expires: "61"
+    kind: uint
+    notification_emails:
+      - sw-telemetry@mozilla.com
+      - echuang@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+      - 'content'
+
 # The following section is for probes testing the Telemetry system. They will not be
 # submitted in pings and are only used for testing.
 telemetry.test:
   unsigned_int_kind:
     bug_numbers:
       - 1276190
     description: >
       This is a test uint type with a really long description, maybe spanning even multiple