| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 import re | 5 import re |
| 7 | 6 |
| 8 from telemetry.page import page as page_module | 7 from telemetry.page import page as page_module |
| 9 from telemetry.page import shared_page_state | 8 from telemetry.page import shared_page_state |
| 10 from telemetry import story | 9 from telemetry import story |
| 11 | 10 |
| 12 from devil.android.sdk import intent # pylint: disable=import-error | 11 from devil.android.sdk import intent # pylint: disable=import-error |
| 13 from devil.android.sdk import keyevent # pylint: disable=import-error | 12 from devil.android.sdk import keyevent # pylint: disable=import-error |
| 14 | 13 |
| 15 from page_sets import top_10_mobile | 14 from page_sets import top_10_mobile |
| 16 | 15 |
| 17 | 16 |
| 18 DUMP_WAIT_TIME = 3 | |
| 19 | |
| 20 | |
| 21 class MemoryMeasurementPage(page_module.Page): | 17 class MemoryMeasurementPage(page_module.Page): |
| 22 """Abstract class for measuring memory on a story unit.""" | 18 """Abstract class for measuring memory on a story unit.""" |
| 23 | 19 |
| 24 _PHASE = NotImplemented | 20 _PHASE = NotImplemented |
| 25 | 21 |
| 26 def __init__(self, story_set, name, url): | 22 def __init__(self, story_set, name, url): |
| 27 super(MemoryMeasurementPage, self).__init__( | 23 super(MemoryMeasurementPage, self).__init__( |
| 28 page_set=story_set, name=name, url=url, | 24 page_set=story_set, name=name, url=url, |
| 29 shared_page_state_class=shared_page_state.SharedMobilePageState, | 25 shared_page_state_class=shared_page_state.SharedMobilePageState, |
| 30 grouping_keys={'phase': self._PHASE}) | 26 grouping_keys={'phase': self._PHASE}) |
| 31 | 27 |
| 32 def _TakeMemoryMeasurement(self, action_runner): | |
| 33 platform = action_runner.tab.browser.platform | |
| 34 action_runner.Wait(1) # See crbug.com/540022#c17. | |
| 35 if not platform.tracing_controller.is_tracing_running: | |
| 36 logging.warning('Tracing is off. No memory dumps are being recorded.') | |
| 37 return # Tracing is not running, e.g., when recording a WPR archive. | |
| 38 with action_runner.CreateInteraction(self._PHASE): | |
| 39 action_runner.Wait(DUMP_WAIT_TIME) | |
| 40 action_runner.ForceGarbageCollection() | |
| 41 platform.FlushEntireSystemCache() | |
| 42 action_runner.Wait(DUMP_WAIT_TIME) | |
| 43 if not action_runner.tab.browser.DumpMemory(): | |
| 44 logging.error('Unable to get a memory dump for %s.', self.name) | |
| 45 | |
| 46 | 28 |
| 47 class ForegroundPage(MemoryMeasurementPage): | 29 class ForegroundPage(MemoryMeasurementPage): |
| 48 """Take a measurement after loading a regular webpage.""" | 30 """Take a measurement after loading a regular webpage.""" |
| 49 | 31 |
| 50 _PHASE = 'foreground' | 32 _PHASE = 'foreground' |
| 51 | 33 |
| 52 def __init__(self, story_set, name, url): | 34 def __init__(self, story_set, name, url): |
| 53 super(ForegroundPage, self).__init__(story_set, name, url) | 35 super(ForegroundPage, self).__init__(story_set, name, url) |
| 54 | 36 |
| 55 def RunPageInteractions(self, action_runner): | 37 def RunPageInteractions(self, action_runner): |
| 56 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 38 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 57 self._TakeMemoryMeasurement(action_runner) | 39 action_runner.MeasureMemory(self.story_set.DETERMINISTIC_MODE) |
| 58 | 40 |
| 59 | 41 |
| 60 class BackgroundPage(MemoryMeasurementPage): | 42 class BackgroundPage(MemoryMeasurementPage): |
| 61 """Take a measurement while Chrome is in the background.""" | 43 """Take a measurement while Chrome is in the background.""" |
| 62 | 44 |
| 63 _PHASE = 'background' | 45 _PHASE = 'background' |
| 64 | 46 |
| 65 def __init__(self, story_set, name): | 47 def __init__(self, story_set, name): |
| 66 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') | 48 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') |
| 67 | 49 |
| 68 def RunPageInteractions(self, action_runner): | 50 def RunPageInteractions(self, action_runner): |
| 69 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 51 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 70 | 52 |
| 71 # Launch clock app, pushing Chrome to the background. | 53 # Launch clock app, pushing Chrome to the background. |
| 72 android_platform = action_runner.tab.browser.platform | 54 android_platform = action_runner.tab.browser.platform |
| 73 android_platform.LaunchAndroidApplication( | 55 android_platform.LaunchAndroidApplication( |
| 74 intent.Intent(package='com.google.android.deskclock', | 56 intent.Intent(package='com.google.android.deskclock', |
| 75 activity='com.android.deskclock.DeskClock'), | 57 activity='com.android.deskclock.DeskClock'), |
| 76 app_has_webviews=False) | 58 app_has_webviews=False) |
| 77 | 59 |
| 78 # Take measurement. | 60 # Take measurement. |
| 79 self._TakeMemoryMeasurement(action_runner) | 61 action_runner.MeasureMemory(self.story_set.DETERMINISTIC_MODE) |
| 80 | 62 |
| 81 # Go back to Chrome. | 63 # Go back to Chrome. |
| 82 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) | 64 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) |
| 83 | 65 |
| 84 | 66 |
| 85 class MemoryTop10Mobile(story.StorySet): | 67 class MemoryTop10Mobile(story.StorySet): |
| 86 """User story to measure foreground/background memory in top 10 mobile.""" | 68 """User story to measure foreground/background memory in top 10 mobile.""" |
| 69 DETERMINISTIC_MODE = True |
| 87 | 70 |
| 88 def __init__(self): | 71 def __init__(self): |
| 89 super(MemoryTop10Mobile, self).__init__( | 72 super(MemoryTop10Mobile, self).__init__( |
| 90 archive_data_file='data/memory_top_10_mobile.json', | 73 archive_data_file='data/memory_top_10_mobile.json', |
| 91 cloud_storage_bucket=story.PARTNER_BUCKET) | 74 cloud_storage_bucket=story.PARTNER_BUCKET) |
| 92 | 75 |
| 93 for url in top_10_mobile.URL_LIST: | 76 for url in top_10_mobile.URL_LIST: |
| 94 # We name pages so their foreground/background counterparts are easy | 77 # We name pages so their foreground/background counterparts are easy |
| 95 # to identify. For example 'http://google.com' becomes | 78 # to identify. For example 'http://google.com' becomes |
| 96 # 'http_google_com' and 'after_http_google_com' respectively. | 79 # 'http_google_com' and 'after_http_google_com' respectively. |
| 97 name = re.sub('\W+', '_', url) | 80 name = re.sub('\W+', '_', url) |
| 98 self.AddStory(ForegroundPage(self, name, url)) | 81 self.AddStory(ForegroundPage(self, name, url)) |
| 99 self.AddStory(BackgroundPage(self, 'after_' + name)) | 82 self.AddStory(BackgroundPage(self, 'after_' + name)) |
| 83 |
| 84 |
| 85 class MemoryTop10MobileRealistic(MemoryTop10Mobile): |
| 86 """Top 10 mobile user story in realistic mode. |
| 87 |
| 88 This means, in particular, neither forced GCs nor clearing caches. |
| 89 """ |
| 90 DETERMINISTIC_MODE = False |
| OLD | NEW |