Bug 1430635 - Add telemetry to track how often preloaded scripts are used. r=baku, data-review=liuche
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 17 Jan 2018 03:10:00 -0500
changeset 451763 f3dd2335e142f8effc6e80431a249943b5dbd221
parent 451762 677044553e310232b82294cdf1d7b72f7fe07d20
child 451764 8a880591214558414d6a1c6a87280d65feb9dabf
push id8560
push userryanvm@gmail.com
push dateFri, 19 Jan 2018 16:34:00 +0000
treeherdermozilla-beta@4c9965a3b8a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1430635
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 1430635 - Add telemetry to track how often preloaded scripts are used. r=baku, data-review=liuche
dom/script/ScriptLoader.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -60,16 +60,18 @@
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Unused.h"
 #include "nsIScriptError.h"
 #include "nsIOutputStream.h"
 
 using JS::SourceBufferHolder;
 
+using mozilla::Telemetry::LABELS_DOM_SCRIPT_PRELOAD_RESULT;
+
 namespace mozilla {
 namespace dom {
 
 LazyLogModule ScriptLoader::gCspPRLog("CSP");
 LazyLogModule ScriptLoader::gScriptLoaderLog("ScriptLoader");
 
 #undef LOG
 #define LOG(args) \
@@ -175,16 +177,20 @@ ScriptLoader::~ScriptLoader()
     req->FireScriptAvailable(NS_ERROR_ABORT);
   }
 
   // Unblock the kids, in case any of them moved to a different document
   // subtree in the meantime and therefore aren't actually going away.
   for (uint32_t j = 0; j < mPendingChildLoaders.Length(); ++j) {
     mPendingChildLoaders[j]->RemoveParserBlockingScriptExecutionBlocker();
   }
+
+  for (size_t i = 0; i < mPreloads.Length(); i++) {
+    AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::NotUsed);
+  }
 }
 
 // Collect telemtry data about the cache information, and the kind of source
 // which are being loaded, and where it is being loaded from.
 static void
 CollectScriptTelemetry(nsIIncrementalStreamLoader* aLoader,
                        ScriptLoadRequest* aRequest)
 {
@@ -1318,26 +1324,29 @@ ScriptLoader::ProcessExternalScript(nsIS
 
   RefPtr<ScriptLoadRequest> request = LookupPreloadRequest(aElement, aScriptKind);
 
   if (request && NS_FAILED(CheckContentPolicy(mDocument, aElement, request->mURI,
                                               aTypeAttr, false))) {
     // Probably plans have changed; even though the preload was allowed seems
     // like the actual load is not; let's cancel the preload request.
     request->Cancel();
+    AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::RejectedByPolicy);
     return false;
   }
 
   if (request) {
     // Use the preload request.
 
     // It's possible these attributes changed since we started the preload so
     // update them here.
     request->SetScriptMode(aElement->GetScriptDeferred(),
                            aElement->GetScriptAsync());
+
+    AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::Used);
   } else {
     // No usable preload found.
 
     SRIMetadata sriMetadata;
     {
       nsAutoString integrity;
       aScriptContent->AsElement()->GetAttr(kNameSpaceID_None,
                                           nsGkAtoms::integrity,
@@ -1583,16 +1592,17 @@ ScriptLoader::LookupPreloadRequest(nsISc
   // we have now.
   nsAutoString elementCharset;
   aElement->GetScriptCharset(elementCharset);
   if (!elementCharset.Equals(preloadCharset) ||
       aElement->GetCORSMode() != request->mCORSMode ||
       mDocument->GetReferrerPolicy() != request->mReferrerPolicy ||
       aScriptKind != request->mKind) {
     // Drop the preload.
+    AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::RequestMismatch);
     return nullptr;
   }
 
   return request;
 }
 
 void
 ScriptLoader::GetSRIMetadata(const nsAString& aIntegrityAttr,
@@ -2959,16 +2969,17 @@ ScriptLoader::HandleLoadError(ScriptLoad
     nsCOMPtr<nsIScriptElement> oldParserInsertedScript =
       mCurrentParserInsertedScript;
     mCurrentParserInsertedScript = aRequest->mElement;
     FireScriptAvailable(aResult, aRequest);
     ContinueParserAsync(aRequest);
     mCurrentParserInsertedScript = oldParserInsertedScript;
   } else {
     mPreloads.RemoveElement(aRequest, PreloadRequestComparator());
+    AccumulateCategorical(LABELS_DOM_SCRIPT_PRELOAD_RESULT::LoadError);
   }
 }
 
 void
 ScriptLoader::UnblockParser(ScriptLoadRequest* aParserBlockingRequest)
 {
   aParserBlockingRequest->mElement->UnblockParser();
 }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -12606,16 +12606,25 @@
     "expires_in_version": "62",
     "kind": "linear",
     "low": 1,
     "high": 200,
     "n_buckets": 50,
     "bug_numbers": [1362114],
     "description": "Number of script tags evaluated per document."
   },
+  "DOM_SCRIPT_PRELOAD_RESULT": {
+    "record_in_processes": ["main", "content"],
+    "alert_emails": ["jcoppeard@mozilla.com"],
+    "expires_in_version": "63",
+    "kind": "categorical",
+    "bug_numbers": [1430145],
+    "labels": ["Used", "RejectedByPolicy", "RequestMismatch", "LoadError", "NotUsed"],
+    "description": "Whether a preloaded script was used or the reason it was not used."
+  },
   "VIDEO_FASTSEEK_USED": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["cpearce@mozilla.com", "tkuo@mozilla.com"],
     "expires_in_version": "60",
     "bug_numbers": [1245982],
     "kind": "count",
     "description": "Uses of HTMLMediaElement.fastSeek"
   },