From 3fd3115e94638d96be3ac0ed65ec135dbee88418 Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Fri, 15 Dec 2017 14:35:44 +0800 Subject: [PATCH] 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 | 2 + .../base/nsINetworkInterceptController.idl | 39 +++++++++++++++++++ netwerk/protocol/http/InterceptedChannel.cpp | 21 +++++++++- .../protocol/http/InterceptedHttpChannel.cpp | 21 +++++++++- toolkit/components/telemetry/Scalars.yaml | 15 +++++++ 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 46e7cbb40dc0..e58316ad7af1 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -358,6 +358,8 @@ public: } if (!body) { mInternalResponse->GetUnfilteredBody(getter_AddRefs(body)); + } else { + Telemetry::ScalarAdd(Telemetry::ScalarID::SW_ALTERNATIVE_BODY_USED_COUNT, 1); } RefPtr copyHandle; diff --git a/netwerk/base/nsINetworkInterceptController.idl b/netwerk/base/nsINetworkInterceptController.idl index 03ea1dd47bac..65cb7aab2c85 100644 --- a/netwerk/base/nsINetworkInterceptController.idl +++ b/netwerk/base/nsINetworkInterceptController.idl @@ -14,7 +14,10 @@ interface nsIOutputStream; interface nsIURI; %{C++ +#include "nsContentUtils.h" +#include "nsIChannel.h" #include "nsIConsoleReportCollector.h" +#include "nsILoadInfo.h" namespace mozilla { class TimeStamp; @@ -184,6 +187,42 @@ interface nsIInterceptedChannel : nsISupports GetConsoleReportCollector(getter_AddRefs(reporter)); return reporter.forget(); } + + void + GetSubresourceTimeStampKey(nsIChannel* aChannel, nsACString& aKey) + { + if (!nsContentUtils::IsNonSubresourceRequest(aChannel)) { + nsCOMPtr 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; + } + } + } + } + } %} /** diff --git a/netwerk/protocol/http/InterceptedChannel.cpp b/netwerk/protocol/http/InterceptedChannel.cpp index 83e788976669..fbaebe2ed1fc 100644 --- a/netwerk/protocol/http/InterceptedChannel.cpp +++ b/netwerk/protocol/http/InterceptedChannel.cpp @@ -169,9 +169,13 @@ InterceptedChannelBase::SaveTimeStamps() 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()) { @@ -182,16 +186,31 @@ InterceptedChannelBase::SaveTimeStamps() Telemetry::SERVICE_WORKER_FETCH_EVENT_CHANNEL_RESET_MS; Telemetry::Accumulate(id, navigationOrSubresource, static_cast((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(id, subresourceKey, + static_cast((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds())); + } } Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS, navigationOrSubresource, static_cast((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS, + subresourceKey, + static_cast((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds())); + } + if (!mFinishResponseEnd.IsNull()) { Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS, navigationOrSubresource, static_cast((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS, + subresourceKey, + static_cast((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds())); + } } return rv; diff --git a/netwerk/protocol/http/InterceptedHttpChannel.cpp b/netwerk/protocol/http/InterceptedHttpChannel.cpp index 63b1d784b1e0..c7fdd26de3e3 100644 --- a/netwerk/protocol/http/InterceptedHttpChannel.cpp +++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp @@ -944,9 +944,13 @@ InterceptedHttpChannel::SetChannelResetEnd(mozilla::TimeStamp aTimeStamp) 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()) { @@ -955,16 +959,31 @@ InterceptedHttpChannel::SaveTimeStamps(void) Telemetry::SERVICE_WORKER_FETCH_EVENT_CHANNEL_RESET_MS; Telemetry::Accumulate(id, navigationOrSubresource, static_cast((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(id, subresourceKey, + static_cast((mFinishResponseEnd - mFinishResponseStart).ToMilliseconds())); + } } Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS, navigationOrSubresource, static_cast((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_EVENT_DISPATCH_MS, + subresourceKey, + static_cast((mHandleFetchEventStart - mDispatchFetchEventStart).ToMilliseconds())); + } + if (!mFinishResponseEnd.IsNull()) { Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS, navigationOrSubresource, static_cast((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds())); + if (!isNonSubresourceRequest && !subresourceKey.IsEmpty()) { + Telemetry::Accumulate(Telemetry::SERVICE_WORKER_FETCH_INTERCEPTION_DURATION_MS, + subresourceKey, + static_cast((mFinishResponseEnd - mDispatchFetchEventStart).ToMilliseconds())); + } } return NS_OK; diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index c8b471bbb9f7..a00d910873ca 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -1359,6 +1359,21 @@ sw: - '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: