Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/browser/resource_request_info.h" | 34 #include "content/public/browser/resource_request_info.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
| 37 #include "net/base/network_change_notifier.h" | |
| 37 #include "net/http/http_response_headers.h" | 38 #include "net/http/http_response_headers.h" |
| 38 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
| 39 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
| 40 | 41 |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 // For reporting whether a subresource is handled or not, and for what reasons. | 46 // For reporting whether a subresource is handled or not, and for what reasons. |
| 46 enum ResourceStatus { | 47 enum ResourceStatus { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, | 84 REPORTING_EVENT_PARTIAL_HISTORY_CLEARED = 1, |
| 84 REPORTING_EVENT_COUNT = 2 | 85 REPORTING_EVENT_COUNT = 2 |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 void RecordNavigationEvent(NavigationEvent event) { | 88 void RecordNavigationEvent(NavigationEvent event) { |
| 88 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent", | 89 UMA_HISTOGRAM_ENUMERATION("ResourcePrefetchPredictor.NavigationEvent", |
| 89 event, | 90 event, |
| 90 NAVIGATION_EVENT_COUNT); | 91 NAVIGATION_EVENT_COUNT); |
| 91 } | 92 } |
| 92 | 93 |
| 94 enum AdditionalConnectionType { | |
| 95 CONNECTION_CELLULAR = net::NetworkChangeNotifier::CONNECTION_LAST + 1, | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
What happens if net::NetworkChangeNotifier::CONNEC
Zhen Wang
2014/10/27 14:12:47
Good point. Using UMA_HISTOGRAM_SPARSE_SLOWLY now.
Alexei Svitkine (slow)
2014/10/27 14:59:09
It involves a lock on the histogram object and a s
| |
| 96 CONNECTION_ALL = net::NetworkChangeNotifier::CONNECTION_LAST + 2, | |
| 97 CONNECTION_COUNT = net::NetworkChangeNotifier::CONNECTION_LAST + 3 | |
| 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 ReportPagePrefetchedNetworkType(int type) { | |
| 124 UMA_HISTOGRAM_ENUMERATION( | |
| 125 "ResourcePrefetchPredictor.PagePrefetchedNetworkType", | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
I suggest naming this one and the one below to hav
Zhen Wang
2014/10/27 14:12:47
We need to put pages prefetched in different netwo
Alexei Svitkine (slow)
2014/10/27 14:59:09
My suggestion is not contrary to that. I'm just su
Zhen Wang
2014/10/27 18:09:46
I see. Thanks for the clarification! Using new nam
| |
| 126 type, | |
| 127 CONNECTION_COUNT); | |
| 128 } | |
| 129 | |
| 130 void ReportPageNotPrefetchedNetworkType(int type) { | |
| 131 UMA_HISTOGRAM_ENUMERATION( | |
| 132 "ResourcePrefetchPredictor.PageNotPrefetchedNetworkType", | |
| 133 type, | |
| 134 CONNECTION_COUNT); | |
| 135 } | |
| 136 | |
| 93 } // namespace | 137 } // namespace |
| 94 | 138 |
| 95 namespace predictors { | 139 namespace predictors { |
| 96 | 140 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 141 //////////////////////////////////////////////////////////////////////////////// |
| 98 // History lookup task. | 142 // History lookup task. |
| 99 | 143 |
| 100 // Used to fetch the visit count for a URL from the History database. | 144 // Used to fetch the visit count for a URL from the History database. |
| 101 class GetUrlVisitCountTask : public history::HistoryDBTask { | 145 class GetUrlVisitCountTask : public history::HistoryDBTask { |
| 102 public: | 146 public: |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 562 |
| 519 NavigationMap::iterator nav_it = | 563 NavigationMap::iterator nav_it = |
| 520 inflight_navigations_.find(navigation_id); | 564 inflight_navigations_.find(navigation_id); |
| 521 if (nav_it == inflight_navigations_.end()) { | 565 if (nav_it == inflight_navigations_.end()) { |
| 522 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL); | 566 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_UNTRACKED_URL); |
| 523 return; | 567 return; |
| 524 } | 568 } |
| 525 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL); | 569 RecordNavigationEvent(NAVIGATION_EVENT_ONLOAD_TRACKED_URL); |
| 526 | 570 |
| 527 // Report any stats. | 571 // Report any stats. |
| 572 base::TimeDelta plt = base::TimeTicks::Now() - navigation_id.creation_time; | |
| 573 ReportPageLoadTimeStats(plt); | |
| 528 if (prefetch_manager_.get()) { | 574 if (prefetch_manager_.get()) { |
| 529 ResultsMap::iterator results_it = results_map_.find(navigation_id); | 575 ResultsMap::iterator results_it = results_map_.find(navigation_id); |
| 530 bool have_prefetch_results = results_it != results_map_.end(); | 576 bool have_prefetch_results = results_it != results_map_.end(); |
| 531 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", | 577 UMA_HISTOGRAM_BOOLEAN("ResourcePrefetchPredictor.HavePrefetchResults", |
| 532 have_prefetch_results); | 578 have_prefetch_results); |
| 533 if (have_prefetch_results) { | 579 if (have_prefetch_results) { |
| 534 ReportAccuracyStats(results_it->second->key_type, | 580 ReportAccuracyStats(results_it->second->key_type, |
| 535 *(nav_it->second), | 581 *(nav_it->second), |
| 536 results_it->second->requests.get()); | 582 results_it->second->requests.get()); |
| 583 ReportPageLoadTimePrefetchedStats(results_it->second->key_type, plt); | |
| 584 } else { | |
| 585 ReportPageLoadTimeNotPrefetchedStats(plt); | |
| 537 } | 586 } |
| 538 } else { | 587 } else { |
| 539 scoped_ptr<ResourcePrefetcher::RequestVector> requests( | 588 scoped_ptr<ResourcePrefetcher::RequestVector> requests( |
| 540 new ResourcePrefetcher::RequestVector); | 589 new ResourcePrefetcher::RequestVector); |
| 541 PrefetchKeyType key_type; | 590 PrefetchKeyType key_type; |
| 542 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) { | 591 if (GetPrefetchData(navigation_id, requests.get(), &key_type)) { |
| 543 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL); | 592 RecordNavigationEvent(NAVIGATION_EVENT_HAVE_PREDICTIONS_FOR_URL); |
| 544 ReportPredictedAccuracyStats(key_type, | 593 ReportPredictedAccuracyStats(key_type, |
| 545 *(nav_it->second), | 594 *(nav_it->second), |
| 546 *requests); | 595 *requests); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 BrowserThread::PostTask( | 1045 BrowserThread::PostTask( |
| 997 BrowserThread::DB, FROM_HERE, | 1046 BrowserThread::DB, FROM_HERE, |
| 998 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, | 1047 base::Bind(&ResourcePrefetchPredictorTables::UpdateData, |
| 999 tables_, | 1048 tables_, |
| 1000 url_data, | 1049 url_data, |
| 1001 host_data)); | 1050 host_data)); |
| 1002 } | 1051 } |
| 1003 } | 1052 } |
| 1004 | 1053 |
| 1005 //////////////////////////////////////////////////////////////////////////////// | 1054 //////////////////////////////////////////////////////////////////////////////// |
| 1006 // Accuracy measurement. | 1055 // Page load time and accuracy measurement. |
| 1056 | |
| 1057 // This is essentially UMA_HISTOGRAM_MEDIUM_TIMES, but it avoids using the | |
| 1058 // STATIC_HISTOGRAM_POINTER_BLOCK in UMA_HISTOGRAM definitions. | |
| 1059 #define RPP_HISTOGRAM_MEDIUM_TIMES(name, page_load_time) \ | |
| 1060 { \ | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
Nit: Make this a do { } while (0) loop.
Also, ind
Zhen Wang
2014/10/27 14:12:46
Done.
By the way, why do we prefer the style of "
| |
| 1061 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( \ | |
| 1062 name, \ | |
| 1063 base::TimeDelta::FromMilliseconds(10), \ | |
| 1064 base::TimeDelta::FromMinutes(3), \ | |
| 1065 50, \ | |
| 1066 base::HistogramBase::kUmaTargetedHistogramFlag); \ | |
| 1067 histogram->AddTime(page_load_time); \ | |
| 1068 } | |
| 1069 | |
| 1070 void ResourcePrefetchPredictor::ReportPageLoadTimeStats( | |
| 1071 base::TimeDelta plt) const { | |
| 1072 net::NetworkChangeNotifier::ConnectionType connection_type = | |
| 1073 net::NetworkChangeNotifier::GetConnectionType(); | |
| 1074 | |
| 1075 RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT", plt); | |
| 1076 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1077 "ResourcePrefetchPredictor.PLT" + GetNetTypeStr(), plt); | |
| 1078 if (net::NetworkChangeNotifier::IsConnectionCellular(connection_type)) | |
| 1079 RPP_HISTOGRAM_MEDIUM_TIMES("ResourcePrefetchPredictor.PLT_Cellular", plt); | |
| 1080 } | |
| 1081 | |
| 1082 void ResourcePrefetchPredictor::ReportPageLoadTimePrefetchedStats( | |
| 1083 PrefetchKeyType key_type, | |
| 1084 base::TimeDelta plt) const { | |
| 1085 net::NetworkChangeNotifier::ConnectionType connection_type = | |
| 1086 net::NetworkChangeNotifier::GetConnectionType(); | |
| 1087 bool on_cellular = | |
| 1088 net::NetworkChangeNotifier::IsConnectionCellular(connection_type); | |
| 1089 | |
| 1090 ReportPagePrefetchedNetworkType(CONNECTION_ALL); | |
| 1091 ReportPagePrefetchedNetworkType( | |
| 1092 net::NetworkChangeNotifier::GetConnectionType()); | |
| 1093 if (on_cellular) | |
| 1094 ReportPagePrefetchedNetworkType(CONNECTION_CELLULAR); | |
| 1095 | |
| 1096 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1097 "ResourcePrefetchPredictor.PLT.PagePrefetched", plt); | |
| 1098 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1099 "ResourcePrefetchPredictor.PLT.PagePrefetched"+ GetNetTypeStr(), plt); | |
| 1100 if (on_cellular) { | |
| 1101 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1102 "ResourcePrefetchPredictor.PLT.PagePrefetched_Cellular", plt); | |
| 1103 } | |
| 1104 | |
| 1105 std::string type = | |
| 1106 key_type == PREFETCH_KEY_TYPE_HOST ? "Host" : "Url"; | |
| 1107 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1108 "ResourcePrefetchPredictor.PLT.PagePrefetched." + type, plt); | |
| 1109 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1110 "ResourcePrefetchPredictor.PLT.PagePrefetched." + type + GetNetTypeStr(), | |
| 1111 plt); | |
| 1112 if (on_cellular) { | |
| 1113 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1114 "ResourcePrefetchPredictor.PLT.PagePrefetched." + type + "_Cellular", | |
| 1115 plt); | |
| 1116 } | |
| 1117 } | |
| 1118 | |
| 1119 void ResourcePrefetchPredictor::ReportPageLoadTimeNotPrefetchedStats( | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
It seems the logic of this function mirrors pretty
Zhen Wang
2014/10/27 14:12:46
Done.
| |
| 1120 base::TimeDelta plt) const { | |
| 1121 net::NetworkChangeNotifier::ConnectionType connection_type = | |
| 1122 net::NetworkChangeNotifier::GetConnectionType(); | |
| 1123 bool on_cellular = | |
| 1124 net::NetworkChangeNotifier::IsConnectionCellular(connection_type); | |
| 1125 | |
| 1126 ReportPageNotPrefetchedNetworkType(CONNECTION_ALL); | |
| 1127 ReportPageNotPrefetchedNetworkType( | |
| 1128 net::NetworkChangeNotifier::GetConnectionType()); | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
Nit: Use connection_type which you have as a varia
Zhen Wang
2014/10/27 14:12:46
Done.
| |
| 1129 if (on_cellular) | |
| 1130 ReportPageNotPrefetchedNetworkType(CONNECTION_CELLULAR); | |
| 1131 | |
| 1132 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1133 "ResourcePrefetchPredictor.PLT.PageNotPrefetched", plt); | |
| 1134 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1135 "ResourcePrefetchPredictor.PLT.PageNotPrefetched" + GetNetTypeStr(), plt); | |
|
Alexei Svitkine (slow)
2014/10/20 18:30:35
Nit: I'd find it clearer if you make the "_" be pa
Zhen Wang
2014/10/27 14:12:46
Done.
| |
| 1136 if (on_cellular) { | |
| 1137 RPP_HISTOGRAM_MEDIUM_TIMES( | |
| 1138 "ResourcePrefetchPredictor.PLT.PageNotPrefetched_Cellular", plt); | |
| 1139 } | |
| 1140 } | |
| 1007 | 1141 |
| 1008 void ResourcePrefetchPredictor::ReportAccuracyStats( | 1142 void ResourcePrefetchPredictor::ReportAccuracyStats( |
| 1009 PrefetchKeyType key_type, | 1143 PrefetchKeyType key_type, |
| 1010 const std::vector<URLRequestSummary>& actual, | 1144 const std::vector<URLRequestSummary>& actual, |
| 1011 ResourcePrefetcher::RequestVector* prefetched) const { | 1145 ResourcePrefetcher::RequestVector* prefetched) const { |
| 1012 // Annotate the results. | 1146 // Annotate the results. |
| 1013 std::map<GURL, bool> actual_resources; | 1147 std::map<GURL, bool> actual_resources; |
| 1014 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); | 1148 for (std::vector<URLRequestSummary>::const_iterator it = actual.begin(); |
| 1015 it != actual.end(); ++it) { | 1149 it != actual.end(); ++it) { |
| 1016 actual_resources[it->resource_url] = it->was_cached; | 1150 actual_resources[it->resource_url] = it->was_cached; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 prefetch_network * 100.0 / num_assumed_prefetched); | 1344 prefetch_network * 100.0 / num_assumed_prefetched); |
| 1211 | 1345 |
| 1212 // Measure the ratio of total number of resources prefetched from network vs | 1346 // 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. | 1347 // the total number of resources fetched by the page from the network. |
| 1214 if (total_resources_fetched_from_network > 0) { | 1348 if (total_resources_fetched_from_network > 0) { |
| 1215 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( | 1349 RPP_PREDICTED_HISTOGRAM_PERCENTAGE( |
| 1216 "PrefetchFromNetworkPercentOfTotalFromNetwork", | 1350 "PrefetchFromNetworkPercentOfTotalFromNetwork", |
| 1217 prefetch_network * 100.0 / total_resources_fetched_from_network); | 1351 prefetch_network * 100.0 / total_resources_fetched_from_network); |
| 1218 } | 1352 } |
| 1219 | 1353 |
| 1354 #undef RPP_HISTOGRAM_MEDIUM_TIMES | |
| 1220 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE | 1355 #undef RPP_PREDICTED_HISTOGRAM_PERCENTAGE |
| 1221 #undef RPP_PREDICTED_HISTOGRAM_COUNTS | 1356 #undef RPP_PREDICTED_HISTOGRAM_COUNTS |
| 1222 } | 1357 } |
| 1223 | 1358 |
| 1224 } // namespace predictors | 1359 } // namespace predictors |
| OLD | NEW |