| 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" |
| 11 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | |
| 13 #include "chrome/browser/prerender/prerender_manager.h" | 14 #include "chrome/browser/prerender/prerender_manager.h" |
| 14 #include "chrome/browser/prerender/prerender_util.h" | 15 #include "chrome/browser/prerender/prerender_util.h" |
| 15 | 16 |
| 16 using predictors::AutocompleteActionPredictor; | |
| 17 | |
| 18 namespace prerender { | 17 namespace prerender { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 21 // This enum is used to define the buckets for the |
| 22 // "Prerender.NoStatePrefetchResourceCount" histogram family. |
| 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. |
| 25 enum NoStatePrefetchResourceType { |
| 26 MAIN_RESOURCE_CACHEABLE = 0, |
| 27 MAIN_RESOURCE_NO_STORE = 1, |
| 28 SUB_RESOURCE_CACHEABLE = 2, |
| 29 SUB_RESOURCE_NO_STORE = 3, |
| 30 |
| 31 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last. |
| 32 }; |
| 33 |
| 22 // Time window for which we will record windowed PLTs from the last observed | 34 // Time window for which we will record windowed PLTs from the last observed |
| 23 // link rel=prefetch tag. This is not intended to be the same as the prerender | 35 // link rel=prefetch tag. This is not intended to be the same as the prerender |
| 24 // ttl, it's just intended to be a window during which a prerender has likely | 36 // ttl, it's just intended to be a window during which a prerender has likely |
| 25 // affected performance. | 37 // affected performance. |
| 26 const int kWindowDurationSeconds = 30; | 38 const int kWindowDurationSeconds = 30; |
| 27 | 39 |
| 28 std::string ComposeHistogramName(const std::string& prefix_type, | 40 std::string ComposeHistogramName(const std::string& prefix_type, |
| 29 const std::string& name) { | 41 const std::string& name) { |
| 30 if (prefix_type.empty()) | 42 if (prefix_type.empty()) |
| 31 return std::string("Prerender.") + name; | 43 return std::string("Prerender.") + name; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 FinalStatus final_status) const { | 359 FinalStatus final_status) const { |
| 348 DCHECK(final_status != FINAL_STATUS_MAX); | 360 DCHECK(final_status != FINAL_STATUS_MAX); |
| 349 PREFIXED_HISTOGRAM_ORIGIN_EXPERIMENT( | 361 PREFIXED_HISTOGRAM_ORIGIN_EXPERIMENT( |
| 350 "FinalStatus", origin, | 362 "FinalStatus", origin, |
| 351 UMA_HISTOGRAM_ENUMERATION(name, final_status, FINAL_STATUS_MAX)); | 363 UMA_HISTOGRAM_ENUMERATION(name, final_status, FINAL_STATUS_MAX)); |
| 352 } | 364 } |
| 353 | 365 |
| 354 void PrerenderHistograms::RecordNetworkBytes(Origin origin, | 366 void PrerenderHistograms::RecordNetworkBytes(Origin origin, |
| 355 bool used, | 367 bool used, |
| 356 int64_t prerender_bytes, | 368 int64_t prerender_bytes, |
| 357 int64_t profile_bytes) { | 369 int64_t profile_bytes) const { |
| 358 const int kHistogramMin = 1; | 370 const int kHistogramMin = 1; |
| 359 const int kHistogramMax = 100000000; // 100M. | 371 const int kHistogramMax = 100000000; // 100M. |
| 360 const int kBucketCount = 50; | 372 const int kBucketCount = 50; |
| 361 | 373 |
| 362 UMA_HISTOGRAM_CUSTOM_COUNTS("Prerender.NetworkBytesTotalForProfile", | 374 UMA_HISTOGRAM_CUSTOM_COUNTS("Prerender.NetworkBytesTotalForProfile", |
| 363 profile_bytes, | 375 profile_bytes, |
| 364 kHistogramMin, | 376 kHistogramMin, |
| 365 1000000000, // 1G | 377 1000000000, // 1G |
| 366 kBucketCount); | 378 kBucketCount); |
| 367 | 379 |
| 368 if (prerender_bytes == 0) | 380 if (prerender_bytes == 0) |
| 369 return; | 381 return; |
| 370 | 382 |
| 371 if (used) { | 383 if (used) { |
| 372 PREFIXED_HISTOGRAM( | 384 PREFIXED_HISTOGRAM( |
| 373 "NetworkBytesUsed", | 385 "NetworkBytesUsed", |
| 374 origin, | 386 origin, |
| 375 UMA_HISTOGRAM_CUSTOM_COUNTS( | 387 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 376 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); | 388 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); |
| 377 } else { | 389 } else { |
| 378 PREFIXED_HISTOGRAM( | 390 PREFIXED_HISTOGRAM( |
| 379 "NetworkBytesWasted", | 391 "NetworkBytesWasted", |
| 380 origin, | 392 origin, |
| 381 UMA_HISTOGRAM_CUSTOM_COUNTS( | 393 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 382 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); | 394 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); |
| 383 } | 395 } |
| 384 } | 396 } |
| 385 | 397 |
| 398 void PrerenderHistograms::RecordResourcePrefetch(Origin origin, |
| 399 bool is_main_resource, |
| 400 bool is_no_store) const { |
| 401 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 |
| 408 std::string histogram_name = |
| 409 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceTypes"); |
| 410 |
| 411 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram |
| 412 // name. |
| 413 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet( |
| 414 histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT, |
| 415 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1, |
| 416 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 417 histogram_pointer->Add(type); |
| 418 } |
| 419 |
| 386 bool PrerenderHistograms::IsOriginWash() const { | 420 bool PrerenderHistograms::IsOriginWash() const { |
| 387 if (!WithinWindow()) | 421 if (!WithinWindow()) |
| 388 return false; | 422 return false; |
| 389 return origin_wash_; | 423 return origin_wash_; |
| 390 } | 424 } |
| 391 | 425 |
| 392 } // namespace prerender | 426 } // namespace prerender |
| OLD | NEW |