Chromium Code Reviews| 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 self._deterministic_mode = story_set.DETERMINISTIC_MODE |
|
petrcermak
2016/07/07 12:52:11
I don't think you need to store this at all. You s
perezju
2016/08/05 10:50:01
Done.
| |
| 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 | 28 |
| 46 | 29 |
| 47 class ForegroundPage(MemoryMeasurementPage): | 30 class ForegroundPage(MemoryMeasurementPage): |
| 48 """Take a measurement after loading a regular webpage.""" | 31 """Take a measurement after loading a regular webpage.""" |
| 49 | 32 |
| 50 _PHASE = 'foreground' | 33 _PHASE = 'foreground' |
| 51 | 34 |
| 52 def __init__(self, story_set, name, url): | 35 def __init__(self, story_set, name, url): |
| 53 super(ForegroundPage, self).__init__(story_set, name, url) | 36 super(ForegroundPage, self).__init__(story_set, name, url) |
| 54 | 37 |
| 55 def RunPageInteractions(self, action_runner): | 38 def RunPageInteractions(self, action_runner): |
| 56 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 39 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 57 self._TakeMemoryMeasurement(action_runner) | 40 action_runner.MeasureMemory(self._deterministic_mode) |
| 58 | 41 |
| 59 | 42 |
| 60 class BackgroundPage(MemoryMeasurementPage): | 43 class BackgroundPage(MemoryMeasurementPage): |
| 61 """Take a measurement while Chrome is in the background.""" | 44 """Take a measurement while Chrome is in the background.""" |
| 62 | 45 |
| 63 _PHASE = 'background' | 46 _PHASE = 'background' |
| 64 | 47 |
| 65 def __init__(self, story_set, name): | 48 def __init__(self, story_set, name): |
| 66 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') | 49 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') |
| 67 | 50 |
| 68 def RunPageInteractions(self, action_runner): | 51 def RunPageInteractions(self, action_runner): |
| 69 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 52 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 70 | 53 |
| 71 # Launch clock app, pushing Chrome to the background. | 54 # Launch clock app, pushing Chrome to the background. |
| 72 android_platform = action_runner.tab.browser.platform | 55 android_platform = action_runner.tab.browser.platform |
| 73 android_platform.LaunchAndroidApplication( | 56 android_platform.LaunchAndroidApplication( |
| 74 intent.Intent(package='com.google.android.deskclock', | 57 intent.Intent(package='com.google.android.deskclock', |
| 75 activity='com.android.deskclock.DeskClock'), | 58 activity='com.android.deskclock.DeskClock'), |
| 76 app_has_webviews=False) | 59 app_has_webviews=False) |
| 77 | 60 |
| 78 # Take measurement. | 61 # Take measurement. |
| 79 self._TakeMemoryMeasurement(action_runner) | 62 action_runner.MeasureMemory(self._deterministic_mode) |
| 80 | 63 |
| 81 # Go back to Chrome. | 64 # Go back to Chrome. |
| 82 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) | 65 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) |
| 83 | 66 |
| 84 | 67 |
| 85 class MemoryTop10Mobile(story.StorySet): | 68 class MemoryTop10Mobile(story.StorySet): |
| 86 """User story to measure foreground/background memory in top 10 mobile.""" | 69 """User story to measure foreground/background memory in top 10 mobile.""" |
| 70 DETERMINISTIC_MODE = True | |
| 87 | 71 |
| 88 def __init__(self): | 72 def __init__(self): |
| 89 super(MemoryTop10Mobile, self).__init__( | 73 super(MemoryTop10Mobile, self).__init__( |
| 90 archive_data_file='data/memory_top_10_mobile.json', | 74 archive_data_file='data/memory_top_10_mobile.json', |
| 91 cloud_storage_bucket=story.PARTNER_BUCKET) | 75 cloud_storage_bucket=story.PARTNER_BUCKET) |
| 92 | 76 |
| 93 for url in top_10_mobile.URL_LIST: | 77 for url in top_10_mobile.URL_LIST: |
| 94 # We name pages so their foreground/background counterparts are easy | 78 # We name pages so their foreground/background counterparts are easy |
| 95 # to identify. For example 'http://google.com' becomes | 79 # to identify. For example 'http://google.com' becomes |
| 96 # 'http_google_com' and 'after_http_google_com' respectively. | 80 # 'http_google_com' and 'after_http_google_com' respectively. |
| 97 name = re.sub('\W+', '_', url) | 81 name = re.sub('\W+', '_', url) |
| 98 self.AddStory(ForegroundPage(self, name, url)) | 82 self.AddStory(ForegroundPage(self, name, url)) |
| 99 self.AddStory(BackgroundPage(self, 'after_' + name)) | 83 self.AddStory(BackgroundPage(self, 'after_' + name)) |
| 84 | |
| 85 | |
| 86 class MemoryTop10MobileRealistic(MemoryTop10Mobile): | |
| 87 """Top 10 mobile user story in realistic mode. | |
| 88 | |
| 89 This means, in particular, no forced GCs nor clearing caches. | |
|
petrcermak
2016/07/07 12:52:11
nit: "NEITHER ... nor ..."
perezju
2016/08/05 10:50:01
Done.
| |
| 90 """ | |
| 91 DETERMINISTIC_MODE = False | |
| OLD | NEW |