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.
8 from telemetry
import benchmark
10 from measurements
import session_restore
12 from profile_creators
import profile_generator
13 from profile_creators
import small_profile_creator
16 class _SessionRestoreTypical25(benchmark
.Benchmark
):
17 """Base Benchmark class for session restore benchmarks.
19 A cold start means none of the Chromium files are in the disk cache.
20 A warm start assumes the OS has already cached much of Chromium's content.
21 For warm tests, you should repeat the page set to ensure it's cached.
23 Use Typical25PageSet to match what the SmallProfileCreator uses.
24 TODO(slamm): Make SmallProfileCreator and this use the same page_set ref.
26 page_set
= page_sets
.Typical25PageSet
27 tag
= None # override with 'warm' or 'cold'
31 return 'session_restore'
34 def ProcessCommandLineArgs(cls
, parser
, args
):
35 super(_SessionRestoreTypical25
, cls
).ProcessCommandLineArgs(parser
, args
)
36 profile_type
= 'small_profile'
37 if not args
.browser_options
.profile_dir
:
38 output_dir
= os
.path
.join(tempfile
.gettempdir(), profile_type
)
39 profile_dir
= os
.path
.join(output_dir
, profile_type
)
40 if not os
.path
.exists(output_dir
):
41 os
.makedirs(output_dir
)
43 # Generate new profiles if profile_dir does not exist. It only exists if
44 # all profiles had been correctly generated in a previous run.
45 if not os
.path
.exists(profile_dir
):
46 new_args
= args
.Copy()
47 new_args
.pageset_repeat
= 1
48 new_args
.output_dir
= output_dir
49 profile_generator
.GenerateProfiles(
50 small_profile_creator
.SmallProfileCreator
, profile_type
, new_args
)
51 args
.browser_options
.profile_dir
= profile_dir
54 def ValueCanBeAddedPredicate(cls
, _
, is_first_result
):
55 return cls
.tag
== 'cold' or not is_first_result
57 def CreateUserStorySet(self
, _
):
58 """Return a user story set that only has the first user story.
60 The session restore measurement skips the navigation step and
61 only tests session restore by having the browser start-up.
62 The first user story is used to get WPR set up and hold results.
64 user_story_set
= self
.page_set()
65 for user_story
in user_story_set
.user_stories
[1:]:
66 user_story_set
.RemoveUserStory(user_story
)
69 def CreatePageTest(self
, options
):
70 is_cold
= (self
.tag
== 'cold')
71 return session_restore
.SessionRestore(cold
=is_cold
)
73 def CreatePageSet(self
, options
):
74 return page_sets
.Typical25PageSet(run_no_page_interactions
=True)
76 # crbug.com/325479, crbug.com/381990
77 @benchmark.Disabled('android', 'linux', 'reference')
78 class SessionRestoreColdTypical25(_SessionRestoreTypical25
):
79 """Test by clearing system cache and profile before repeats."""
81 options
= {'pageset_repeat': 5}
85 return 'session_restore.cold.typical_25'
88 # crbug.com/325479, crbug.com/381990
89 @benchmark.Disabled('android', 'linux', 'reference', 'xp')
90 class SessionRestoreWarmTypical25(_SessionRestoreTypical25
):
91 """Test without clearing system cache or profile before repeats.
93 The first result is discarded.
96 options
= {'pageset_repeat': 20}
100 return 'session_restore.warm.typical_25'