| OLD | NEW |
| 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 import logging | |
| 6 | |
| 7 from page_sets.system_health import platforms | 5 from page_sets.system_health import platforms |
| 8 | 6 |
| 9 from telemetry.page import page | 7 from telemetry.page import page |
| 10 | 8 |
| 11 | 9 |
| 12 _DUMP_WAIT_TIME = 3 | 10 # 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. |
| 12 # TODO(petrcermak): Switch the memory benchmarks to use it as well. |
| 13 _WAIT_TIME_AFTER_LOAD = 10 |
| 13 | 14 |
| 14 | 15 |
| 15 class _MetaSystemHealthStory(type): | 16 class _MetaSystemHealthStory(type): |
| 16 """Metaclass for SystemHealthStory.""" | 17 """Metaclass for SystemHealthStory.""" |
| 17 | 18 |
| 18 @property | 19 @property |
| 19 def ABSTRACT_STORY(cls): | 20 def ABSTRACT_STORY(cls): |
| 20 """Class field marking whether the class is abstract. | 21 """Class field marking whether the class is abstract. |
| 21 | 22 |
| 22 If true, the story will NOT be instantiated and added to a System Health | 23 If true, the story will NOT be instantiated and added to a System Health |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 def __init__(self, story_set, take_memory_measurement): | 41 def __init__(self, story_set, take_memory_measurement): |
| 41 case, group, _ = self.NAME.split(':') | 42 case, group, _ = self.NAME.split(':') |
| 42 super(SystemHealthStory, self).__init__( | 43 super(SystemHealthStory, self).__init__( |
| 43 page_set=story_set, name=self.NAME, url=self.URL, | 44 page_set=story_set, name=self.NAME, url=self.URL, |
| 44 credentials_path='../data/credentials.json', | 45 credentials_path='../data/credentials.json', |
| 45 grouping_keys={'case': case, 'group': group}) | 46 grouping_keys={'case': case, 'group': group}) |
| 46 self._take_memory_measurement = take_memory_measurement | 47 self._take_memory_measurement = take_memory_measurement |
| 47 | 48 |
| 48 def _Measure(self, action_runner): | 49 def _Measure(self, action_runner): |
| 50 if self._ShouldMeasureMemory(action_runner): |
| 51 action_runner.MeasureMemory(deterministic_mode=True) |
| 52 else: |
| 53 action_runner.Wait(_WAIT_TIME_AFTER_LOAD) |
| 54 |
| 55 def _ShouldMeasureMemory(self, action_runner): |
| 49 if not self._take_memory_measurement: | 56 if not self._take_memory_measurement: |
| 50 return | 57 return False |
| 51 # TODO(petrcermak): This method is essentially the same as | 58 # The check below is also performed in action_runner.MeasureMemory(). |
| 52 # MemoryHealthPage._TakeMemoryMeasurement() in memory_health_story.py. | 59 # However, we need to duplicate it here so that the story would wait for |
| 53 # Consider sharing the common code. | 60 # |_WAIT_TIME_AFTER_LOAD| seconds after load when recorded via the |
| 54 action_runner.Wait(_DUMP_WAIT_TIME) | 61 # system_health.memory_* benchmarks. |
| 55 action_runner.ForceGarbageCollection() | 62 # TODO(petrcermak): Make it possible (and mandatory) to record the story |
| 56 action_runner.Wait(_DUMP_WAIT_TIME) | 63 # directly through the story set and remove this check. |
| 57 tracing_controller = action_runner.tab.browser.platform.tracing_controller | 64 tracing_controller = action_runner.tab.browser.platform.tracing_controller |
| 58 if not tracing_controller.is_tracing_running: | 65 if not tracing_controller.is_tracing_running: |
| 59 return # Tracing is not running, e.g., when recording a WPR archive. | 66 return False # Tracing is not running, e.g. when recording a WPR archive. |
| 60 if not action_runner.tab.browser.DumpMemory(): | 67 return True |
| 61 logging.error('Unable to get a memory dump for %s.', self.name) | |
| 62 | 68 |
| 63 def _Login(self, action_runner): | 69 def _Login(self, action_runner): |
| 64 pass | 70 pass |
| 65 | 71 |
| 66 def _DidLoadDocument(self, action_runner): | 72 def _DidLoadDocument(self, action_runner): |
| 67 pass | 73 pass |
| 68 | 74 |
| 69 def RunNavigateSteps(self, action_runner): | 75 def RunNavigateSteps(self, action_runner): |
| 70 self._Login(action_runner) | 76 self._Login(action_runner) |
| 71 super(SystemHealthStory, self).RunNavigateSteps(action_runner) | 77 super(SystemHealthStory, self).RunNavigateSteps(action_runner) |
| 72 | 78 |
| 73 def RunPageInteractions(self, action_runner): | 79 def RunPageInteractions(self, action_runner): |
| 74 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 80 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 75 self._DidLoadDocument(action_runner) | 81 self._DidLoadDocument(action_runner) |
| 76 self._Measure(action_runner) | 82 self._Measure(action_runner) |
| OLD | NEW |