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

Side by Side Diff: chrome/browser/prerender/prerender_histograms.cc

Issue 2302433002: [NoStatePrefetch] Track redirects in UMA (Closed)
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prerender/prerender_histograms.h" 5 #include "chrome/browser/prerender/prerender_histograms.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/prerender/prerender_manager.h" 14 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/prerender/prerender_util.h" 15 #include "chrome/browser/prerender/prerender_util.h"
16 16
17 namespace prerender { 17 namespace prerender {
18 18
19 namespace { 19 namespace {
20 20
21 // This enum is used to define the buckets for the 21 // This enum is used to define the buckets for the
22 // "Prerender.NoStatePrefetchResourceCount" histogram family. 22 // "Prerender.NoStatePrefetchResourceCount" histogram family.
23 // Hence, existing enumerated constants should never be deleted or reordered, 23 // Hence, existing enumerated constants should never be deleted or reordered,
24 // and new constants should only be appended at the end of the enumeration. 24 // and new constants should only be appended at the end of the enumeration.
25 enum NoStatePrefetchResourceType { 25 enum NoStatePrefetchResponseType {
26 MAIN_RESOURCE_CACHEABLE = 0, 26 NO_STORE = 1 << 0,
27 MAIN_RESOURCE_NO_STORE = 1, 27 REDIRECT = 1 << 1,
28 SUB_RESOURCE_CACHEABLE = 2, 28 MAIN_RESOURCE = 1 << 2,
29 SUB_RESOURCE_NO_STORE = 3, 29 NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT = 1 << 3
30 };
30 31
31 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last. 32 int GetResourceType(bool is_main_resource, bool is_redirect, bool is_no_store) {
32 }; 33 return (is_no_store * NO_STORE) + (is_redirect * REDIRECT) +
34 (is_main_resource * MAIN_RESOURCE);
35 }
36
37 // Similar to UMA_HISTOGRAM_ENUMERATION but allows a dynamic histogram name.
38 // Records a sample such as 0 <= sample < bucket_count, in a histogram with
39 // |bucket_count| buckets of width 1 each.
40 void RecordHistogramEnum(std::string histogram_name,
41 base::HistogramBase::Sample sample,
42 base::HistogramBase::Sample bucket_count) {
43 DCHECK_LT(sample, bucket_count);
44 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
45 histogram_name, 1, bucket_count, bucket_count + 1,
46 base::HistogramBase::kUmaTargetedHistogramFlag);
47 histogram_pointer->Add(sample);
48 }
33 49
34 // Time window for which we will record windowed PLTs from the last observed 50 // Time window for which we will record windowed PLTs from the last observed
35 // link rel=prefetch tag. This is not intended to be the same as the prerender 51 // link rel=prefetch tag. This is not intended to be the same as the prerender
36 // ttl, it's just intended to be a window during which a prerender has likely 52 // ttl, it's just intended to be a window during which a prerender has likely
37 // affected performance. 53 // affected performance.
38 const int kWindowDurationSeconds = 30; 54 const int kWindowDurationSeconds = 30;
39 55
40 std::string ComposeHistogramName(const std::string& prefix_type, 56 std::string ComposeHistogramName(const std::string& prefix_type,
41 const std::string& name) { 57 const std::string& name) {
42 if (prefix_type.empty()) 58 if (prefix_type.empty())
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 404 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
389 } else { 405 } else {
390 PREFIXED_HISTOGRAM( 406 PREFIXED_HISTOGRAM(
391 "NetworkBytesWasted", 407 "NetworkBytesWasted",
392 origin, 408 origin,
393 UMA_HISTOGRAM_CUSTOM_COUNTS( 409 UMA_HISTOGRAM_CUSTOM_COUNTS(
394 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 410 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
395 } 411 }
396 } 412 }
397 413
398 void PrerenderHistograms::RecordResourcePrefetch(Origin origin, 414 void PrerenderHistograms::RecordPrefetchResponseReceived(
399 bool is_main_resource, 415 Origin origin,
400 bool is_no_store) const { 416 bool is_main_resource,
417 bool is_redirect,
418 bool is_no_store) const {
401 DCHECK(thread_checker_.CalledOnValidThread()); 419 DCHECK(thread_checker_.CalledOnValidThread());
402 NoStatePrefetchResourceType type =
403 is_main_resource
404 ? (is_no_store ? MAIN_RESOURCE_NO_STORE : MAIN_RESOURCE_CACHEABLE)
405 : (is_no_store ? SUB_RESOURCE_NO_STORE : SUB_RESOURCE_CACHEABLE);
406 DCHECK_LT(type, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT);
407 420
421 int sample = GetResourceType(is_main_resource, is_redirect, is_no_store);
408 std::string histogram_name = 422 std::string histogram_name =
409 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceTypes"); 423 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResponseTypes");
424 RecordHistogramEnum(histogram_name, sample,
425 NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT);
426 }
410 427
411 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram 428 void PrerenderHistograms::RecordPrefetchRedirectCount(
412 // name. 429 Origin origin,
413 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( 430 bool is_main_resource,
414 histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT, 431 int redirect_count) const {
415 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1, 432 DCHECK(thread_checker_.CalledOnValidThread());
416 base::HistogramBase::kUmaTargetedHistogramFlag); 433
417 histogram_pointer->Add(type); 434 const int kMaxRedirectCount = 10;
435 std::string histogram_base_name = base::StringPrintf(
436 "NoStatePrefetch%sResourceRedirects", is_main_resource ? "Main" : "Sub");
437 std::string histogram_name =
438 GetHistogramName(origin, IsOriginWash(), histogram_base_name);
439 RecordHistogramEnum(histogram_name, redirect_count, kMaxRedirectCount);
418 } 440 }
419 441
420 bool PrerenderHistograms::IsOriginWash() const { 442 bool PrerenderHistograms::IsOriginWash() const {
421 if (!WithinWindow()) 443 if (!WithinWindow())
422 return false; 444 return false;
423 return origin_wash_; 445 return origin_wash_;
424 } 446 }
425 447
426 } // namespace prerender 448 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_histograms.h ('k') | chrome/browser/prerender/prerender_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698