 Chromium Code Reviews
 Chromium Code Reviews Issue 14949012:
  Add instrumentation to see how often a local predictor prerender could be  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/
    
  
    Issue 14949012:
  Add instrumentation to see how often a local predictor prerender could be  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prerender/prerender_local_predictor.h" | 5 #include "chrome/browser/prerender/prerender_local_predictor.h" | 
| 6 | 6 | 
| 7 #include <ctype.h> | 7 #include <ctype.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <map> | 10 #include <map> | 
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 base::Time actual_start_time; | 299 base::Time actual_start_time; | 
| 300 | 300 | 
| 301 private: | 301 private: | 
| 302 DISALLOW_IMPLICIT_CONSTRUCTORS(PrerenderProperties); | 302 DISALLOW_IMPLICIT_CONSTRUCTORS(PrerenderProperties); | 
| 303 }; | 303 }; | 
| 304 | 304 | 
| 305 PrerenderLocalPredictor::PrerenderLocalPredictor( | 305 PrerenderLocalPredictor::PrerenderLocalPredictor( | 
| 306 PrerenderManager* prerender_manager) | 306 PrerenderManager* prerender_manager) | 
| 307 : prerender_manager_(prerender_manager), | 307 : prerender_manager_(prerender_manager), | 
| 308 is_visit_database_observer_(false), | 308 is_visit_database_observer_(false), | 
| 309 weak_factory_(this) { | 309 weak_factory_(this), | 
| 310 current_prerender_would_have_matched_(false) { | |
| 310 RecordEvent(EVENT_CONSTRUCTED); | 311 RecordEvent(EVENT_CONSTRUCTED); | 
| 311 if (MessageLoop::current()) { | 312 if (MessageLoop::current()) { | 
| 312 timer_.Start(FROM_HERE, | 313 timer_.Start(FROM_HERE, | 
| 313 base::TimeDelta::FromMilliseconds(kInitDelayMs), | 314 base::TimeDelta::FromMilliseconds(kInitDelayMs), | 
| 314 this, | 315 this, | 
| 315 &PrerenderLocalPredictor::Init); | 316 &PrerenderLocalPredictor::Init); | 
| 316 RecordEvent(EVENT_INIT_SCHEDULED); | 317 RecordEvent(EVENT_INIT_SCHEDULED); | 
| 317 } | 318 } | 
| 318 | 319 | 
| 319 static const size_t kChecksumHashSize = 32; | 320 static const size_t kChecksumHashSize = 32; | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 WebContents* source_web_contents = NULL; | 476 WebContents* source_web_contents = NULL; | 
| 476 | 477 | 
| 477 #if !defined(OS_ANDROID) | 478 #if !defined(OS_ANDROID) | 
| 478 // We need to figure out what tab launched the prerender. We do this by | 479 // We need to figure out what tab launched the prerender. We do this by | 
| 479 // comparing URLs. This may not always work: the URL may occur in two | 480 // comparing URLs. This may not always work: the URL may occur in two | 
| 480 // tabs, and we pick the wrong one, or the tab we should have picked | 481 // tabs, and we pick the wrong one, or the tab we should have picked | 
| 481 // may have navigated elsewhere. Hopefully, this doesn't happen too often, | 482 // may have navigated elsewhere. Hopefully, this doesn't happen too often, | 
| 482 // so we ignore these cases for now. | 483 // so we ignore these cases for now. | 
| 483 // TODO(tburkard): Reconsider this, potentially measure it, and fix this | 484 // TODO(tburkard): Reconsider this, potentially measure it, and fix this | 
| 484 // in the future. | 485 // in the future. | 
| 485 for (TabContentsIterator it; !it.done(); it.Next()) { | 486 for (TabContentsIterator it; !it.done(); it.Next()) { | 
| 
Shishir
2013/05/14 18:19:34
Since you are adding stats, how about adding a sta
 
tburkard
2013/05/14 19:28:06
Done.
 | |
| 486 if (it->GetURL() == info->source_url_.url) { | 487 if (it->GetURL() == info->source_url_.url) { | 
| 487 source_web_contents = *it; | 488 source_web_contents = *it; | 
| 488 break; | 489 break; | 
| 489 } | 490 } | 
| 490 } | 491 } | 
| 491 #endif | 492 #endif | 
| 492 | 493 | 
| 493 if (!source_web_contents) { | 494 if (!source_web_contents) { | 
| 494 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); | 495 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); | 
| 495 return; | 496 return; | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 const GURL& url = info->url; | 725 const GURL& url = info->url; | 
| 725 double priority = info->priority; | 726 double priority = info->priority; | 
| 726 base::Time current_time = GetCurrentTime(); | 727 base::Time current_time = GetCurrentTime(); | 
| 727 RecordEvent(EVENT_ISSUING_PRERENDER); | 728 RecordEvent(EVENT_ISSUING_PRERENDER); | 
| 728 | 729 | 
| 729 current_prerender_priority_ = priority; | 730 current_prerender_priority_ = priority; | 
| 730 scoped_ptr<prerender::PrerenderHandle> old_prerender_handle( | 731 scoped_ptr<prerender::PrerenderHandle> old_prerender_handle( | 
| 731 prerender_handle_.release()); | 732 prerender_handle_.release()); | 
| 732 prerender_handle_.reset(prerender_manager_->AddPrerenderFromLocalPredictor( | 733 prerender_handle_.reset(prerender_manager_->AddPrerenderFromLocalPredictor( | 
| 733 url, session_storage_namespace.get(), *size)); | 734 url, session_storage_namespace.get(), *size)); | 
| 735 current_prerender_would_have_matched_ = false; | |
| 734 if (old_prerender_handle) | 736 if (old_prerender_handle) | 
| 735 old_prerender_handle->OnCancel(); | 737 old_prerender_handle->OnCancel(); | 
| 736 | 738 | 
| 737 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); | 739 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); | 
| 738 if (current_prerender_.get() && current_prerender_->url_id == url_id) { | 740 if (current_prerender_.get() && current_prerender_->url_id == url_id) { | 
| 739 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); | 741 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); | 
| 740 if (priority > current_prerender_->priority) | 742 if (priority > current_prerender_->priority) | 
| 741 current_prerender_->priority = priority; | 743 current_prerender_->priority = priority; | 
| 742 // If the prerender already existed, we want to extend it. However, | 744 // If the prerender already existed, we want to extend it. However, | 
| 743 // we do not want to set its start_time to the current time to | 745 // we do not want to set its start_time to the current time to | 
| 744 // disadvantage PLT computations when the prerender is swapped in. | 746 // disadvantage PLT computations when the prerender is swapped in. | 
| 745 // So we set the new start time to current_time - 10s (since the vast | 747 // So we set the new start time to current_time - 10s (since the vast | 
| 746 // majority of PLTs are < 10s), provided that is not before the actual | 748 // majority of PLTs are < 10s), provided that is not before the actual | 
| 747 // time the prerender was started (so as to not artificially advantage | 749 // time the prerender was started (so as to not artificially advantage | 
| 748 // the PLT computation). | 750 // the PLT computation). | 
| 749 base::Time simulated_new_start_time = | 751 base::Time simulated_new_start_time = | 
| 750 current_time - base::TimeDelta::FromSeconds(10); | 752 current_time - base::TimeDelta::FromSeconds(10); | 
| 751 if (simulated_new_start_time > current_prerender_->start_time) | 753 if (simulated_new_start_time > current_prerender_->start_time) | 
| 752 current_prerender_->start_time = simulated_new_start_time; | 754 current_prerender_->start_time = simulated_new_start_time; | 
| 753 } else { | 755 } else { | 
| 754 current_prerender_.reset( | 756 current_prerender_.reset( | 
| 755 new PrerenderProperties(url_id, url, priority, current_time)); | 757 new PrerenderProperties(url_id, url, priority, current_time)); | 
| 756 } | 758 } | 
| 757 current_prerender_->actual_start_time = current_time; | 759 current_prerender_->actual_start_time = current_time; | 
| 758 } | 760 } | 
| 759 | 761 | 
| 762 void PrerenderLocalPredictor::OnTabHelperURLSeen( | |
| 763 const GURL& url, WebContents* web_contents) { | |
| 764 RecordEvent(EVENT_TAB_HELPER_URL_SEEN); | |
| 
Shishir
2013/05/14 18:19:34
This event will have a lot of duplicates since it
 
tburkard
2013/05/14 19:28:06
We already have other events for when a DidNavigat
 | |
| 765 if (current_prerender_would_have_matched_ || | |
| 766 !prerender_handle_.get() || | |
| 767 !prerender_handle_->Matches(url, NULL)) { | |
| 
Shishir
2013/05/14 18:19:34
Can you call this with NULL if the prerender is li
 
tburkard
2013/05/14 19:28:06
Done.
 | |
| 768 return; | |
| 769 } | |
| 770 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_MATCH); | |
| 771 if (prerender_handle_->Matches( | |
| 772 url, | |
| 773 web_contents->GetController().GetDefaultSessionStorageNamespace())) { | |
| 774 RecordEvent(EVENT_TAB_HELPER_URL_SEEN_NAMESPACE_MATCH); | |
| 775 } | |
| 776 current_prerender_would_have_matched_ = true; | |
| 
Shishir
2013/05/14 18:19:34
Can you add a comment as to the conditions where t
 
tburkard
2013/05/14 19:28:06
Done.
 | |
| 777 } | |
| 778 | |
| 760 } // namespace prerender | 779 } // namespace prerender | 
| OLD | NEW |