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

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

Issue 2937623007: predictors: Move more methods from ResourcePrefetchPredictor into LoadingDataCollector. (Closed)
Patch Set: Combine RecordMainFrameLoadComplete and OnNavigationComplete. Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/loading_stats_collector.h" 5 #include "chrome/browser/predictors/loading_stats_collector.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "chrome/browser/predictors/loading_data_collector.h"
11 12
12 namespace predictors { 13 namespace predictors {
13 14
14 namespace { 15 namespace {
15 16
16 void ReportPredictionAccuracy( 17 void ReportPredictionAccuracy(
17 const ResourcePrefetchPredictor::Prediction& prediction, 18 const ResourcePrefetchPredictor::Prediction& prediction,
18 const ResourcePrefetchPredictor::PageRequestSummary& summary) { 19 const PageRequestSummary& summary) {
19 const std::vector<GURL>& predicted_urls = prediction.subresource_urls; 20 const std::vector<GURL>& predicted_urls = prediction.subresource_urls;
20 if (predicted_urls.empty() || summary.subresource_requests.empty()) 21 if (predicted_urls.empty() || summary.subresource_requests.empty())
21 return; 22 return;
22 23
23 std::set<GURL> predicted_urls_set(predicted_urls.begin(), 24 std::set<GURL> predicted_urls_set(predicted_urls.begin(),
24 predicted_urls.end()); 25 predicted_urls.end());
25 std::set<GURL> actual_urls_set; 26 std::set<GURL> actual_urls_set;
26 for (const auto& request_summary : summary.subresource_requests) 27 for (const auto& request_summary : summary.subresource_requests)
27 actual_urls_set.emplace(request_summary.resource_url); 28 actual_urls_set.emplace(request_summary.resource_url);
28 29
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 precision_percentage); 63 precision_percentage);
63 UMA_HISTOGRAM_PERCENTAGE(internal::kResourcePrefetchPredictorRecallHistogram, 64 UMA_HISTOGRAM_PERCENTAGE(internal::kResourcePrefetchPredictorRecallHistogram,
64 recall_percentage); 65 recall_percentage);
65 UMA_HISTOGRAM_COUNTS_100(internal::kResourcePrefetchPredictorCountHistogram, 66 UMA_HISTOGRAM_COUNTS_100(internal::kResourcePrefetchPredictorCountHistogram,
66 predicted_urls.size()); 67 predicted_urls.size());
67 UMA_HISTOGRAM_ENUMERATION( 68 UMA_HISTOGRAM_ENUMERATION(
68 internal::kResourcePrefetchPredictorRedirectStatusHistogram, 69 internal::kResourcePrefetchPredictorRedirectStatusHistogram,
69 static_cast<int>(redirect_status), static_cast<int>(RedirectStatus::MAX)); 70 static_cast<int>(redirect_status), static_cast<int>(RedirectStatus::MAX));
70 } 71 }
71 72
72 void ReportPrefetchAccuracy( 73 void ReportPrefetchAccuracy(const ResourcePrefetcher::PrefetcherStats& stats,
73 const ResourcePrefetcher::PrefetcherStats& stats, 74 const std::vector<URLRequestSummary>& requests) {
74 const std::vector<ResourcePrefetchPredictor::URLRequestSummary>& requests) {
75 if (stats.requests_stats.empty()) 75 if (stats.requests_stats.empty())
76 return; 76 return;
77 77
78 std::set<GURL> urls; 78 std::set<GURL> urls;
79 for (const auto& request : requests) 79 for (const auto& request : requests)
80 urls.emplace(request.resource_url); 80 urls.emplace(request.resource_url);
81 81
82 int cached_misses_count = 0; 82 int cached_misses_count = 0;
83 int not_cached_misses_count = 0; 83 int not_cached_misses_count = 0;
84 int cached_hits_count = 0; 84 int cached_hits_count = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 config.max_navigation_lifetime_seconds)) {} 128 config.max_navigation_lifetime_seconds)) {}
129 129
130 LoadingStatsCollector::~LoadingStatsCollector() = default; 130 LoadingStatsCollector::~LoadingStatsCollector() = default;
131 131
132 void LoadingStatsCollector::RecordPrefetcherStats( 132 void LoadingStatsCollector::RecordPrefetcherStats(
133 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) { 133 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) {
134 const GURL main_frame_url = stats->url; 134 const GURL main_frame_url = stats->url;
135 auto it = prefetcher_stats_.find(main_frame_url); 135 auto it = prefetcher_stats_.find(main_frame_url);
136 if (it != prefetcher_stats_.end()) { 136 if (it != prefetcher_stats_.end()) {
137 // No requests -> everything is a miss. 137 // No requests -> everything is a miss.
138 ReportPrefetchAccuracy( 138 ReportPrefetchAccuracy(*it->second, std::vector<URLRequestSummary>());
139 *it->second,
140 std::vector<ResourcePrefetchPredictor::URLRequestSummary>());
141 prefetcher_stats_.erase(it); 139 prefetcher_stats_.erase(it);
142 } 140 }
143 141
144 prefetcher_stats_.emplace(main_frame_url, std::move(stats)); 142 prefetcher_stats_.emplace(main_frame_url, std::move(stats));
145 } 143 }
146 144
147 void LoadingStatsCollector::RecordPageRequestSummary( 145 void LoadingStatsCollector::RecordPageRequestSummary(
148 const ResourcePrefetchPredictor::PageRequestSummary& summary) { 146 const PageRequestSummary& summary) {
149 const GURL& initial_url = summary.initial_url; 147 const GURL& initial_url = summary.initial_url;
150 148
151 ResourcePrefetchPredictor::Prediction prediction; 149 ResourcePrefetchPredictor::Prediction prediction;
152 if (predictor_->GetPrefetchData(initial_url, &prediction)) 150 if (predictor_->GetPrefetchData(initial_url, &prediction))
153 ReportPredictionAccuracy(prediction, summary); 151 ReportPredictionAccuracy(prediction, summary);
154 152
155 auto it = prefetcher_stats_.find(initial_url); 153 auto it = prefetcher_stats_.find(initial_url);
156 if (it != prefetcher_stats_.end()) { 154 if (it != prefetcher_stats_.end()) {
157 ReportPrefetchAccuracy(*it->second, summary.subresource_requests); 155 ReportPrefetchAccuracy(*it->second, summary.subresource_requests);
158 prefetcher_stats_.erase(it); 156 prefetcher_stats_.erase(it);
159 } 157 }
160 } 158 }
161 159
162 void LoadingStatsCollector::CleanupAbandonedStats() { 160 void LoadingStatsCollector::CleanupAbandonedStats() {
163 base::TimeTicks time_now = base::TimeTicks::Now(); 161 base::TimeTicks time_now = base::TimeTicks::Now();
164 for (auto it = prefetcher_stats_.begin(); it != prefetcher_stats_.end();) { 162 for (auto it = prefetcher_stats_.begin(); it != prefetcher_stats_.end();) {
165 if (time_now - it->second->start_time > max_stats_age_) { 163 if (time_now - it->second->start_time > max_stats_age_) {
166 // No requests -> everything is a miss. 164 // No requests -> everything is a miss.
167 ReportPrefetchAccuracy( 165 ReportPrefetchAccuracy(*it->second, std::vector<URLRequestSummary>());
168 *it->second,
169 std::vector<ResourcePrefetchPredictor::URLRequestSummary>());
170 it = prefetcher_stats_.erase(it); 166 it = prefetcher_stats_.erase(it);
171 } else { 167 } else {
172 ++it; 168 ++it;
173 } 169 }
174 } 170 }
175 } 171 }
176 172
177 } // namespace predictors 173 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698