Bug 1409542 part 2 - telemetry on why a resource marked prefetchable is not prefetched.
MozReview-Commit-ID: AFJnbTjU5Ju
--- a/netwerk/base/Predictor.cpp
+++ b/netwerk/base/Predictor.cpp
@@ -1322,54 +1322,96 @@ Predictor::CalculatePredictions(nsICache
}
int32_t confidence = CalculateConfidence(hitCount, loadCount, lastHit,
lastLoad, globalDegradation);
if (fullUri) {
UpdateRollingLoadCount(entry, flags, key, hitCount, lastHit);
}
PREDICTOR_LOG(("CalculatePredictions key=%s value=%s confidence=%d", key, value, confidence));
+ PrefetchIgnoreReason reason = PREFETCH_OK;
if (!fullUri) {
// Not full URI - don't prefetch! No sense in it!
PREDICTOR_LOG((" forcing non-cacheability - not full URI"));
+ if (flags & FLAG_PREFETCHABLE) {
+ // This only applies if we had somehow otherwise marked this
+ // prefetchable.
+ reason = NOT_FULL_URI;
+ }
flags &= ~FLAG_PREFETCHABLE;
} else if (!referrer) {
// No referrer means we can't prefetch, so pretend it's non-cacheable,
// no matter what.
PREDICTOR_LOG((" forcing non-cacheability - no referrer"));
+ if (flags & FLAG_PREFETCHABLE) {
+ // This only applies if we had somehow otherwise marked this
+ // prefetchable.
+ reason = NO_REFERRER;
+ }
flags &= ~FLAG_PREFETCHABLE;
} else {
uint32_t expectedRollingLoadCount = (1 << mPrefetchRollingLoadCount) - 1;
expectedRollingLoadCount <<= kRollingLoadOffset;
if ((flags & expectedRollingLoadCount) != expectedRollingLoadCount) {
PREDICTOR_LOG((" forcing non-cacheability - missed a load"));
+ if (flags & FLAG_PREFETCHABLE) {
+ // This only applies if we had somehow otherwise marked this
+ // prefetchable.
+ reason = MISSED_A_LOAD;
+ }
flags &= ~FLAG_PREFETCHABLE;
}
}
PREDICTOR_LOG((" setting up prediction"));
- SetupPrediction(confidence, flags, uri);
+ SetupPrediction(confidence, flags, uri, reason);
}
}
// (Maybe) adds a predictive action to the prediction runner, based on our
// calculated confidence for the subresource in question.
void
-Predictor::SetupPrediction(int32_t confidence, uint32_t flags, const nsCString &uri)
+Predictor::SetupPrediction(int32_t confidence, uint32_t flags,
+ const nsCString &uri,
+ PrefetchIgnoreReason earlyReason)
{
MOZ_ASSERT(NS_IsMainThread());
nsresult rv = NS_OK;
PREDICTOR_LOG(("SetupPrediction mEnablePrefetch=%d mPrefetchMinConfidence=%d "
"mPreconnectMinConfidence=%d mPreresolveMinConfidence=%d "
"flags=%d confidence=%d uri=%s", mEnablePrefetch,
mPrefetchMinConfidence, mPreconnectMinConfidence,
mPreresolveMinConfidence, flags, confidence, uri.get()));
- if (mEnablePrefetch && (flags & FLAG_PREFETCHABLE) &&
- (mPrefetchRollingLoadCount || (confidence >= mPrefetchMinConfidence))) {
+
+ bool prefetchOk = !!(flags & FLAG_PREFETCHABLE);
+ PrefetchIgnoreReason reason = earlyReason;
+ if (prefetchOk && !mEnablePrefetch) {
+ prefetchOk = false;
+ reason = PREFETCH_DISABLED;
+ } else if (prefetchOk && !mPrefetchRollingLoadCount &&
+ confidence < mPrefetchMinConfidence) {
+ prefetchOk = false;
+ if (!mPrefetchRollingLoadCount) {
+ reason = PREFETCH_DISABLED_VIA_COUNT;
+ } else {
+ reason = CONFIDENCE_TOO_LOW;
+ }
+ }
+
+ // prefetchOk == false and reason == PREFETCH_OK indicates that the reason
+ // we aren't prefetching this item is because it was marked un-prefetchable in
+ // our metadata. We already have separate telemetry on that decision, so we
+ // aren't going to accumulate more here. Right now we only care about why
+ // something we had marked prefetchable isn't being prefetched.
+ if (!prefetchOk && reason != PREFETCH_OK) {
+ Telemetry::Accumulate(Telemetry::PREDICTOR_PREFETCH_IGNORE_REASON, reason);
+ }
+
+ if (prefetchOk) {
nsCOMPtr<nsIURI> prefetchURI;
rv = NS_NewURI(getter_AddRefs(prefetchURI), uri, nullptr, nullptr,
mIOService);
if (NS_SUCCEEDED(rv)) {
mPrefetches.AppendElement(prefetchURI);
}
} else if (confidence >= mPreconnectMinConfidence) {
nsCOMPtr<nsIURI> preconnectURI;
--- a/netwerk/base/Predictor.h
+++ b/netwerk/base/Predictor.h
@@ -329,21 +329,32 @@ private:
// * loadCount - number of times this page has been loaded
// * gloablDegradation - value calculated by CalculateGlobalDegradation for
// this page
// * fullUri - whether we're predicting for a full URI or origin-only
void CalculatePredictions(nsICacheEntry *entry, nsIURI *referrer,
uint32_t lastLoad, uint32_t loadCount,
int32_t globalDegradation, bool fullUri);
+ enum PrefetchIgnoreReason {
+ PREFETCH_OK,
+ NOT_FULL_URI,
+ NO_REFERRER,
+ MISSED_A_LOAD,
+ PREFETCH_DISABLED,
+ PREFETCH_DISABLED_VIA_COUNT,
+ CONFIDENCE_TOO_LOW
+ };
+
// Used to prepare any necessary prediction for a resource on a page
// * confidence - value calculated by CalculateConfidence for this resource
// * flags - the flags taken from the resource
// * uri - the ascii spec of the URI of the resource
- void SetupPrediction(int32_t confidence, uint32_t flags, const nsCString &uri);
+ void SetupPrediction(int32_t confidence, uint32_t flags, const nsCString &uri,
+ PrefetchIgnoreReason reason);
// Used to kick off a prefetch from RunPredictions if necessary
// * uri - the URI to prefetch
// * referrer - the URI of the referring page
// * originAttributes - the originAttributes of this prefetch
// * verifier - used for testing to ensure the expected prefetch happens
nsresult Prefetch(nsIURI *uri, nsIURI *referrer,
const OriginAttributes& originAttributes,
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -3912,16 +3912,25 @@
"record_in_processes": ["main"],
"expires_in_version": "60",
"kind": "enumerated",
"n_values": 15,
"alert_emails": ["hurley@mozilla.com"],
"bug_numbers": [1409542],
"description": "Why the predictor determined a particular resource was eligible for future prefetch (or not). See PrefetchDecisionReason in Predictor.cpp for value meanings"
},
+ "PREDICTOR_PREFETCH_IGNORE_REASON": {
+ "record_in_processes": ["main"],
+ "expires_in_version": "60",
+ "kind": "enumerated",
+ "n_values": 15,
+ "alert_emails": ["hurley@mozilla.com"],
+ "bug_numbers": [1409542],
+ "description": "Why the predictor determined a particular resource that was marked eligible for prefetch should not be prefetched. See PrefetchIgnoreReason in Predictor.cpp for value meanings"
+ },
"HTTPCONNMGR_TOTAL_SPECULATIVE_CONN": {
"record_in_processes": ["main", "content"],
"expires_in_version": "never",
"kind": "exponential",
"high": 1000000,
"n_buckets": 50,
"description": "How many speculative http connections are created"
},