summaryrefslogtreecommitdiffstats
path: root/tools/perf/metrics/startup_metric.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/metrics/startup_metric.py')
-rw-r--r--tools/perf/metrics/startup_metric.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/perf/metrics/startup_metric.py b/tools/perf/metrics/startup_metric.py
index 1ebdbc3..4c36508 100644
--- a/tools/perf/metrics/startup_metric.py
+++ b/tools/perf/metrics/startup_metric.py
@@ -1,9 +1,11 @@
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import collections
import json
from metrics import Metric
+from metrics import histogram_util
class StartupMetric(Metric):
@@ -21,6 +23,73 @@ class StartupMetric(Metric):
def Stop(self, page, tab):
raise NotImplementedError()
+ def _GetBrowserMainEntryTime(self, tab):
+ """Returns the main entry time (in ms) of the browser."""
+ histogram_type = histogram_util.BROWSER_HISTOGRAM
+ high_bytes = histogram_util.GetHistogramSum(
+ histogram_type,
+ 'Startup.BrowserMainEntryTimeAbsoluteHighWord',
+ tab)
+ low_bytes = histogram_util.GetHistogramSum(
+ histogram_type,
+ 'Startup.BrowserMainEntryTimeAbsoluteLowWord',
+ tab)
+ if high_bytes == 0 and low_bytes == 0:
+ return None
+ return (int(high_bytes) << 32) | (int(low_bytes) << 1)
+
+ # 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):
+ t = tab.browser.tabs[i]
+ t.WaitForDocumentReadyStateToBeComplete()
+ result = t.EvaluateJavaScript('statsCollectionController.tabLoadTiming()')
+ result = json.loads(result)
+
+ 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
+
+ is_foreground_tab = t.EvaluateJavaScript('!document.hidden')
+ tab_load_times.append(TabLoadTime(
+ int(result['load_start_ms']),
+ int(result['load_duration_ms']),
+ is_foreground_tab))
+
+ # 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]
+
+ # 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)
+
+ 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")'
@@ -38,3 +107,10 @@ class StartupMetric(Metric):
(result['buckets'][0]['high'] + result['buckets'][0]['low']) / 2
results.Add(display_name, 'ms', measured_time)
+
+ # Get tab load times.
+ browser_main_entry_time_ms = self._GetBrowserMainEntryTime(tab)
+ if (browser_main_entry_time_ms is None):
+ print "Outdated Chrome version, browser main entry time not supported."
+ return
+ self._RecordTabLoadTimes(tab, browser_main_entry_time_ms, results)