Index: tools/perf/metrics/startup_metric.py |
diff --git a/tools/perf/metrics/startup_metric.py b/tools/perf/metrics/startup_metric.py |
index d0d400c4ce57cc61371d83e1dfc6d2374928a615..ccd39c1e4430ac1beb13fa133ad80cc8476a5c77 100644 |
--- a/tools/perf/metrics/startup_metric.py |
+++ b/tools/perf/metrics/startup_metric.py |
@@ -41,17 +41,16 @@ class StartupMetric(Metric): |
return None |
return (int(high_bytes) << 32) | (int(low_bytes) << 1) |
- # pylint: disable=W0101 |
+# pylint: disable=W0101 |
def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): |
"""Records the tab load times for the browser. """ |
tab_load_times = [] |
TabLoadTime = collections.namedtuple( |
'TabLoadTime', |
['load_start_ms', 'load_duration_ms', 'is_foreground_tab']) |
- num_open_tabs = len(tab.browser.tabs) |
- for i in xrange(num_open_tabs): |
+ |
+ def RecordTabLoadTime(t): |
try: |
- t = tab.browser.tabs[i] |
t.WaitForDocumentReadyStateToBeComplete() |
result = t.EvaluateJavaScript( |
@@ -61,11 +60,10 @@ class StartupMetric(Metric): |
if 'load_start_ms' not in result or 'load_duration_ms' not in result: |
raise Exception("Outdated Chrome version, " |
"statsCollectionController.tabLoadTiming() not present") |
- return |
if result['load_duration_ms'] is None: |
tab_title = t.EvaluateJavaScript('document.title') |
print "Page: ", tab_title, " didn't finish loading." |
- continue |
+ return |
is_foreground_tab = t.EvaluateJavaScript('!document.hidden') |
tab_load_times.append(TabLoadTime( |
@@ -76,35 +74,46 @@ class StartupMetric(Metric): |
# 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 |
# access a background tab. Ignore these tabs. |
- logging.error("Tab number: %d timed out on JavaScript access" % i) |
- continue |
- |
- # Postprocess results |
- load_complete_times = ( |
- [t.load_start_ms + t.load_duration_ms for t in tab_load_times]) |
- load_complete_times.sort() |
+ logging.error("Tab number: %d timed out on JavaScript access" % 0) |
if 'android' in tab.browser.browser_type: |
- # document.hidden is broken on Android - crbug.com/322544. |
- foreground_tab_stats = [tab_load_times[0]] |
+ # On android the background tabs are loaded on demand, so wont have been |
+ # loaded at this stage; only record the foreground tab. Also |
+ # document.hidden is broken on Android - crbug.com/322544 so assume this |
+ # is tab[0] |
jeremy
2014/02/13 09:40:15
Can you stick in a comment explaining in detail th
|
+ RecordTabLoadTime(tab.browser.tabs[0]) |
+ |
+ foreground_tab_stats = tab_load_times[0] |
+ foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
+ foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
+ results.Add( |
+ 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) |
else: |
+ num_open_tabs = len(tab.browser.tabs) |
+ for i in xrange(num_open_tabs): |
+ RecordTabLoadTime(tab.browser.tabs[i]) |
+ # Postprocess results |
+ load_complete_times = ( |
+ [t.load_start_ms + t.load_duration_ms for t in tab_load_times]) |
+ load_complete_times.sort() |
+ |
foreground_tab_stats = ( |
[t for t in tab_load_times if t.is_foreground_tab == True]) |
- if (len(foreground_tab_stats) != 1): |
- raise Exception ("More than one foreground tab? ", foreground_tab_stats) |
- foreground_tab_stats = foreground_tab_stats[0] |
+ if (len(foreground_tab_stats) != 1): |
+ raise Exception ("More than one foreground tab? ", foreground_tab_stats) |
+ foreground_tab_stats = foreground_tab_stats[0] |
- # Report load stats. |
- foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
- foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
+ # Report load stats. |
+ foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + |
+ foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) |
- results.Add( |
- 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) |
+ results.Add( |
+ 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) |
- if num_open_tabs > 1: |
- last_tab_load_complete = ( |
- load_complete_times[-1] - browser_main_entry_time_ms) |
- results.Add('last_tab_load_complete', 'ms', last_tab_load_complete) |
+ if num_open_tabs > 1: |
+ last_tab_load_complete = ( |
+ load_complete_times[-1] - browser_main_entry_time_ms) |
+ results.Add('last_tab_load_complete', 'ms', last_tab_load_complete) |
def AddResults(self, tab, results): |
get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' |