Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor.cc |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc |
| index 41497fe7c9a80dfa85d3a7ee640e583e282d5708..2de8d4e1cdaed9a33aa87996656f67fe676653b1 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor.cc |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc |
| @@ -120,6 +120,56 @@ void GetUrlVisitCountTask::DoneRunOnMainThread() { |
| GetUrlVisitCountTask::~GetUrlVisitCountTask() {} |
| +void ReportPrefetchAccuracy( |
| + const ResourcePrefetcher::PrefetcherStats& stats, |
| + const std::vector<ResourcePrefetchPredictor::URLRequestSummary>& |
| + summaries) { |
| + if (stats.requests_stats.empty()) |
| + return; |
| + |
| + std::set<GURL> urls; |
| + for (const auto& summary : summaries) |
| + urls.insert(summary.resource_url); |
| + |
| + int cached_misses_count = 0; |
| + int not_cached_misses_count = 0; |
| + int cached_hits_count = 0; |
| + int not_cached_hits_count = 0; |
| + int64_t misses_bytes = 0; |
| + int64_t hits_bytes = 0; |
| + |
| + for (const auto& request_stats : stats.requests_stats) { |
| + bool hit = urls.find(request_stats.resource_url) != urls.end(); |
| + bool cached = request_stats.was_cached; |
| + size_t bytes = request_stats.total_received_bytes; |
| + |
| + cached_hits_count += cached && hit; |
| + cached_misses_count += cached && !hit; |
| + not_cached_hits_count += !cached && hit; |
| + not_cached_misses_count += !cached && !hit; |
| + misses_bytes += !hit * bytes; |
| + hits_bytes += hit * bytes; |
| + } |
| + |
| + UMA_HISTOGRAM_COUNTS_100( |
| + internal::kResourcePrefetchPredictorPrefetchMissesCountCached, |
| + cached_misses_count); |
| + UMA_HISTOGRAM_COUNTS_100( |
| + internal::kResourcePrefetchPredictorPrefetchMissesCountNotCached, |
| + not_cached_misses_count); |
| + UMA_HISTOGRAM_COUNTS_100( |
| + internal::kResourcePrefetchPredictorPrefetchHitsCountCached, |
| + cached_hits_count); |
| + UMA_HISTOGRAM_COUNTS_100( |
| + internal::kResourcePrefetchPredictorPrefetchHitsCountNotCached, |
| + not_cached_hits_count); |
| + UMA_HISTOGRAM_COUNTS_10000( |
| + internal::kResourcePrefetchPredictorPrefetchHitsSize, hits_bytes / 1024); |
|
Ilya Sherman
2017/02/15 00:07:41
This goes up to about 10MB, right? Is that enough
Benoit L
2017/02/15 09:55:34
I think so, yes. The amount of actual data fetched
|
| + UMA_HISTOGRAM_COUNTS_10000( |
| + internal::kResourcePrefetchPredictorPrefetchMissesSize, |
| + misses_bytes / 1024); |
| +} |
| + |
| void ReportPredictionAccuracy( |
| const std::vector<GURL>& predicted_urls, |
| const ResourcePrefetchPredictor::PageRequestSummary& summary) { |
| @@ -549,9 +599,12 @@ void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) { |
| } |
| void ResourcePrefetchPredictor::OnPrefetchingFinished( |
| - const GURL& main_frame_url) { |
| + const GURL& main_frame_url, |
| + std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) { |
| if (observer_) |
| observer_->OnPrefetchingFinished(main_frame_url); |
| + |
| + prefetcher_stats_.insert(std::make_pair(main_frame_url, std::move(stats))); |
| } |
| bool ResourcePrefetchPredictor::IsUrlPrefetchable(const GURL& main_frame_url) { |
| @@ -582,7 +635,6 @@ void ResourcePrefetchPredictor::OnMainFrameRequest( |
| const GURL& main_frame_url = request.navigation_id.main_frame_url; |
| StartPrefetching(main_frame_url, PrefetchOrigin::NAVIGATION); |
| - // Cleanup older navigations. |
| CleanupAbandonedNavigations(request.navigation_id); |
| // New empty navigation entry. |
| @@ -657,12 +709,20 @@ void ResourcePrefetchPredictor::OnNavigationComplete( |
| std::unique_ptr<PageRequestSummary> summary = std::move(nav_it->second); |
| inflight_navigations_.erase(nav_it); |
| + const GURL& main_frame_url = nav_id_without_timing_info.main_frame_url; |
| std::vector<GURL> predicted_urls; |
| - bool has_data = GetPrefetchData(nav_id_without_timing_info.main_frame_url, |
| - &predicted_urls); |
| + bool has_data = GetPrefetchData(main_frame_url, &predicted_urls); |
| if (has_data) |
| ReportPredictionAccuracy(predicted_urls, *summary); |
| + auto it = prefetcher_stats_.find(main_frame_url); |
| + if (it != prefetcher_stats_.end()) { |
| + const std::vector<URLRequestSummary>& summaries = |
| + summary->subresource_requests; |
| + ReportPrefetchAccuracy(*it->second, summaries); |
| + prefetcher_stats_.erase(it); |
| + } |
| + |
| // Kick off history lookup to determine if we should record the URL. |
| history::HistoryService* history_service = |
| HistoryServiceFactory::GetForProfile(profile_, |
| @@ -792,6 +852,19 @@ void ResourcePrefetchPredictor::CleanupAbandonedNavigations( |
| else |
| ++it; |
| } |
| + |
| + // Remove old prefetches that haven't been claimed. |
| + for (auto stats_it = prefetcher_stats_.begin(); |
| + stats_it != prefetcher_stats_.end();) { |
| + if (time_now - stats_it->second->start_time > max_navigation_age) { |
| + // No requests -> everything is a miss. |
| + ReportPrefetchAccuracy(*stats_it->second, |
| + std::vector<URLRequestSummary>()); |
| + stats_it = prefetcher_stats_.erase(stats_it); |
| + } else { |
| + ++stats_it; |
| + } |
| + } |
| } |
| void ResourcePrefetchPredictor::DeleteAllUrls() { |