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 | 5 import logging |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 from telemetry.page import page as page_module | 8 from telemetry.page import page as page_module |
| 9 from telemetry.page import shared_page_state | 9 from telemetry.page import shared_page_state |
| 10 from telemetry import story | 10 from telemetry import story |
| 11 | 11 |
| 12 from devil.android.sdk import intent # pylint: disable=import-error | 12 from devil.android.sdk import intent # pylint: disable=import-error |
| 13 from devil.android.sdk import keyevent # pylint: disable=import-error | 13 from devil.android.sdk import keyevent # pylint: disable=import-error |
| 14 | 14 |
| 15 from page_sets import top_10_mobile | |
| 16 | |
| 15 | 17 |
| 16 DUMP_WAIT_TIME = 3 | 18 DUMP_WAIT_TIME = 3 |
| 17 | 19 |
| 18 URL_LIST = [ | |
| 19 'http://google.com', | |
| 20 'http://vimeo.com', | |
| 21 'http://yahoo.com', | |
| 22 'http://baidu.com', | |
| 23 'http://cnn.com', | |
| 24 'http://yandex.ru', | |
| 25 'http://yahoo.co.jp', | |
| 26 'http://amazon.com', | |
| 27 'http://ebay.com', | |
| 28 'http://bing.com', | |
| 29 ] | |
| 30 | 20 |
| 31 | 21 class MemoryMeasuringPage(page_module.Page): |
|
petrcermak
2016/05/24 15:08:55
nit: I'd rename this to "MemoryMeasurementPage".
perezju
2016/05/24 15:33:48
Done.
| |
| 32 class MemoryHealthPage(page_module.Page): | 22 """Abstract class for measuring memory on a story unit.""" |
| 33 """Abstract page class for measuring memory.""" | |
| 34 | 23 |
| 35 _PHASE = NotImplemented | 24 _PHASE = NotImplemented |
| 36 | 25 |
| 37 def __init__(self, story_set, name, url): | 26 def __init__(self, story_set, name, url): |
| 38 super(MemoryHealthPage, self).__init__( | 27 super(MemoryMeasuringPage, self).__init__( |
| 39 page_set=story_set, name=name, url=url, | 28 page_set=story_set, name=name, url=url, |
| 40 shared_page_state_class=shared_page_state.SharedMobilePageState, | 29 shared_page_state_class=shared_page_state.SharedMobilePageState, |
| 41 grouping_keys={'phase': self._PHASE}) | 30 grouping_keys={'phase': self._PHASE}) |
| 42 | 31 |
| 43 def _TakeMemoryMeasurement(self, action_runner): | 32 def _TakeMemoryMeasurement(self, action_runner): |
| 33 platform = action_runner.tab.browser.platform | |
| 44 action_runner.Wait(1) # See crbug.com/540022#c17. | 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. | |
| 45 with action_runner.CreateInteraction(self._PHASE): | 38 with action_runner.CreateInteraction(self._PHASE): |
| 46 action_runner.Wait(DUMP_WAIT_TIME) | 39 action_runner.Wait(DUMP_WAIT_TIME) |
| 47 action_runner.ForceGarbageCollection() | 40 action_runner.ForceGarbageCollection() |
| 48 action_runner.tab.browser.platform.FlushEntireSystemCache() | 41 platform.FlushEntireSystemCache() |
| 49 action_runner.Wait(DUMP_WAIT_TIME) | 42 action_runner.Wait(DUMP_WAIT_TIME) |
| 50 if not action_runner.tab.browser.DumpMemory(): | 43 if not action_runner.tab.browser.DumpMemory(): |
| 51 logging.error('Unable to get a memory dump for %s.', self.name) | 44 logging.error('Unable to get a memory dump for %s.', self.name) |
| 52 | 45 |
| 53 | 46 |
| 54 class ForegroundPage(MemoryHealthPage): | 47 class ForegroundPage(MemoryMeasuringPage): |
| 55 """Take a measurement after loading a regular webpage.""" | 48 """Take a measurement after loading a regular webpage.""" |
| 56 | 49 |
| 57 _PHASE = 'foreground' | 50 _PHASE = 'foreground' |
| 58 | 51 |
| 59 def __init__(self, story_set, name, url): | 52 def __init__(self, story_set, name, url): |
| 60 super(ForegroundPage, self).__init__(story_set, name, url) | 53 super(ForegroundPage, self).__init__(story_set, name, url) |
| 61 | 54 |
| 62 def RunPageInteractions(self, action_runner): | 55 def RunPageInteractions(self, action_runner): |
| 63 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 56 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 64 self._TakeMemoryMeasurement(action_runner) | 57 self._TakeMemoryMeasurement(action_runner) |
| 65 | 58 |
| 66 | 59 |
| 67 class BackgroundPage(MemoryHealthPage): | 60 class BackgroundPage(MemoryMeasuringPage): |
| 68 """Take a measurement while Chrome is in the background.""" | 61 """Take a measurement while Chrome is in the background.""" |
| 69 | 62 |
| 70 _PHASE = 'background' | 63 _PHASE = 'background' |
| 71 | 64 |
| 72 def __init__(self, story_set, name): | 65 def __init__(self, story_set, name): |
| 73 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') | 66 super(BackgroundPage, self).__init__(story_set, name, 'about:blank') |
| 74 | 67 |
| 75 def RunPageInteractions(self, action_runner): | 68 def RunPageInteractions(self, action_runner): |
| 76 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 69 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 77 | 70 |
| 78 # Launch clock app, pushing Chrome to the background. | 71 # Launch clock app, pushing Chrome to the background. |
| 79 android_platform = action_runner.tab.browser.platform | 72 android_platform = action_runner.tab.browser.platform |
| 80 android_platform.LaunchAndroidApplication( | 73 android_platform.LaunchAndroidApplication( |
| 81 intent.Intent(package='com.google.android.deskclock', | 74 intent.Intent(package='com.google.android.deskclock', |
| 82 activity='com.android.deskclock.DeskClock'), | 75 activity='com.android.deskclock.DeskClock'), |
| 83 app_has_webviews=False) | 76 app_has_webviews=False) |
| 84 | 77 |
| 85 # Take measurement. | 78 # Take measurement. |
| 86 self._TakeMemoryMeasurement(action_runner) | 79 self._TakeMemoryMeasurement(action_runner) |
| 87 | 80 |
| 88 # Go back to Chrome. | 81 # Go back to Chrome. |
| 89 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) | 82 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) |
| 90 | 83 |
| 91 | 84 |
| 92 class MemoryHealthStory(story.StorySet): | 85 class MemoryTop10Mobile(story.StorySet): |
| 93 """User story for the Memory Health Plan.""" | 86 """User story to measure foreground/background memory in top 10 mobile.""" |
| 94 | 87 |
| 95 def __init__(self): | 88 def __init__(self): |
| 96 super(MemoryHealthStory, self).__init__( | 89 super(MemoryTop10Mobile, self).__init__( |
| 97 archive_data_file='data/memory_health_plan.json', | 90 archive_data_file='data/memory_top_10_mobile.json', |
| 98 cloud_storage_bucket=story.PARTNER_BUCKET) | 91 cloud_storage_bucket=story.PARTNER_BUCKET) |
| 99 | 92 |
| 100 for url in URL_LIST: | 93 for url in top_10_mobile.URL_LIST: |
| 101 # We name pages so their foreground/background counterparts are easy | 94 # We name pages so their foreground/background counterparts are easy |
| 102 # to identify. For example 'http://google.com' becomes | 95 # to identify. For example 'http://google.com' becomes |
| 103 # 'http_google_com' and 'after_http_google_com' respectively. | 96 # 'http_google_com' and 'after_http_google_com' respectively. |
| 104 name = re.sub('\W+', '_', url) | 97 name = re.sub('\W+', '_', url) |
| 105 self.AddStory(ForegroundPage(self, name, url)) | 98 self.AddStory(ForegroundPage(self, name, url)) |
| 106 self.AddStory(BackgroundPage(self, 'after_' + name)) | 99 self.AddStory(BackgroundPage(self, 'after_' + name)) |
| OLD | NEW |