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

Side by Side Diff: components/precache/core/precache_fetcher.cc

Issue 2711473006: Add Precache.Fetch.MinWeight UMA. (Closed)
Patch Set: Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/precache/core/precache_fetcher.h" 5 #include "components/precache/core/precache_fetcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 response_bytes_ = source->GetReceivedResponseContentLength(); 385 response_bytes_ = source->GetReceivedResponseContentLength();
386 network_response_bytes_ = source->GetTotalReceivedBytes(); 386 network_response_bytes_ = source->GetTotalReceivedBytes();
387 was_cached_ = source->WasCached(); 387 was_cached_ = source->WasCached();
388 callback_.Run(*this); 388 callback_.Run(*this);
389 } 389 }
390 390
391 // static 391 // static
392 void PrecacheFetcher::RecordCompletionStatistics( 392 void PrecacheFetcher::RecordCompletionStatistics(
393 const PrecacheUnfinishedWork& unfinished_work, 393 const PrecacheUnfinishedWork& unfinished_work,
394 size_t remaining_manifest_urls_to_fetch, 394 size_t remaining_manifest_urls_to_fetch,
395 size_t remaining_resource_urls_to_fetch) { 395 size_t remaining_resource_urls_to_fetch,
396 base::Optional<double> min_weight_fetched) {
396 // These may be unset in tests. 397 // These may be unset in tests.
397 if (!unfinished_work.has_start_time()) 398 if (!unfinished_work.has_start_time())
398 return; 399 return;
399 base::TimeDelta time_to_fetch = 400 base::TimeDelta time_to_fetch =
400 base::Time::Now() - 401 base::Time::Now() -
401 base::Time::FromInternalValue(unfinished_work.start_time()); 402 base::Time::FromInternalValue(unfinished_work.start_time());
402 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch, 403 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch,
403 base::TimeDelta::FromSeconds(1), 404 base::TimeDelta::FromSeconds(1),
404 base::TimeDelta::FromHours(4), 50); 405 base::TimeDelta::FromHours(4), 50);
405 406
406 int num_total_resources = unfinished_work.num_resource_urls(); 407 int num_total_resources = unfinished_work.num_resource_urls();
407 int percent_completed = 408 int percent_completed =
408 num_total_resources == 0 409 num_total_resources == 0
409 ? 101 // Overflow bucket. 410 ? 101 // Overflow bucket.
410 : (100 * (static_cast<double>(num_total_resources - 411 : (100 * (static_cast<double>(num_total_resources -
411 remaining_resource_urls_to_fetch) / 412 remaining_resource_urls_to_fetch) /
412 num_total_resources)); 413 num_total_resources));
413 414
414 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted", 415 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted",
415 percent_completed); 416 percent_completed);
416 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Total", 417 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Total",
417 unfinished_work.total_bytes(), 1, 418 unfinished_work.total_bytes(), 1,
418 kMaxResponseBytes, 100); 419 kMaxResponseBytes, 100);
419 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Network", 420 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Network",
420 unfinished_work.network_bytes(), 1, 421 unfinished_work.network_bytes(), 1,
421 kMaxResponseBytes, 100); 422 kMaxResponseBytes, 100);
423
424 if (min_weight_fetched.has_value()) {
425 UMA_HISTOGRAM_COUNTS_1000("Precache.Fetch.MinWeight",
426 min_weight_fetched.value() * 1000);
twifkak 2017/02/22 18:20:00 BTW, the bucket boundaries will look approximately
427 }
422 } 428 }
423 429
424 // static 430 // static
425 std::string PrecacheFetcher::GetResourceURLBase64HashForTesting( 431 std::string PrecacheFetcher::GetResourceURLBase64HashForTesting(
426 const std::vector<GURL>& urls) { 432 const std::vector<GURL>& urls) {
427 return GetResourceURLBase64Hash(urls); 433 return GetResourceURLBase64Hash(urls);
428 } 434 }
429 435
430 PrecacheFetcher::PrecacheFetcher( 436 PrecacheFetcher::PrecacheFetcher(
431 net::URLRequestContextGetter* request_context, 437 net::URLRequestContextGetter* request_context,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 request_context_.get(), top_host.manifest_url, top_host.hostname, 560 request_context_.get(), top_host.manifest_url, top_host.hostname,
555 base::Bind(&PrecacheFetcher::OnManifestFetchComplete, AsWeakPtr(), 561 base::Bind(&PrecacheFetcher::OnManifestFetchComplete, AsWeakPtr(),
556 top_host.visits), 562 top_host.visits),
557 false /* is_resource_request */, std::numeric_limits<int32_t>::max(), 563 false /* is_resource_request */, std::numeric_limits<int32_t>::max(),
558 false /* revalidation_only */)); 564 false /* revalidation_only */));
559 top_hosts_fetching_.push_back(std::move(top_host)); 565 top_hosts_fetching_.push_back(std::move(top_host));
560 top_hosts_to_fetch_.pop_front(); 566 top_hosts_to_fetch_.pop_front();
561 } 567 }
562 } 568 }
563 569
564 void PrecacheFetcher::NotifyDone( 570 void PrecacheFetcher::NotifyDone(size_t remaining_manifest_urls_to_fetch,
565 size_t remaining_manifest_urls_to_fetch, 571 size_t remaining_resource_urls_to_fetch,
566 size_t remaining_resource_urls_to_fetch) { 572 base::Optional<double> min_weight_fetched) {
567 RecordCompletionStatistics(*unfinished_work_, 573 RecordCompletionStatistics(
568 remaining_manifest_urls_to_fetch, 574 *unfinished_work_, remaining_manifest_urls_to_fetch,
569 remaining_resource_urls_to_fetch); 575 remaining_resource_urls_to_fetch, min_weight_fetched);
570 precache_delegate_->OnDone(); 576 precache_delegate_->OnDone();
571 } 577 }
572 578
573 void PrecacheFetcher::StartNextFetch() { 579 void PrecacheFetcher::StartNextFetch() {
574 DCHECK(unfinished_work_->has_config_settings()); 580 DCHECK(unfinished_work_->has_config_settings());
575 581
576 // If over the precache total size cap or daily quota, then stop prefetching. 582 // If over the precache total size cap or daily quota, then stop prefetching.
577 if ((unfinished_work_->total_bytes() > 583 if ((unfinished_work_->total_bytes() >
578 unfinished_work_->config_settings().max_bytes_total()) || 584 unfinished_work_->config_settings().max_bytes_total()) ||
579 quota_.remaining() == 0) { 585 quota_.remaining() == 0) {
580 pool_.DeleteAll(); 586 pool_.DeleteAll();
587 base::Optional<double> min_weight;
588 if (unfinished_work_->config_settings().global_ranking() &&
589 !resources_to_fetch_.empty())
jamartin 2017/02/22 22:54:07 If resources_to_fetch_.empty(), shouldn't you repo
twifkak 2017/02/23 23:28:41 Yes. This is a bit of an edge case, I think. If th
590 min_weight.emplace(resources_to_fetch_.front().weight);
581 NotifyDone(top_hosts_to_fetch_.size() + top_hosts_fetching_.size(), 591 NotifyDone(top_hosts_to_fetch_.size() + top_hosts_fetching_.size(),
582 resources_to_fetch_.size() + resources_fetching_.size()); 592 resources_to_fetch_.size() + resources_fetching_.size(),
593 min_weight);
jamartin 2017/02/22 22:54:07 I wonder if we may want to report also the rank di
twifkak 2017/02/23 23:28:41 The problem is that rank 23 for host A may mean so
583 return; 594 return;
584 } 595 }
585 596
586 StartNextResourceFetch(); 597 StartNextResourceFetch();
587 StartNextManifestFetches(); 598 StartNextManifestFetches();
588 if (top_hosts_to_fetch_.empty() && resources_to_fetch_.empty() && 599 if (top_hosts_to_fetch_.empty() && resources_to_fetch_.empty() &&
589 pool_.IsEmpty()) { 600 pool_.IsEmpty()) {
590 // There are no more URLs to fetch, so end the precache cycle. 601 // There are no more URLs to fetch, so end the precache cycle.
591 NotifyDone(0, 0); 602 base::Optional<double> min_weight;
603 if (unfinished_work_->config_settings().global_ranking())
604 min_weight.emplace(0);
jamartin 2017/02/22 22:54:07 (nit/opt) I prefer min_weight = 0.
twifkak 2017/02/23 23:28:42 Me too. Somehow I missed operator= when scanning t
605 NotifyDone(0, 0, min_weight);
592 // OnDone may have deleted this PrecacheFetcher, so don't do anything after 606 // OnDone may have deleted this PrecacheFetcher, so don't do anything after
593 // it is called. 607 // it is called.
594 } 608 }
595 } 609 }
596 610
597 void PrecacheFetcher::OnConfigFetchComplete(const Fetcher& source) { 611 void PrecacheFetcher::OnConfigFetchComplete(const Fetcher& source) {
598 UpdateStats(source.response_bytes(), source.network_response_bytes()); 612 UpdateStats(source.response_bytes(), source.network_response_bytes());
599 if (source.network_url_fetcher() == nullptr) { 613 if (source.network_url_fetcher() == nullptr) {
600 pool_.DeleteAll(); // Cancel any other ongoing request. 614 pool_.DeleteAll(); // Cancel any other ongoing request.
601 } else { 615 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 void PrecacheFetcher::OnManifestInfoRetrieved( 667 void PrecacheFetcher::OnManifestInfoRetrieved(
654 std::deque<ManifestHostInfo> manifests_info) { 668 std::deque<ManifestHostInfo> manifests_info) {
655 const std::string prefix = manifest_url_prefix_.empty() 669 const std::string prefix = manifest_url_prefix_.empty()
656 ? GetDefaultManifestURLPrefix() 670 ? GetDefaultManifestURLPrefix()
657 : manifest_url_prefix_; 671 : manifest_url_prefix_;
658 if (!GURL(prefix).is_valid()) { 672 if (!GURL(prefix).is_valid()) {
659 // Don't attempt to fetch any manifests if the manifest URL prefix 673 // Don't attempt to fetch any manifests if the manifest URL prefix
660 // is invalid. 674 // is invalid.
661 top_hosts_to_fetch_.clear(); 675 top_hosts_to_fetch_.clear();
662 unfinished_work_->set_num_manifest_urls(manifests_info.size()); 676 unfinished_work_->set_num_manifest_urls(manifests_info.size());
663 NotifyDone(manifests_info.size(), resources_to_rank_.size()); 677 NotifyDone(manifests_info.size(), resources_to_rank_.size(), base::nullopt);
664 return; 678 return;
665 } 679 }
666 680
667 top_hosts_to_fetch_ = std::move(manifests_info); 681 top_hosts_to_fetch_ = std::move(manifests_info);
668 for (auto& manifest : top_hosts_to_fetch_) { 682 for (auto& manifest : top_hosts_to_fetch_) {
669 manifest.manifest_url = 683 manifest.manifest_url =
670 GURL(prefix + 684 GURL(prefix +
671 net::EscapeQueryParamValue( 685 net::EscapeQueryParamValue(
672 net::EscapeQueryParamValue(manifest.hostname, false), false)); 686 net::EscapeQueryParamValue(manifest.hostname, false), false));
673 if (manifest.manifest_id != PrecacheReferrerHostEntry::kInvalidId) { 687 if (manifest.manifest_id != PrecacheReferrerHostEntry::kInvalidId) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 remaining = 0; 857 remaining = 0;
844 quota_.set_remaining( 858 quota_.set_remaining(
845 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); 859 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes);
846 db_task_runner_->PostTask( 860 db_task_runner_->PostTask(
847 FROM_HERE, 861 FROM_HERE,
848 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); 862 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_));
849 } 863 }
850 } 864 }
851 865
852 } // namespace precache 866 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698