Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: tools/perf/page_sets/system_health/system_health_story.py

Issue 2228103002: [system-health] Add support for disabling individual stories on individual platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use possible_browser instead of browser Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from page_sets.system_health import platforms 5 from page_sets.system_health import platforms
6 6
7 from telemetry import decorators
7 from telemetry.page import page 8 from telemetry.page import page
9 from telemetry.page import shared_page_state
8 10
9 11
10 # Extra wait time after the page has loaded required by the loading metric. We 12 # Extra wait time after the page has loaded required by the loading metric. We
11 # use it in all benchmarks to avoid divergence between benchmarks. 13 # use it in all benchmarks to avoid divergence between benchmarks.
12 # TODO(petrcermak): Switch the memory benchmarks to use it as well. 14 # TODO(petrcermak): Switch the memory benchmarks to use it as well.
13 _WAIT_TIME_AFTER_LOAD = 10 15 _WAIT_TIME_AFTER_LOAD = 10
14 16
15 17
18 class _SystemHealthSharedState(shared_page_state.SharedPageState):
19 """Shared state which enables disabling stories on individual platforms.
20
21 This class adds support for enabling/disabling individual stories on
22 individual platforms using the same approaches as for benchmarks:
23
24 1. Disabled/Enabled decorator:
25
26 @decorators.Disabled('win')
27 class Story(system_health_story.SystemHealthStory):
28 ...
29
30 2. ShouldDisable method:
31
32 class Story(system_health_story.SystemHealthStory):
33 ...
34
35 @classmethod
36 def ShouldDisable(cls, possible_browser):
37 return possible_browser.platform.GetOSName() == 'win'
38 """
39
40 def CanRunStory(self, story):
41 return story.CanRun(self.possible_browser)
42
43
16 class _MetaSystemHealthStory(type): 44 class _MetaSystemHealthStory(type):
17 """Metaclass for SystemHealthStory.""" 45 """Metaclass for SystemHealthStory."""
18 46
19 @property 47 @property
20 def ABSTRACT_STORY(cls): 48 def ABSTRACT_STORY(cls):
21 """Class field marking whether the class is abstract. 49 """Class field marking whether the class is abstract.
22 50
23 If true, the story will NOT be instantiated and added to a System Health 51 If true, the story will NOT be instantiated and added to a System Health
24 story set. This field is NOT inherited by subclasses (that's why it's 52 story set. This field is NOT inherited by subclasses (that's why it's
25 defined on the metaclass). 53 defined on the metaclass).
26 """ 54 """
27 return cls.__dict__.get('ABSTRACT_STORY', False) 55 return cls.__dict__.get('ABSTRACT_STORY', False)
28 56
29 57
30 class SystemHealthStory(page.Page): 58 class SystemHealthStory(page.Page):
31 """Abstract base class for System Health user stories.""" 59 """Abstract base class for System Health user stories."""
32 __metaclass__ = _MetaSystemHealthStory 60 __metaclass__ = _MetaSystemHealthStory
33 61
34 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g. 62 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g.
35 # 'load:search:google'). 63 # 'load:search:google').
36 NAME = NotImplemented 64 NAME = NotImplemented
37 URL = NotImplemented 65 URL = NotImplemented
38 ABSTRACT_STORY = True 66 ABSTRACT_STORY = True
39 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS 67 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS
40 68
41 def __init__(self, story_set, take_memory_measurement): 69 def __init__(self, story_set, take_memory_measurement):
42 case, group, _ = self.NAME.split(':') 70 case, group, _ = self.NAME.split(':')
43 super(SystemHealthStory, self).__init__( 71 super(SystemHealthStory, self).__init__(
44 page_set=story_set, name=self.NAME, url=self.URL, 72 shared_page_state_class=_SystemHealthSharedState, page_set=story_set,
73 name=self.NAME, url=self.URL,
45 credentials_path='../data/credentials.json', 74 credentials_path='../data/credentials.json',
46 grouping_keys={'case': case, 'group': group}) 75 grouping_keys={'case': case, 'group': group})
47 self._take_memory_measurement = take_memory_measurement 76 self._take_memory_measurement = take_memory_measurement
48 77
78 @classmethod
79 def CanRun(cls, possible_browser):
80 if (decorators.ShouldSkip(cls, possible_browser)[0] or
81 cls.ShouldDisable(possible_browser)):
82 return False
83 return True
84
85 @classmethod
86 def ShouldDisable(cls, possible_browser):
87 """Override this method to disable a story under specific conditions.
88
89 This method is modelled after telemetry.benchmark.Benchmark.ShouldDisable().
90 """
91 del possible_browser
92 return False
93
49 def _Measure(self, action_runner): 94 def _Measure(self, action_runner):
50 if self._take_memory_measurement: 95 if self._take_memory_measurement:
51 action_runner.MeasureMemory(deterministic_mode=True) 96 action_runner.MeasureMemory(deterministic_mode=True)
52 else: 97 else:
53 action_runner.Wait(_WAIT_TIME_AFTER_LOAD) 98 action_runner.Wait(_WAIT_TIME_AFTER_LOAD)
54 99
55 def _Login(self, action_runner): 100 def _Login(self, action_runner):
56 pass 101 pass
57 102
58 def _DidLoadDocument(self, action_runner): 103 def _DidLoadDocument(self, action_runner):
59 pass 104 pass
60 105
61 def RunNavigateSteps(self, action_runner): 106 def RunNavigateSteps(self, action_runner):
62 self._Login(action_runner) 107 self._Login(action_runner)
63 super(SystemHealthStory, self).RunNavigateSteps(action_runner) 108 super(SystemHealthStory, self).RunNavigateSteps(action_runner)
64 109
65 def RunPageInteractions(self, action_runner): 110 def RunPageInteractions(self, action_runner):
66 action_runner.tab.WaitForDocumentReadyStateToBeComplete() 111 action_runner.tab.WaitForDocumentReadyStateToBeComplete()
67 self._DidLoadDocument(action_runner) 112 self._DidLoadDocument(action_runner)
68 self._Measure(action_runner) 113 self._Measure(action_runner)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698