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
='RunPageInteractions'):
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 RunNavigateSteps(self
, page
, tab
):
46 # Overridden so that no page navigation occurs.
49 def ValidatePageSet(self
, page_set
):
50 wpr_archive_names_to_page_urls
= collections
.defaultdict(list)
51 # Construct the map from pages' wpr archive names to pages' urls.
55 wpr_archive_name
= page_set
.WprFilePathForUserStory(page
)
56 wpr_archive_names_to_page_urls
[wpr_archive_name
].append(page
.url
)
58 # Reject any pageset that contains more than one WPR archive.
59 if len(wpr_archive_names_to_page_urls
.keys()) > 1:
60 raise Exception("Invalid pageset: more than 1 WPR archive found.: " +
61 repr(wpr_archive_names_to_page_urls
))
63 def DidStartBrowser(self
, browser
):
64 self
._cpu
_metric
= cpu
.CpuMetric(browser
)
65 self
._cpu
_metric
.Start(None, None)
67 def ValidateAndMeasurePage(self
, page
, tab
, results
):
68 tab
.WaitForDocumentReadyStateToBeComplete()
69 super(SessionRestore
, self
).ValidateAndMeasurePage(page
, tab
, results
)
71 # Record CPU usage from browser start to when the foreground page is loaded.
72 self
._cpu
_metric
.Stop(None, None)
73 self
._cpu
_metric
.AddResults(tab
, results
, 'cpu_utilization')
75 # TODO(jeremy): Measure time to load - first, last and frontmost tab here.