Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/browser/prerender/prerender_manager.h" | 13 #include "chrome/browser/prerender/prerender_manager.h" |
| 14 #include "chrome/browser/prerender/prerender_util.h" | 14 #include "chrome/browser/prerender/prerender_util.h" |
| 15 | 15 |
| 16 namespace prerender { | 16 namespace prerender { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // This enum is used to define the buckets for the | 20 // This enum is used to define the buckets for the |
| 21 // "Prerender.NoStatePrefetchResourceCount" histogram family. | 21 // "Prerender.NoStatePrefetchResourceCount" histogram family. |
| 22 // Hence, existing enumerated constants should never be deleted or reordered, | 22 // Hence, existing enumerated constants should never be deleted or reordered, |
| 23 // and new constants should only be appended at the end of the enumeration. | 23 // and new constants should only be appended at the end of the enumeration. |
| 24 enum NoStatePrefetchResourceType { | 24 enum NoStatePrefetchResourceType { |
| 25 MAIN_RESOURCE_CACHEABLE = 0, | 25 SUB_RESOURCE_CACHEABLE = 0, |
| 26 MAIN_RESOURCE_NO_STORE = 1, | 26 SUB_RESOURCE_NO_STORE = 1, |
| 27 SUB_RESOURCE_CACHEABLE = 2, | 27 SUB_RESOURCE_REDIRECT_CACHEABLE = 2, |
| 28 SUB_RESOURCE_NO_STORE = 3, | 28 SUB_RESOURCE_REDIRECT_NO_STORE = 3, |
| 29 MAIN_RESOURCE_CACHEABLE = 4, | |
| 30 MAIN_RESOURCE_NO_STORE = 5, | |
| 31 MAIN_RESOURCE_REDIRECT_CACHEABLE = 6, | |
| 32 MAIN_RESOURCE_REDIRECT_NO_STORE = 7, | |
| 29 | 33 |
| 30 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last. | 34 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last. |
| 31 }; | 35 }; |
| 32 | 36 |
| 37 NoStatePrefetchResourceType GetResourceType(bool is_main_resource, | |
| 38 bool is_redirect, | |
| 39 bool is_no_store) { | |
| 40 return static_cast<NoStatePrefetchResourceType>( | |
|
pasko
2016/09/02 16:34:48
This was confusing to me:
* casting explicitly to
droger
2016/09/05 12:38:47
Done using a bitfield.
| |
| 41 4 * is_main_resource + 2 * is_redirect + is_no_store); | |
| 42 } | |
| 43 | |
| 33 // Time window for which we will record windowed PLTs from the last observed | 44 // Time window for which we will record windowed PLTs from the last observed |
| 34 // link rel=prefetch tag. This is not intended to be the same as the prerender | 45 // link rel=prefetch tag. This is not intended to be the same as the prerender |
| 35 // ttl, it's just intended to be a window during which a prerender has likely | 46 // ttl, it's just intended to be a window during which a prerender has likely |
| 36 // affected performance. | 47 // affected performance. |
| 37 const int kWindowDurationSeconds = 30; | 48 const int kWindowDurationSeconds = 30; |
| 38 | 49 |
| 39 std::string ComposeHistogramName(const std::string& prefix_type, | 50 std::string ComposeHistogramName(const std::string& prefix_type, |
| 40 const std::string& name) { | 51 const std::string& name) { |
| 41 if (prefix_type.empty()) | 52 if (prefix_type.empty()) |
| 42 return std::string("Prerender.") + name; | 53 return std::string("Prerender.") + name; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 PREFIXED_HISTOGRAM( | 400 PREFIXED_HISTOGRAM( |
| 390 "NetworkBytesWasted", | 401 "NetworkBytesWasted", |
| 391 origin, | 402 origin, |
| 392 UMA_HISTOGRAM_CUSTOM_COUNTS( | 403 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 393 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); | 404 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); |
| 394 } | 405 } |
| 395 } | 406 } |
| 396 | 407 |
| 397 void PrerenderHistograms::RecordResourcePrefetch(Origin origin, | 408 void PrerenderHistograms::RecordResourcePrefetch(Origin origin, |
| 398 bool is_main_resource, | 409 bool is_main_resource, |
| 410 bool is_redirect, | |
| 399 bool is_no_store) const { | 411 bool is_no_store) const { |
| 400 DCHECK(thread_checker_.CalledOnValidThread()); | 412 DCHECK(thread_checker_.CalledOnValidThread()); |
| 401 NoStatePrefetchResourceType type = | 413 NoStatePrefetchResourceType type = |
| 402 is_main_resource | 414 GetResourceType(is_main_resource, is_redirect, is_no_store); |
| 403 ? (is_no_store ? MAIN_RESOURCE_NO_STORE : MAIN_RESOURCE_CACHEABLE) | |
| 404 : (is_no_store ? SUB_RESOURCE_NO_STORE : SUB_RESOURCE_CACHEABLE); | |
| 405 DCHECK_LT(type, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT); | 415 DCHECK_LT(type, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT); |
| 406 | 416 |
| 407 std::string histogram_name = | 417 std::string histogram_name = |
| 408 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceTypes"); | 418 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceTypes"); |
| 409 | 419 |
| 410 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram | 420 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram |
| 411 // name. | 421 // name. |
| 412 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( | 422 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( |
| 413 histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT, | 423 histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT, |
| 414 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1, | 424 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1, |
| 415 base::HistogramBase::kUmaTargetedHistogramFlag); | 425 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 416 histogram_pointer->Add(type); | 426 histogram_pointer->Add(type); |
| 417 } | 427 } |
| 418 | 428 |
| 429 void PrerenderHistograms::RecordPrefetchRedirectCount( | |
| 430 Origin origin, | |
| 431 bool is_main_resource, | |
| 432 size_t redirect_count) const { | |
| 433 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 434 | |
| 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 | |
| 440 // Unrolls UMA_HISTOGRAM_CUSTOM_COUNTS, required to support dynamic histogram | |
|
pasko
2016/09/02 16:34:48
can we avoid repeating ourselves twice here?
void
droger
2016/09/05 12:38:47
Done.
| |
| 441 // name. | |
| 442 const int kMaxRedirectCount = 10; | |
| 443 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( | |
| 444 histogram_name, 1, kMaxRedirectCount, kMaxRedirectCount + 1, | |
| 445 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 446 histogram_pointer->Add(redirect_count); | |
| 447 } | |
| 448 | |
| 419 bool PrerenderHistograms::IsOriginWash() const { | 449 bool PrerenderHistograms::IsOriginWash() const { |
| 420 if (!WithinWindow()) | 450 if (!WithinWindow()) |
| 421 return false; | 451 return false; |
| 422 return origin_wash_; | 452 return origin_wash_; |
| 423 } | 453 } |
| 424 | 454 |
| 425 } // namespace prerender | 455 } // namespace prerender |
| OLD | NEW |