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

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

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

Powered by Google App Engine
This is Rietveld 408576698