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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 632033002: Add PLT measurement to Resource Prefetching for Mobile Web (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase fix Created 6 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/predictors/resource_prefetch_predictor.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/history/history_database.h" 19 #include "chrome/browser/history/history_database.h"
19 #include "chrome/browser/history/history_db_task.h" 20 #include "chrome/browser/history/history_db_task.h"
20 #include "chrome/browser/history/history_notifications.h" 21 #include "chrome/browser/history/history_notifications.h"
21 #include "chrome/browser/history/history_service.h" 22 #include "chrome/browser/history/history_service.h"
22 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
23 #include "chrome/browser/predictors/predictor_database.h" 24 #include "chrome/browser/predictors/predictor_database.h"
24 #include "chrome/browser/predictors/predictor_database_factory.h" 25 #include "chrome/browser/predictors/predictor_database_factory.h"
25 #include "chrome/browser/predictors/resource_prefetcher_manager.h" 26 #include "chrome/browser/predictors/resource_prefetcher_manager.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/navigation_controller.h" 31 #include "content/public/browser/navigation_controller.h"
31 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/browser/resource_request_info.h" 35 #include "content/public/browser/resource_request_info.h"
35 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
36 #include "net/base/mime_util.h" 37 #include "net/base/mime_util.h"
38 #include "net/base/network_change_notifier.h"
37 #include "net/http/http_response_headers.h" 39 #include "net/http/http_response_headers.h"
38 #include "net/url_request/url_request.h" 40 #include "net/url_request/url_request.h"
39 #include "net/url_request/url_request_context_getter.h" 41 #include "net/url_request/url_request_context_getter.h"
40 42
41 using content::BrowserThread; 43 using content::BrowserThread;
42 44
43 namespace { 45 namespace {
44 46
45 // For reporting whether a subresource is handled or not, and for what reasons. 47 // For reporting whether a subresource is handled or not, and for what reasons.
46 enum ResourceStatus { 48 enum ResourceStatus {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, 85 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1,
84 REPORTING_EVENT_COUNT = 2 86 REPORTING_EVENT_COUNT = 2
85 }; 87 };
86 88
87 void RecordNavigationEvent(NavigationEvent event) { 89 void RecordNavigationEvent(NavigationEvent event) {
88 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent", 90 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent",
89 event, 91 event,
90 NAVIGATION_EVENT_COUNT); 92 NAVIGATION_EVENT_COUNT);
91 } 93 }
92 94
95 enum AdditionalConnectionType {
Lei Zhang 2014/11/03 18:06:27 Please add a comment to explain why these values a
Zhen Wang 2014/11/03 21:53:27 Done.
96 CONNECTION_ALL = -2,
97 CONNECTION_CELLULAR = -1
98 };
99
100 std::string GetNetTypeStr() {
101 switch (net::NetworkChangeNotifier::GetConnectionType()) {
102 case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
103 return "Ethernet";
104 case net::NetworkChangeNotifier::CONNECTION_WIFI:
105 return "WiFi";
106 case net::NetworkChangeNotifier::CONNECTION_2G:
107 return "2G";
108 case net::NetworkChangeNotifier::CONNECTION_3G:
109 return "3G";
110 case net::NetworkChangeNotifier::CONNECTION_4G:
111 return "4G";
112 case net::NetworkChangeNotifier::CONNECTION_NONE:
113 return "None";
114 case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
115 return "Bluetooth";
116 case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
117 default:
118 break;
119 }
120 return "Unknown";
121 }
122
123 void ReportPrefetchedNetworkType(int type) {
124 UMA_HISTOGRAM_SPARSE_SLOWLY(
125 "ResourcePrefetchPredictor.NetworkType.Prefetched",
126 type);
127 }
128
129 void ReportNotPrefetchedNetworkType(int type) {
130 UMA_HISTOGRAM_SPARSE_SLOWLY(
131 "ResourcePrefetchPredictor.NetworkType.NotPrefetched",
132 type);
133 }
134
93 } // namespace 135 } // namespace
94 136
95 namespace predictors { 137 namespace predictors {
96 138
97 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
98 // History lookup task. 140 // History lookup task.
99 141
100 // Used to fetch the visit count for a URL from the History database. 142 // Used to fetch the visit count for a URL from the History database.
101 class GetUrlVisitCountTask : public history::HistoryDBTask { 143 class GetUrlVisitCountTask : public history::HistoryDBTask {
102 public: 144 public:
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 560
519 NavigationMap::iterator nav_it = 561 NavigationMap::iterator nav_it =
520 inflight_navigations_.find(navigation_id); 562 inflight_navigations_.find(navigation_id);
521 if (nav_it == inflight_navigations_.end()) { 563 if (nav_it == inflight_navigations_.end()) {
522 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL); 564 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL);
523 return; 565 return;
524 } 566 }
525 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL); 567 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL);
526 568
527 // Report any stats. 569 // Report any stats.
570 base::TimeDelta plt = base::TimeTicks::Now() - navigation_id.creation_time;
571 ReportPageLoadTimeStats(plt);
528 if (prefetch_manager_.get()) { 572 if (prefetch_manager_.get()) {
529 ResultsMap::iterator results_it = results_map_.find(navigation_id); 573 ResultsMap::iterator results_it = results_map_.find(navigation_id);
530 bool have_prefetch_results = results_it != results_map_.end(); 574 bool have_prefetch_results = results_it != results_map_.end();
531 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", 575 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults",
532 have_prefetch_results); 576 have_prefetch_results);
533 if (have_prefetch_results) { 577 if (have_prefetch_results) {
534 ReportAccuracyStats(results_it->second->key_type, 578 ReportAccuracyStats(results_it->second->key_type,
535 *(nav_it->second), 579 *(nav_it->second),
536 results_it->second->requests.get()); 580 results_it->second->requests.get());
581 ReportPageLoadTimePrefetchStats(
582 plt,
583 true,
584 base::Bind(&ReportPrefetchedNetworkType),
585 results_it->second->key_type);
586 } else {
587 ReportPageLoadTimePrefetchStats(
588 plt,
589 false,
590 base::Bind(&ReportNotPrefetchedNetworkType),
591 PREFETCH_KEY_TYPE_URL);
537 } 592 }
538 } else { 593 } else {
539 scoped_ptr<ResourcePrefetcher::RequestVector> requests( 594 scoped_ptr<ResourcePrefetcher::RequestVector> requests(
540 new ResourcePrefetcher::RequestVector); 595 new ResourcePrefetcher::RequestVector);
541 PrefetchKeyType key_type; 596 PrefetchKeyType key_type;
542 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) { 597 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) {
543 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL); 598 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL);
544 ReportPredictedAccuracyStats(key_type, 599 ReportPredictedAccuracyStats(key_type,
545 *(nav_it->second), 600 *(nav_it->second),
546 *requests); 601 *requests);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 BrowserThread::PostTask( 1051 BrowserThread::PostTask(
997 BrowserThread::DB, FROM_HERE, 1052 BrowserThread::DB, FROM_HERE,
998 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, 1053 base::Bind(&ResourcePrefetchPredictorTables::UpdateData,
999 tables_, 1054 tables_,
1000 url_data, 1055 url_data,
1001 host_data)); 1056 host_data));
1002 } 1057 }
1003 } 1058 }
1004 1059
1005 //////////////////////////////////////////////////////////////////////////////// 1060 ////////////////////////////////////////////////////////////////////////////////
1006 // Accuracy measurement. 1061 // Page load time and accuracy measurement.
1062
1063 // This is essentially UMA_HISTOGRAM_MEDIUM_TIMES, but it avoids using the
1064 // STATIC_HISTOGRAM_POINTER_BLOCK in UMA_HISTOGRAM definitions.
1065 #define RPP_HISTOGRAM_MEDIUM_TIMES(name, page_load_time) \
1066 do { \
1067 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( \
1068 name, \
1069 base::TimeDelta::FromMilliseconds(10), \
1070 base::TimeDelta::FromMinutes(3), \
1071 50, \
1072 base::HistogramBase::kUmaTargetedHistogramFlag); \
1073 histogram->AddTime(page_load_time); \
1074 } while (0)
1075
1076 void ResourcePrefetchPredictor::ReportPageLoadTimeStats(
1077 base::TimeDelta plt) const {
1078 net::NetworkChangeNotifier::ConnectionType connection_type =
1079 net::NetworkChangeNotifier::GetConnectionType();
1080
1081 RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT", plt);
1082 RPP_HISTOGRAM_MEDIUM_TIMES(
1083 "ResourcePrefetchPredictor.PLT_" + GetNetTypeStr(), plt);
1084 if (net::NetworkChangeNotifier::IsConnectionCellular(connection_type))
1085 RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT_Cellular", plt);
1086 }
1087
1088 void ResourcePrefetchPredictor::ReportPageLoadTimePrefetchStats(
1089 base::TimeDelta plt,
1090 bool prefetched,
1091 base::Callback<void(int)> report_network_type_callback,
1092 PrefetchKeyType key_type) const {
1093 net::NetworkChangeNotifier::ConnectionType connection_type =
1094 net::NetworkChangeNotifier::GetConnectionType();
1095 bool on_cellular =
1096 net::NetworkChangeNotifier::IsConnectionCellular(connection_type);
1097
1098 report_network_type_callback.Run(CONNECTION_ALL);
1099 report_network_type_callback.Run(connection_type);
1100 if (on_cellular)
1101 report_network_type_callback.Run(CONNECTION_CELLULAR);
1102
1103 std::string prefetched_str;
1104 if (prefetched)
1105 prefetched_str = "Prefetched";
1106 else
1107 prefetched_str = "NotPrefetched";
1108
1109 RPP_HISTOGRAM_MEDIUM_TIMES(
1110 "ResourcePrefetchPredictor.PLT." + prefetched_str, plt);
1111 RPP_HISTOGRAM_MEDIUM_TIMES(
1112 "ResourcePrefetchPredictor.PLT." + prefetched_str + "_" + GetNetTypeStr(),
1113 plt);
1114 if (on_cellular) {
1115 RPP_HISTOGRAM_MEDIUM_TIMES(
1116 "ResourcePrefetchPredictor.PLT." + prefetched_str + "_Cellular", plt);
1117 }
1118
1119 if (!prefetched)
1120 return;
1121
1122 std::string type =
1123 key_type == PREFETCH_KEY_TYPE_HOST ? "Host" : "Url";
1124 RPP_HISTOGRAM_MEDIUM_TIMES(
1125 "ResourcePrefetchPredictor.PLT.Prefetched." + type, plt);
1126 RPP_HISTOGRAM_MEDIUM_TIMES(
1127 "ResourcePrefetchPredictor.PLT.Prefetched." + type + "_"
1128 + GetNetTypeStr(),
1129 plt);
1130 if (on_cellular) {
1131 RPP_HISTOGRAM_MEDIUM_TIMES(
1132 "ResourcePrefetchPredictor.PLT.Prefetched." + type + "_Cellular",
1133 plt);
1134 }
1135 }
1007 1136
1008 void ResourcePrefetchPredictor::ReportAccuracyStats( 1137 void ResourcePrefetchPredictor::ReportAccuracyStats(
1009 PrefetchKeyType key_type, 1138 PrefetchKeyType key_type,
1010 const std::vector<URLRequestSummary>& actual, 1139 const std::vector<URLRequestSummary>& actual,
1011 ResourcePrefetcher::RequestVector* prefetched) const { 1140 ResourcePrefetcher::RequestVector* prefetched) const {
1012 // Annotate the results. 1141 // Annotate the results.
1013 std::map<GURL, bool> actual_resources; 1142 std::map<GURL, bool> actual_resources;
1014 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); 1143 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin();
1015 it != actual.end(); ++it) { 1144 it != actual.end(); ++it) {
1016 actual_resources[it->resource_url] = it->was_cached; 1145 actual_resources[it->resource_url] = it->was_cached;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 prefetch_network * 100.0 / num_assumed_prefetched); 1339 prefetch_network * 100.0 / num_assumed_prefetched);
1211 1340
1212 // Measure the ratio of total number of resources prefetched from network vs 1341 // Measure the ratio of total number of resources prefetched from network vs
1213 // the total number of resources fetched by the page from the network. 1342 // the total number of resources fetched by the page from the network.
1214 if (total_resources_fetched_from_network > 0) { 1343 if (total_resources_fetched_from_network > 0) {
1215 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( 1344 RPP_PREDICTED_HISTOGRAM_PERCENTAGE(
1216 "PrefetchFromNetworkPercentOfTotalFromNetwork", 1345 "PrefetchFromNetworkPercentOfTotalFromNetwork",
1217 prefetch_network * 100.0 / total_resources_fetched_from_network); 1346 prefetch_network * 100.0 / total_resources_fetched_from_network);
1218 } 1347 }
1219 1348
1349 #undef RPP_HISTOGRAM_MEDIUM_TIMES
1220 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE 1350 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE
1221 #undef RPP_PREDICTED_HISTOGRAM_COUNTS 1351 #undef RPP_PREDICTED_HISTOGRAM_COUNTS
1222 } 1352 }
1223 1353
1224 } // namespace predictors 1354 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698