Commit ad8d3f3d authored by cylee's avatar cylee Committed by Commit bot

Re-subimission of https://codereview.chromium.org/1041213003/

1. Use window.performance.timing instead of statsCollectionController to get page loading time.
2. Fix waiting condition to avoid racing condition

BUG=472603,467964

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

Cr-Commit-Position: refs/heads/master@{#324118}
parent 9845b890
...@@ -15,6 +15,9 @@ from metrics import Metric ...@@ -15,6 +15,9 @@ from metrics import Metric
class StartupMetric(Metric): class StartupMetric(Metric):
"A metric for browser startup time." "A metric for browser startup time."
# Seconds to wait for page loading complete.
DEFAULT_LOADING_TIMEOUT = 90
HISTOGRAMS_TO_RECORD = { HISTOGRAMS_TO_RECORD = {
'messageloop_start_time' : 'messageloop_start_time' :
'Startup.BrowserMessageLoopStartTimeFromMainEntry', 'Startup.BrowserMessageLoopStartTimeFromMainEntry',
...@@ -46,36 +49,34 @@ class StartupMetric(Metric): ...@@ -46,36 +49,34 @@ class StartupMetric(Metric):
def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results):
"""Records the tab load times for the browser. """ """Records the tab load times for the browser. """
tab_load_times = []
TabLoadTime = collections.namedtuple( TabLoadTime = collections.namedtuple(
'TabLoadTime', 'TabLoadTime',
['load_start_ms', 'load_duration_ms', 'request_start_ms']) ['request_start_ms', 'load_end_ms'])
def RecordTabLoadTime(t): def RecordOneTab(t):
try: def EvaluateInt(exp):
t.WaitForDocumentReadyStateToBeComplete() val = t.EvaluateJavaScript(exp)
if not val:
logging.warn('%s undefined' % exp)
return 0
return int(val)
result = t.EvaluateJavaScript( try:
'statsCollectionController.tabLoadTiming()') t.WaitForJavaScriptExpression(
result = json.loads(result) 'window.performance.timing["loadEventEnd"] > 0',
self.DEFAULT_LOADING_TIMEOUT)
if 'load_start_ms' not in result or 'load_duration_ms' not in result: # EvaluateJavaScript(window.performance.timing) doesn't guarantee to
raise Exception("Outdated Chrome version, " # return the desired javascript object (crbug/472603). It may return an
"statsCollectionController.tabLoadTiming() not present") # empty object. However getting individual field works.
if result['load_duration_ms'] is None: # The behavior depends on Webkit implementation on different platforms.
tab_title = t.EvaluateJavaScript('document.title') load_event_end = EvaluateInt(
print "Page: ", tab_title, " didn't finish loading." 'window.performance.timing["loadEventEnd"]')
return request_start = EvaluateInt(
'window.performance.timing["requestStart"]')
perf_timing = t.EvaluateJavaScript('window.performance.timing') return TabLoadTime(request_start, load_event_end)
if 'requestStart' not in perf_timing:
perf_timing['requestStart'] = 0 # Exclude from benchmark results
print 'requestStart is not supported by this browser'
tab_load_times.append(TabLoadTime(
int(result['load_start_ms']),
int(result['load_duration_ms']),
int(perf_timing['requestStart'])))
except exceptions.TimeoutException: except exceptions.TimeoutException:
# Low memory Android devices may not be able to load more than # Low memory Android devices may not be able to load more than
# one tab at a time, so may timeout when the test attempts to # one tab at a time, so may timeout when the test attempts to
...@@ -87,12 +88,11 @@ class StartupMetric(Metric): ...@@ -87,12 +88,11 @@ class StartupMetric(Metric):
# when the user switches to them, rather than during startup. In view of # when the user switches to them, rather than during startup. In view of
# this, to get the same measures on all platform, we only measure the # this, to get the same measures on all platform, we only measure the
# foreground tab on all platforms. # foreground tab on all platforms.
foreground_tab_stats = RecordOneTab(tab.browser.foreground_tab)
RecordTabLoadTime(tab.browser.foreground_tab) if foreground_tab_stats:
foreground_tab_load_complete = (
foreground_tab_stats = tab_load_times[0] foreground_tab_stats.load_end_ms - browser_main_entry_time_ms)
foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms +
foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms)
results.AddValue(scalar.ScalarValue( results.AddValue(scalar.ScalarValue(
results.current_page, 'foreground_tab_load_complete', 'ms', results.current_page, 'foreground_tab_load_complete', 'ms',
foreground_tab_load_complete)) foreground_tab_load_complete))
......
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