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

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

Issue 2321083002: [NoStatePrefetch] Add performance histograms. (Closed)
Patch Set: Added browser test 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 #include "net/http/http_cache.h"
16 17
17 namespace prerender { 18 namespace prerender {
18 19
19 namespace { 20 namespace {
20 21
21 // This enum is used to define the buckets for the 22 // This enum is used to define the buckets for the
22 // "Prerender.NoStatePrefetchResourceCount" histogram family. 23 // "Prerender.NoStatePrefetchResourceCount" histogram family.
23 // Hence, existing enumerated constants should never be deleted or reordered, 24 // Hence, existing enumerated constants should never be deleted or reordered,
24 // and new constants should only be appended at the end of the enumeration. 25 // and new constants should only be appended at the end of the enumeration.
25 enum NoStatePrefetchResponseType { 26 enum NoStatePrefetchResponseType {
26 NO_STORE = 1 << 0, 27 NO_STORE = 1 << 0,
27 REDIRECT = 1 << 1, 28 REDIRECT = 1 << 1,
28 MAIN_RESOURCE = 1 << 2, 29 MAIN_RESOURCE = 1 << 2,
29 NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT = 1 << 3 30 NO_STATE_PREFETCH_RESPONSE_TYPE_COUNT = 1 << 3
30 }; 31 };
31 32
32 int GetResourceType(bool is_main_resource, bool is_redirect, bool is_no_store) { 33 int GetResourceType(bool is_main_resource, bool is_redirect, bool is_no_store) {
33 return (is_no_store * NO_STORE) + (is_redirect * REDIRECT) + 34 return (is_no_store * NO_STORE) + (is_redirect * REDIRECT) +
34 (is_main_resource * MAIN_RESOURCE); 35 (is_main_resource * MAIN_RESOURCE);
35 } 36 }
36 37
37 // Similar to UMA_HISTOGRAM_ENUMERATION but allows a dynamic histogram name. 38 // 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 // Records a sample such as 0 <= sample < bucket_count, in a histogram with
39 // |bucket_count| buckets of width 1 each. 40 // |bucket_count| buckets of width 1 each.
40 void RecordHistogramEnum(std::string histogram_name, 41 void RecordHistogramEnum(const std::string& histogram_name,
41 base::HistogramBase::Sample sample, 42 base::HistogramBase::Sample sample,
42 base::HistogramBase::Sample bucket_count) { 43 base::HistogramBase::Sample bucket_count) {
43 DCHECK_LT(sample, bucket_count); 44 DCHECK_LT(sample, bucket_count);
44 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( 45 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
45 histogram_name, 1, bucket_count, bucket_count + 1, 46 histogram_name, 1, bucket_count, bucket_count + 1,
46 base::HistogramBase::kUmaTargetedHistogramFlag); 47 base::HistogramBase::kUmaTargetedHistogramFlag);
47 histogram_pointer->Add(sample); 48 histogram_pointer->Add(sample);
48 } 49 }
49 50
51 // Similar to UMA_HISTOGRAM_CUSTOM_TIMES but allows a dynamic histogram name.
52 void RecordHistogramTime(const std::string& histogram_name,
53 base::TimeDelta time_min,
54 base::TimeDelta time_max,
55 base::TimeDelta sample,
56 base::HistogramBase::Sample bucket_count) {
57 base::HistogramBase* histogram_pointer = base::Histogram::FactoryTimeGet(
58 histogram_name, time_min, time_max, bucket_count,
59 base::HistogramBase::kUmaTargetedHistogramFlag);
60 histogram_pointer->AddTime(sample);
61 }
62
50 // Time window for which we will record windowed PLTs from the last observed 63 // Time window for which we will record windowed PLTs from the last observed
51 // link rel=prefetch tag. This is not intended to be the same as the prerender 64 // link rel=prefetch tag. This is not intended to be the same as the prerender
52 // ttl, it's just intended to be a window during which a prerender has likely 65 // ttl, it's just intended to be a window during which a prerender has likely
53 // affected performance. 66 // affected performance.
54 const int kWindowDurationSeconds = 30; 67 const int kWindowDurationSeconds = 30;
55 68
56 std::string ComposeHistogramName(const std::string& prefix_type, 69 std::string ComposeHistogramName(const std::string& prefix_type,
57 const std::string& name) { 70 const std::string& name) {
58 if (prefix_type.empty()) 71 if (prefix_type.empty())
59 return std::string("Prerender.") + name; 72 return std::string("Prerender.") + name;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 DCHECK(thread_checker_.CalledOnValidThread()); 445 DCHECK(thread_checker_.CalledOnValidThread());
433 446
434 const int kMaxRedirectCount = 10; 447 const int kMaxRedirectCount = 10;
435 std::string histogram_base_name = base::StringPrintf( 448 std::string histogram_base_name = base::StringPrintf(
436 "NoStatePrefetch%sResourceRedirects", is_main_resource ? "Main" : "Sub"); 449 "NoStatePrefetch%sResourceRedirects", is_main_resource ? "Main" : "Sub");
437 std::string histogram_name = 450 std::string histogram_name =
438 GetHistogramName(origin, IsOriginWash(), histogram_base_name); 451 GetHistogramName(origin, IsOriginWash(), histogram_base_name);
439 RecordHistogramEnum(histogram_name, redirect_count, kMaxRedirectCount); 452 RecordHistogramEnum(histogram_name, redirect_count, kMaxRedirectCount);
440 } 453 }
441 454
455 void PrerenderHistograms::RecordFirstContentfulPaint(
456 Origin origin,
457 bool is_no_store,
458 base::TimeDelta time,
459 base::TimeDelta prefetch_age) {
460 DCHECK(thread_checker_.CalledOnValidThread());
461
462 if (!prefetch_age.is_zero()) {
463 DCHECK_NE(origin, ORIGIN_NONE);
464 RecordHistogramTime(GetHistogramName(origin, IsOriginWash(),
465 "Prerender.NoStatePrefetchAge"),
466 base::TimeDelta::FromMilliseconds(10),
467 base::TimeDelta::FromMinutes(30), prefetch_age, 50);
468 }
469
470 RecordHistogramTime(GetFirstContentfulPaintHistogrameName(
471 origin, IsOriginWash(), is_no_store, prefetch_age),
472 base::TimeDelta::FromMilliseconds(10),
473 base::TimeDelta::FromMinutes(2), time, 50);
474 }
475
442 bool PrerenderHistograms::IsOriginWash() const { 476 bool PrerenderHistograms::IsOriginWash() const {
443 if (!WithinWindow()) 477 if (!WithinWindow())
444 return false; 478 return false;
445 return origin_wash_; 479 return origin_wash_;
446 } 480 }
447 481
482 // static
483 std::string PrerenderHistograms::GetFirstContentfulPaintHistogrameName(
484 Origin origin,
485 bool is_wash,
486 bool is_no_store,
487 base::TimeDelta prefetch_age) {
488 std::string histogram_base_name;
489 if (prefetch_age.is_zero()) {
490 histogram_base_name = "NoStatePrefetchTTFCP.Reference";
491 } else {
492 histogram_base_name = prefetch_age < base::TimeDelta::FromMinutes(
493 net::HttpCache::kPrefetchReuseMins)
494 ? "NoStatePrefetchTTFCP.Warm"
495 : "NoStatePrefetchTTFCP.Cold";
496 }
497
498 histogram_base_name += is_no_store ? ".NoStore" : ".Cacheable";
499 return GetHistogramName(origin, is_wash, histogram_base_name);
500 }
501
448 } // namespace prerender 502 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698