Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: chrome/browser/prerender/prerender_histograms.cc

Issue 2302433002: [NoStatePrefetch] Track redirects in UMA (Closed)
Patch Set: review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prerender/prerender_histograms.cc
diff --git a/chrome/browser/prerender/prerender_histograms.cc b/chrome/browser/prerender/prerender_histograms.cc
index 895adb0c3cf6a42412dcee04f25e25c9fad529b5..7e89e8ba033291a2b381adb9b26282dcf7f13d07 100644
--- a/chrome/browser/prerender/prerender_histograms.cc
+++ b/chrome/browser/prerender/prerender_histograms.cc
@@ -22,15 +22,31 @@ namespace {
// "Prerender.NoStatePrefetchResourceCount" histogram family.
// Hence, existing enumerated constants should never be deleted or reordered,
// and new constants should only be appended at the end of the enumeration.
-enum NoStatePrefetchResourceType {
- MAIN_RESOURCE_CACHEABLE = 0,
- MAIN_RESOURCE_NO_STORE = 1,
- SUB_RESOURCE_CACHEABLE = 2,
- SUB_RESOURCE_NO_STORE = 3,
-
- NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last.
+enum NoStatePrefetchResponseType {
+ NO_STORE = 1 << 0,
+ REDIRECT = 1 << 1,
+ MAIN_RESOURCE = 1 << 2,
+ NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT = 1 << 3
};
+int GetResourceType(bool is_main_resource, bool is_redirect, bool is_no_store) {
+ return (is_no_store * NO_STORE) + (is_redirect * REDIRECT) +
+ (is_main_resource * MAIN_RESOURCE);
+}
+
+// Similar to UMA_HISTOGRAM_ENUMERATION but allows a dynamic histogram name.
+// Records a sample such as 0 <= sample < max_value, in a histogram with
pasko 2016/09/05 14:39:48 nit: I find it slightly inconvenient that all poss
droger 2016/09/05 15:03:44 Done.
+// |max_value| buckets of width 1 each.
+void RecordHistogramEnum(std::string histogram_name,
+ base::HistogramBase::Sample sample,
+ base::HistogramBase::Sample max_value) {
+ DCHECK_LT(sample, max_value);
+ base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
+ histogram_name, 1, max_value, max_value + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag);
+ histogram_pointer->Add(sample);
+}
+
// Time window for which we will record windowed PLTs from the last observed
// link rel=prefetch tag. This is not intended to be the same as the prerender
// ttl, it's just intended to be a window during which a prerender has likely
@@ -395,26 +411,32 @@ void PrerenderHistograms::RecordNetworkBytes(Origin origin,
}
}
-void PrerenderHistograms::RecordResourcePrefetch(Origin origin,
- bool is_main_resource,
- bool is_no_store) const {
+void PrerenderHistograms::RecordPrefetchResponseReceived(
+ Origin origin,
+ bool is_main_resource,
+ bool is_redirect,
+ bool is_no_store) const {
DCHECK(thread_checker_.CalledOnValidThread());
- NoStatePrefetchResourceType type =
- is_main_resource
- ? (is_no_store ? MAIN_RESOURCE_NO_STORE : MAIN_RESOURCE_CACHEABLE)
- : (is_no_store ? SUB_RESOURCE_NO_STORE : SUB_RESOURCE_CACHEABLE);
- DCHECK_LT(type, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT);
+ int sample = GetResourceType(is_main_resource, is_redirect, is_no_store);
std::string histogram_name =
- GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceTypes");
+ GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResponseTypes");
+ RecordHistogramEnum(histogram_name, sample,
+ NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT);
+}
- // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram
- // name.
- base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
- histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT,
- NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1,
- base::HistogramBase::kUmaTargetedHistogramFlag);
- histogram_pointer->Add(type);
+void PrerenderHistograms::RecordPrefetchRedirectCount(
+ Origin origin,
+ bool is_main_resource,
+ int redirect_count) const {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ const int kMaxRedirectCount = 10;
+ std::string histogram_base_name = base::StringPrintf(
+ "NoStatePrefetch%sResourceRedirects", is_main_resource ? "Main" : "Sub");
+ std::string histogram_name =
+ GetHistogramName(origin, IsOriginWash(), histogram_base_name);
+ RecordHistogramEnum(histogram_name, redirect_count, kMaxRedirectCount);
}
bool PrerenderHistograms::IsOriginWash() const {

Powered by Google App Engine
This is Rietveld 408576698