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

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

Issue 2287993003: [NoStatePrefetch] Add UMA histogram to count prefetch requests (Closed)
Patch Set: comment 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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" 12 #include "chrome/browser/predictors/autocomplete_action_predictor.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 using predictors::AutocompleteActionPredictor; 16 using predictors::AutocompleteActionPredictor;
17 17
18 namespace prerender { 18 namespace prerender {
19 19
20 namespace { 20 namespace {
21 21
22 // This enum is used to define the buckets for the
23 // "Prerender.NoStatePrefetchResourceCount" histogram family.
24 // Hence, existing enumerated constants should never be deleted or reordered,
25 // and new constants should only be appended at the end of the enumeration.
26 enum NoStatePrefetchResourceType {
27 kMainResourceCacheable = 0,
pasko 2016/08/30 13:41:04 I think chromium style prefers MACRO_STYLE constan
droger 2016/08/30 14:31:41 changed the naming style, however I need these to
28 kMainResourceNoStore = 1,
29 kSubResourceCacheable = 2,
30 kSubResourceNoStore = 3,
31
32 kNoStatePrefetchResourceTypeCount // Must be the last.
33 };
34
22 // Time window for which we will record windowed PLTs from the last observed 35 // 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 36 // 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 37 // ttl, it's just intended to be a window during which a prerender has likely
25 // affected performance. 38 // affected performance.
26 const int kWindowDurationSeconds = 30; 39 const int kWindowDurationSeconds = 30;
27 40
28 std::string ComposeHistogramName(const std::string& prefix_type, 41 std::string ComposeHistogramName(const std::string& prefix_type,
29 const std::string& name) { 42 const std::string& name) {
30 if (prefix_type.empty()) 43 if (prefix_type.empty())
31 return std::string("Prerender.") + name; 44 return std::string("Prerender.") + name;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 389 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
377 } else { 390 } else {
378 PREFIXED_HISTOGRAM( 391 PREFIXED_HISTOGRAM(
379 "NetworkBytesWasted", 392 "NetworkBytesWasted",
380 origin, 393 origin,
381 UMA_HISTOGRAM_CUSTOM_COUNTS( 394 UMA_HISTOGRAM_CUSTOM_COUNTS(
382 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 395 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
383 } 396 }
384 } 397 }
385 398
399 void PrerenderHistograms::RecordResourcePrefetch(Origin origin,
400 bool is_main_resource,
401 bool is_no_store) {
402 NoStatePrefetchResourceType type =
403 is_main_resource
404 ? (is_no_store ? kMainResourceNoStore : kMainResourceCacheable)
405 : (is_no_store ? kSubResourceNoStore : kSubResourceCacheable);
406 DCHECK_LT(type, kNoStatePrefetchResourceTypeCount);
407
408 std::string histogram_name =
409 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceCount");
410
411 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram
pasko 2016/08/30 13:41:04 Would it be possible to DCHECK_CURRENTLY_ON(Browse
droger 2016/08/30 14:31:41 Done (using a thread checker).
412 // name.
413 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
414 histogram_name, 1, kNoStatePrefetchResourceTypeCount,
415 kNoStatePrefetchResourceTypeCount + 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698