Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / perf / benchmarks / session_restore.py
blob82d865158df2af695f9038d25704a1cf1f28d053
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 os
6 import tempfile
8 from telemetry import benchmark
10 from measurements import session_restore
11 import page_sets
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.
25 """
26 page_set = page_sets.Typical25PageSet
27 tag = None # override with 'warm' or 'cold'
29 @classmethod
30 def Name(cls):
31 return 'session_restore'
33 @classmethod
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
53 @classmethod
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.
63 """
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)
67 return user_story_set
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."""
80 tag = 'cold'
81 options = {'pageset_repeat': 5}
83 @classmethod
84 def Name(cls):
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.
94 """
95 tag = 'warm'
96 options = {'pageset_repeat': 20}
98 @classmethod
99 def Name(cls):
100 return 'session_restore.warm.typical_25'