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