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

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

Powered by Google App Engine
This is Rietveld 408576698