Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: tools/perf/page_sets/mobile_first_story.py

Issue 1510833002: [Telemetry] Googler Mobile First benchmark (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import logging
6
7 from telemetry.core import android_platform
8 from telemetry.core import platform as platform_module
9 from telemetry.internal.browser import browser_finder
10 from telemetry.internal.platform import android_device
11 from telemetry.page import action_runner
12 from telemetry import story as story_module
13 from telemetry.web_perf import timeline_based_measurement
14
15 # pylint: disable=import-error
nednguyen 2015/12/08 19:08:42 Can you update PRESUBMIT of tools/perf to include
perezju 2015/12/09 12:30:18 Done.
16 from devil.android.sdk import intent as intent_module
17 from devil.android.sdk import keyevent
18 from devil.utils import geometry
19 from devil.utils import timeout_retry
20
21
22 class SharedMobileFirstState(story_module.SharedState):
23 def __init__(self, test, finder_options, story_set):
24 super(SharedMobileFirstState, self).__init__(
25 test, finder_options, story_set)
26 self._test = test
27 self._story_set = story_set
28 self._android_platform = self._GetAndroidPlatform(finder_options)
29 self._gmail_app = self._CreateGmailApp()
30 self._browser = self._CreateBrowser(finder_options)
31 self._current_story = None
32 self._current_results = None
33 self._new_tab_ids = set()
34
35 def _GetAndroidPlatform(self, finder_options):
36 device = android_device.GetDevice(finder_options)
37 assert device, 'Benchmark requires an android device.'
38 platform = platform_module.GetPlatformForDevice(device, finder_options)
39 assert isinstance(platform, android_platform.AndroidPlatform)
40 return platform
41
42 def _CreateGmailApp(self):
43 return self.platform.LaunchAndroidApplication(
44 intent_module.Intent(
45 package='com.google.android.gm',
46 activity='com.google.android.gm.ui.MailActivityGmail'))
47
48 def _CreateBrowser(self, finder_options):
49 return browser_finder.FindBrowser(finder_options).Create(finder_options)
50
51 @property
52 def is_timeline_based(self):
53 return isinstance(
54 self._test, timeline_based_measurement.TimelineBasedMeasurement)
55
56 @property
57 def platform(self):
58 return self._android_platform
59
60 @property
61 def gmail_app(self):
62 return self._gmail_app
63
64 @property
65 def browser(self):
66 return self._browser
67
68 @property
69 def results(self):
70 return self._current_results
71
72 def WillRunStory(self, story):
73 self._current_story = story
74 if self.is_timeline_based:
75 self._test.WillRunStory(self.platform)
76
77 def CanRunStory(self, story):
78 return True # All stories must be run.
79
80 def RunStory(self, results):
81 self._current_results = results
82 self._current_story.Run(self)
83
84 def GetBrowserTab(self, new_tab=False):
85 if new_tab:
86 tab = self.browser.tabs.New()
87 else:
88 tab = self.browser.foreground_tab
89 self._new_tab_ids.add(tab.id)
90 return tab
91
92 def CloseOldTabs(self):
93 logging.info('Closing old tabs:')
94 for tab in self.browser.tabs:
95 if tab.id in self._new_tab_ids:
96 logging.info('- keeping [%s] %s', tab.id, tab.url)
97 else:
98 logging.info('- closing [%s] %s', tab.id, tab.url)
99 tab.Close()
100 self._new_tab_ids = set()
101
102 def DidRunStory(self, results):
103 if self.is_timeline_based:
104 self._test.DidRunStory(self.platform)
105 self._current_story = None
106 self._current_results = None
107
108 def TearDownState(self):
109 self._browser.Close()
110 self._gmail_app.Close()
111
112
113 class _MobileFirstStory(story_module.Story): # pylint: disable=abstract-method
114 DUMP_WAIT_TIME = 3
115 INTERACTION_LABEL = 'foreground'
116
117 def __init__(self, name, memory_infra=False):
118 super(_MobileFirstStory, self).__init__(SharedMobileFirstState, name=name)
119 self._memory_infra = memory_infra
120
121 def _TakeMemoryMeasurement(self, shared_state, tab):
122 runner = action_runner.ActionRunner(tab)
123 runner.tab.WaitForDocumentReadyStateToBeComplete()
124 runner.Wait(1) # See crbug.com/540022#c17.
125 with runner.CreateInteraction(self.INTERACTION_LABEL):
126 runner.Wait(self.DUMP_WAIT_TIME)
127 if shared_state.is_timeline_based and self._memory_infra:
128 runner.ForceGarbageCollection()
129 runner.tab.browser.platform.FlushEntireSystemCache()
130 runner.Wait(self.DUMP_WAIT_TIME)
131 if not runner.tab.browser.DumpMemory():
132 logging.error('Unable to get a memory dump for %s.', self.name)
133 # TODO(perezju): Use platform to also measure memory for Android apps
134 # with no access to memory-infra.
135
136 class ChromeAppStory(_MobileFirstStory):
137 def __init__(self, name, url, last_page=False):
138 super(ChromeAppStory, self).__init__(name=name, memory_infra=True)
139 self._url = url
140 self._last_page = last_page
141
142 def Run(self, shared_state):
143 navigate_on_new_tab = self._url is not None
144 tab = shared_state.GetBrowserTab(new_tab=navigate_on_new_tab)
145 if navigate_on_new_tab:
146 tab.Navigate(self._url)
147 self._TakeMemoryMeasurement(shared_state, tab)
148 if self._last_page:
149 shared_state.CloseOldTabs()
150
151
152 class GmailAppStory(_MobileFirstStory):
153 def __init__(self, name):
154 super(GmailAppStory, self).__init__(name=name)
155
156 def Run(self, shared_state):
157 # Go to the app switcher and tap on Gmail.
158 shared_state.platform.android_action_runner.InputKeyEvent(
159 keyevent.KEYCODE_APP_SWITCH)
160 shared_state.platform.system_ui.WaitForUiNode(
161 resource_id='activity_description', text='Gmail').Tap()
162
163 # If there is a "Back" button, tap on it to go to converation list view.
164 navigate_up = shared_state.gmail_app.ui.GetUiNode(
165 content_desc='Navigate up')
166 if navigate_up:
167 logging.info('Tapping on "Navigate up" button.')
168 navigate_up.Tap()
169
170 # Tap on the last email on the conversation list view.
171 logging.info('Tapping on last email in list view.')
172 shared_state.gmail_app.ui.WaitForUiNode(
173 resource_id='conversation_list_view')[-1].Tap()
174
175 # Wait for the email body to show, and take a memory measurement.
176 logging.info('Waiting for conversation_webview')
177 webview_view = shared_state.gmail_app.ui.WaitForUiNode(
178 resource_id='conversation_webview')
179 webview_content = self._GetSingleWebview(shared_state.gmail_app)
180 self._TakeMemoryMeasurement(shared_state, webview_content)
181
182 # Tap on the first link found on the email body, causes Chrome to launch.
183 link_bounds = geometry.Rectangle.FromDict(
184 webview_content.EvaluateJavaScript(
185 'document.links[0].getBoundingClientRect()'))
186 webview_view.Tap(link_bounds.center, dp_units=True)
187
188 def _GetSingleWebview(self, app):
189 def get_webviews():
190 return app.GetWebViews()
191
192 webviews = timeout_retry.WaitFor(get_webviews, wait_period=1, max_tries=5)
193 assert webviews, 'No webviews found.'
194
195 webview_content = webviews.pop()
196 logging.info('Will work with webview: %s', webview_content.id)
197 if len(webviews):
198 logging.warning('Ignoring (%d) other webviews found: %s.',
199 len(webviews), ', '.join(w.id for w in webviews))
200
201 return webview_content
202
203
204 class GooglerMobileFirstStorySet(story_module.StorySet):
205 """Mobile First Googler story set."""
206
207 def __init__(self):
208 super(GooglerMobileFirstStorySet, self).__init__(
209 archive_data_file='data/googler_mobile_first.json',
210 cloud_storage_bucket=story_module.PARTNER_BUCKET)
211 self.AddStory(GmailAppStory('gmail_read_email'))
212 self.AddStory(ChromeAppStory(
213 name='chromium_code_review',
214 url=None)) # Grabs url from email body.
215 self.AddStory(ChromeAppStory(
216 name='chromium_issue',
217 url='http://crbug.com/567696'))
218 self.AddStory(ChromeAppStory(
219 name='chromium_code_search',
220 url='https://code.google.com/p/chromium/codesearch'
221 '#chromium/src/tools/perf/benchmarks/memory_infra.py',
222 last_page=True))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698