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

Unified Diff: tools/perf/profile_creators/fast_navigation_profile_extender.py

Issue 939143004: Telemetry: Fix several small problems in the profile creator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/perf/profile_creators/fast_navigation_profile_extender.py
diff --git a/tools/perf/profile_creators/fast_navigation_profile_extender.py b/tools/perf/profile_creators/fast_navigation_profile_extender.py
index ec2cb7ce7f137fa9ba72841560f071cd8e6f6261..3b3b2ddad1310428e88af68c5d2427c2aeecd2d0 100644
--- a/tools/perf/profile_creators/fast_navigation_profile_extender.py
+++ b/tools/perf/profile_creators/fast_navigation_profile_extender.py
@@ -8,6 +8,7 @@ from telemetry.core import browser_finder_exceptions
from telemetry.core import exceptions
from telemetry.core import platform
from telemetry.core import util
+from telemetry.core.backends.chrome_inspector import devtools_http
class FastNavigationProfileExtender(object):
@@ -40,6 +41,10 @@ class FastNavigationProfileExtender(object):
# This member is initialized during SetUp().
self._browser = None
+ # The list of tabs to use for url navigations. This list may not contain
+ # all tabs in the browser.
+ self._navigation_tabs = []
+
# The number of tabs to use.
self._NUM_TABS = maximum_batch_size
@@ -95,9 +100,6 @@ class FastNavigationProfileExtender(object):
["win", "mac", "linux"])
self._browser = possible_browser.Create(finder_options)
- while(len(self._browser.tabs) < self._NUM_TABS):
- self._browser.tabs.New()
-
def TearDown(self):
"""Teardown that is guaranteed to be executed before the instance is
destroyed.
@@ -121,6 +123,26 @@ class FastNavigationProfileExtender(object):
def profile_path(self):
return self._profile_path
+ def _RefreshNavigationTabs(self):
+ """Updates the member self._navigation_tabs to contain self._NUM_TABS
+ elements, each of which is not crashed. The crashed tabs are intentionally
+ leaked, since Telemetry doesn't have a good way of killing crashed tabs."""
+ live_tabs = []
+ for tab in self._navigation_tabs:
+ try:
+ live_tab = self._browser.tabs.GetTabById(tab.id)
nednguyen 2015/02/19 20:05:04 If you have to do this just to get the "live tab",
erikchen 2015/02/19 21:55:12 I've added comments - this method is doing more th
+ live_tabs.append(live_tab)
+ except KeyError:
+ pass
+
+ self._navigation_tabs = live_tabs
+
+ while len(self._navigation_tabs) < self._NUM_TABS:
+ self._navigation_tabs.append(self._browser.tabs.New())
+
+ def _RemoveNavigationTab(self, tab):
+ self._navigation_tabs.remove(tab)
+
def _GetPossibleBrowser(self, finder_options):
"""Return a possible_browser with the given options."""
possible_browser = browser_finder.FindBrowser(finder_options)
@@ -137,7 +159,9 @@ class FastNavigationProfileExtender(object):
"""Retrives the URL of the tab."""
try:
return tab.EvaluateJavaScript('document.URL', timeout)
- except exceptions.DevtoolsTargetCrashException:
+ except (exceptions.DevtoolsTargetCrashException,
+ devtools_http.DevToolsClientConnectionError,
+ devtools_http.DevToolsClientUrlError):
return None
def _WaitForUrlToChange(self, tab, initial_url, timeout):
@@ -178,9 +202,12 @@ class FastNavigationProfileExtender(object):
try:
tab.Navigate(url, None, timeout_in_seconds)
- except exceptions.DevtoolsTargetCrashException:
- # We expect a time out, and don't mind if the webpage crashes. Ignore
- # both exceptions.
+ except (exceptions.DevtoolsTargetCrashException,
+ devtools_http.DevToolsClientConnectionError,
+ devtools_http.DevToolsClientUrlError):
+ # We expect a time out. It's possible for other problems to arise, but
+ # this method is not responsible for dealing with them. Ignore all
+ # exceptions.
pass
queued_tabs.append((tab, initial_url))
@@ -210,9 +237,15 @@ class FastNavigationProfileExtender(object):
try:
tab.WaitForDocumentReadyStateToBeComplete(seconds_to_wait)
- except (util.TimeoutException, exceptions.DevtoolsTargetCrashException):
- # Ignore time outs and web page crashes.
+ except util.TimeoutException:
+ # Ignore time outs.
pass
+ except (exceptions.DevtoolsTargetCrashException,
+ devtools_http.DevToolsClientConnectionError,
+ devtools_http.DevToolsClientUrlError):
+ # If any error occurs, remove the tab. it's probably in an
+ # unrecoverable state.
+ self._RemoveNavigationTab(tab)
def _GetUrlsToNavigate(self, url_iterator):
"""Returns an array of urls to navigate to, given a url_iterator."""
@@ -231,6 +264,7 @@ class FastNavigationProfileExtender(object):
"""
url_iterator = self.GetUrlIterator()
while True:
+ self._RefreshNavigationTabs()
urls = self._GetUrlsToNavigate(url_iterator)
if len(urls) == 0:
@@ -239,7 +273,7 @@ class FastNavigationProfileExtender(object):
batch = []
for i in range(len(urls)):
url = urls[i]
- tab = self._browser.tabs[i]
+ tab = self._navigation_tabs[i]
batch.append((tab, url))
queued_tabs = self._BatchNavigateTabs(batch)

Powered by Google App Engine
This is Rietveld 408576698