Commit f1b64877 authored by tonyg@chromium.org's avatar tonyg@chromium.org

Reland: [Telemetry] Fix image_decoding_measurement timeout.

This was reverted because it caused some timeouts. The reland is the same as the
original but I now preseved the original timeout values of Page.enable and
Page.disable.

> util.WaitFor polls which is not appropriate for PerformActionAndWaitForNavigate.
>
> Since DispatchNotifications blocks in recv until it gets some data, there is no
> need to poll at an interval. Instead, we should call recv again as soon as
> possible after dispatching a notification.
>
> In the case of the image decoding measurement, it runs timeline recording. There
> were so many timeline messages to receive that we were not always getting to the
> important Page.navigate message before timing out.
>
> Example:
> http://build.chromium.org/p/chromium.perf/builders/Linux%20Perf%20%281%29/builds/27098
>
> BUG=314375
>
> Review URL: https://codereview.chromium.org/47013004

TBR=kbr@chromium.org
BUG=

Review URL: https://codereview.chromium.org/61483002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233543 0039d316-1c4b-4281-b951-d872f2087c98
parent f6514c66
......@@ -256,7 +256,7 @@ class InspectorBackend(object):
def IsBack():
return self._browser_backend.tab_list_backend.DoesDebuggerUrlExist(
self._debugger_url)
util.WaitFor(IsBack, 512, 0.5)
util.WaitFor(IsBack, 512)
sys.stderr.write('\n')
sys.stderr.write('Inspector\'s UI closed. Telemetry will now resume.\n')
self._Connect()
......
......@@ -3,8 +3,7 @@
# found in the LICENSE file.
import json
import logging
from telemetry.core import util
import time
class InspectorPage(object):
def __init__(self, inspector_backend):
......@@ -30,40 +29,37 @@ class InspectorPage(object):
def _OnClose(self):
pass
def PerformActionAndWaitForNavigate(self, action_function, timeout=60):
"""Executes action_function, and waits for the navigation to complete.
action_function is expect to result in a navigation. This function returns
when the navigation is complete or when the timeout has been exceeded.
"""
# Turn on notifications. We need them to get the Page.frameNavigated event.
def _EnablePageNotifications(self, timeout):
request = {
'method': 'Page.enable'
}
res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
def DisablePageNotifications():
request = {
'method': 'Page.disable'
}
res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
def _DisablePageNotifications(self, timeout):
request = {
'method': 'Page.disable'
}
res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
def PerformActionAndWaitForNavigate(self, action_function, timeout=60):
"""Executes action_function, and waits for the navigation to complete.
self._navigation_pending = True
action_function is expect to result in a navigation. This function returns
when the navigation is complete or when the timeout has been exceeded.
"""
start_time = time.time()
remaining_time = timeout
self._EnablePageNotifications(remaining_time)
try:
action_function()
except:
DisablePageNotifications()
raise
def IsNavigationDone(time_left):
self._inspector_backend.DispatchNotifications(time_left)
return not self._navigation_pending
util.WaitFor(IsNavigationDone, timeout, pass_time_left_to_func=True)
DisablePageNotifications()
self._navigation_pending = True
while self._navigation_pending and remaining_time > 0:
remaining_time = max(timeout - (time.time() - start_time), 0.0)
self._inspector_backend.DispatchNotifications(remaining_time)
finally:
self._DisablePageNotifications(remaining_time)
def Navigate(self, url, script_to_evaluate_on_commit=None, timeout=60):
"""Navigates to |url|.
......
......@@ -39,7 +39,7 @@ def AddDirToPythonPath(*path_parts):
sys.path.append(path)
def WaitFor(condition, timeout, pass_time_left_to_func=False):
def WaitFor(condition, timeout):
"""Waits for up to |timeout| secs for the function |condition| to return True.
Polling frequency is (elapsed_time / 10), with a min of .1s and max of 5s.
......@@ -50,11 +50,7 @@ def WaitFor(condition, timeout, pass_time_left_to_func=False):
start_time = time.time()
while True:
elapsed_time = time.time() - start_time
if pass_time_left_to_func:
remaining_time = timeout - elapsed_time
res = condition(max(remaining_time, 0.0))
else:
res = condition()
res = condition()
if res:
return res
if elapsed_time > timeout:
......
......@@ -38,7 +38,7 @@ class StringIOFile(StringIO.StringIO):
class HtmlPageMeasurementResultsTest(unittest.TestCase):
# TODO(tonyg): Remove this backfill when we can assume python 2.7 everywhere.
def assertIn(self, first, second, msg=None):
def assertIn(self, first, second, _=None):
self.assertTrue(first in second,
msg="'%s' not found in '%s'" % (first, second))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment