Mojo C++ bindings: better log message for serialization warnings.
[chromium-blink-merge.git] / tools / perf / measurements / session_restore.py
blob6c00e27a0c3a8681e05e0e52de4d2698677d39ab
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import collections
7 from measurements import startup
8 from metrics import cpu
9 from metrics import histogram_util
10 from metrics import startup_metric
11 from telemetry.core import util
14 class SessionRestore(startup.Startup):
15 """Performs a measurement of Chromium's Session restore performance.
17 This test is meant to be run against a generated profile.
18 This test inherits support for the --warm or --cold command line options -
19 see startup.py for details.
20 """
22 def __init__(self, action_name_to_run = ''):
23 super(SessionRestore, self).__init__(action_name_to_run=action_name_to_run)
24 self.close_tabs_before_run = False
25 self._cpu_metric = None
27 def CustomizeBrowserOptions(self, options):
28 super(SessionRestore, self).CustomizeBrowserOptions(options)
29 histogram_util.CustomizeBrowserOptions(options)
30 options.AppendExtraBrowserArgs([
31 '--restore-last-session'
34 def TabForPage(self, page, browser):
35 # Detect that the session restore has completed.
36 util.WaitFor(lambda: browser.tabs and
37 histogram_util.GetHistogramCount(
38 histogram_util.BROWSER_HISTOGRAM,
39 'SessionRestore.AllTabsLoaded',
40 browser.foreground_tab),
41 60)
42 return browser.foreground_tab
44 def CanRunForPage(self, page):
45 # No matter how many pages in the pageset, just perform one test iteration.
46 return page.page_set.pages.index(page) == 0
48 def RunNavigateSteps(self, page, tab):
49 # Overriden so that no page navigation occurs.
50 pass
52 def ValidatePageSet(self, page_set):
53 wpr_archive_names_to_page_urls = collections.defaultdict(list)
54 # Construct the map from pages' wpr archive names to pages' urls.
55 for page in page_set:
56 if page.is_local:
57 continue
58 wpr_archive_name = page_set.WprFilePathForPage(page)
59 wpr_archive_names_to_page_urls[wpr_archive_name].append(page.url)
61 # Reject any pageset that contains more than one WPR archive.
62 if len(wpr_archive_names_to_page_urls.keys()) > 1:
63 raise Exception("Invalid pageset: more than 1 WPR archive found.: " +
64 repr(wpr_archive_names_to_page_urls))
66 def DidStartBrowser(self, browser):
67 self._cpu_metric = cpu.CpuMetric(browser)
68 self._cpu_metric.Start(None, None)
70 def ValidateAndMeasurePage(self, page, tab, results):
71 tab.WaitForDocumentReadyStateToBeComplete()
73 # Record CPU usage from browser start to when the foreground page is loaded.
74 self._cpu_metric.Stop(None, None)
75 self._cpu_metric.AddResults(tab, results, 'cpu_utilization')
77 startup_metric.StartupMetric().AddResults(tab, results)
79 # TODO(jeremy): Measure time to load - first, last and frontmost tab here.