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

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

Issue 2287993003: [NoStatePrefetch] Add UMA histogram to count prefetch requests (Closed)
Patch Set: review comments 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/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.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;
17
18 namespace prerender { 16 namespace prerender {
19 17
20 namespace { 18 namespace {
21 19
20 // This enum is used to define the buckets for the
21 // "Prerender.NoStatePrefetchResourceCount" histogram family.
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.
24 enum NoStatePrefetchResourceType {
25 MAIN_RESOURCE_CACHEABLE = 0,
26 MAIN_RESOURCE_NO_STORE = 1,
27 SUB_RESOURCE_CACHEABLE = 2,
28 SUB_RESOURCE_NO_STORE = 3,
29
30 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT // Must be the last.
31 };
32
22 // Time window for which we will record windowed PLTs from the last observed 33 // 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 34 // 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 35 // ttl, it's just intended to be a window during which a prerender has likely
25 // affected performance. 36 // affected performance.
26 const int kWindowDurationSeconds = 30; 37 const int kWindowDurationSeconds = 30;
27 38
28 std::string ComposeHistogramName(const std::string& prefix_type, 39 std::string ComposeHistogramName(const std::string& prefix_type,
29 const std::string& name) { 40 const std::string& name) {
30 if (prefix_type.empty()) 41 if (prefix_type.empty())
31 return std::string("Prerender.") + name; 42 return std::string("Prerender.") + name;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 387 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
377 } else { 388 } else {
378 PREFIXED_HISTOGRAM( 389 PREFIXED_HISTOGRAM(
379 "NetworkBytesWasted", 390 "NetworkBytesWasted",
380 origin, 391 origin,
381 UMA_HISTOGRAM_CUSTOM_COUNTS( 392 UMA_HISTOGRAM_CUSTOM_COUNTS(
382 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount)); 393 name, prerender_bytes, kHistogramMin, kHistogramMax, kBucketCount));
383 } 394 }
384 } 395 }
385 396
397 void PrerenderHistograms::RecordResourcePrefetch(Origin origin,
398 bool is_main_resource,
399 bool is_no_store) {
400 DCHECK(thread_checker_.CalledOnValidThread());
401 NoStatePrefetchResourceType type =
402 is_main_resource
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);
406
407 std::string histogram_name =
408 GetHistogramName(origin, IsOriginWash(), "NoStatePrefetchResourceCount");
pasko 2016/08/30 15:11:19 nit: I think "Count" is implied in histograms, Bla
409
410 // Unrolls UMA_HISTOGRAM_ENUMERATION, required to support dynamic histogram
411 // name.
412 base::HistogramBase* histogram_pointer = base::LinearHistogram::FactoryGet(
413 histogram_name, 1, NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT,
414 NO_STATE_PREFETCH_RESOURCE_TYPE_COUNT + 1,
415 base::HistogramBase::kUmaTargetedHistogramFlag);
416 histogram_pointer->Add(type);
417 }
418
386 bool PrerenderHistograms::IsOriginWash() const { 419 bool PrerenderHistograms::IsOriginWash() const {
387 if (!WithinWindow()) 420 if (!WithinWindow())
388 return false; 421 return false;
389 return origin_wash_; 422 return origin_wash_;
390 } 423 }
391 424
392 } // namespace prerender 425 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698