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.
7 from measurements
import startup
8 from metrics
import cpu
9 from metrics
import startup_metric
10 from telemetry
.core
import util
11 from telemetry
.value
import histogram_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 'cold' option -
19 see startup.py for details.
22 def __init__(self
, cold
=False, action_name_to_run
= ''):
23 super(SessionRestore
, self
).__init
__(cold
=cold
,
24 action_name_to_run
=action_name_to_run
)
25 self
.close_tabs_before_run
= False
26 self
._cpu
_metric
= None
28 def CustomizeBrowserOptions(self
, options
):
29 super(SessionRestore
, self
).CustomizeBrowserOptions(options
)
30 histogram_util
.CustomizeBrowserOptions(options
)
31 options
.AppendExtraBrowserArgs([
32 '--restore-last-session'
35 def TabForPage(self
, page
, browser
):
36 # Detect that the session restore has completed.
37 util
.WaitFor(lambda: browser
.tabs
and
38 histogram_util
.GetHistogramCount(
39 histogram_util
.BROWSER_HISTOGRAM
,
40 'SessionRestore.AllTabsLoaded',
41 browser
.foreground_tab
),
43 return browser
.foreground_tab
45 def CanRunForPage(self
, page
):
46 # No matter how many pages in the pageset, just perform one test iteration.
47 return page
.page_set
.pages
.index(page
) == 0
49 def RunNavigateSteps(self
, page
, tab
):
50 # Overriden so that no page navigation occurs.
53 def ValidatePageSet(self
, page_set
):
54 wpr_archive_names_to_page_urls
= collections
.defaultdict(list)
55 # Construct the map from pages' wpr archive names to pages' urls.
59 wpr_archive_name
= page_set
.WprFilePathForPage(page
)
60 wpr_archive_names_to_page_urls
[wpr_archive_name
].append(page
.url
)
62 # Reject any pageset that contains more than one WPR archive.
63 if len(wpr_archive_names_to_page_urls
.keys()) > 1:
64 raise Exception("Invalid pageset: more than 1 WPR archive found.: " +
65 repr(wpr_archive_names_to_page_urls
))
67 def DidStartBrowser(self
, browser
):
68 self
._cpu
_metric
= cpu
.CpuMetric(browser
)
69 self
._cpu
_metric
.Start(None, None)
71 def ValidateAndMeasurePage(self
, page
, tab
, results
):
72 tab
.WaitForDocumentReadyStateToBeComplete()
74 # Record CPU usage from browser start to when the foreground page is loaded.
75 self
._cpu
_metric
.Stop(None, None)
76 self
._cpu
_metric
.AddResults(tab
, results
, 'cpu_utilization')
78 startup_metric
.StartupMetric().AddResults(tab
, results
)
80 # TODO(jeremy): Measure time to load - first, last and frontmost tab here.