Chromium Code Reviews| Index: tools/perf/page_sets/memory_test.py |
| diff --git a/tools/perf/page_sets/memory_test.py b/tools/perf/page_sets/memory_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3cfffa01c21cd04014394d302365a031ccd1d566 |
| --- /dev/null |
| +++ b/tools/perf/page_sets/memory_test.py |
| @@ -0,0 +1,366 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
|
bashi
2016/07/08 04:16:22
Are you going to add this?
tasak
2016/07/08 06:47:23
No. This code is just for explaining how I measure
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +import logging |
| +import os |
| + |
| +from page_sets.login_helpers import dropbox_login |
| +from page_sets.login_helpers import google_login |
| + |
| +from telemetry.page import page as page_module |
| +from telemetry.page import shared_page_state |
| +from telemetry import story |
| + |
| +DUMP_WAIT_TIME = 10 |
| +DUMP_COUNT = 10 |
| + |
| +class MemoryTestPage(page_module.Page): |
| + def __init__(self, story_set, group, url, page_spec): |
| + name = 'load:%s:%s' % (group, page_spec.name) |
| + super(MemoryTestPage, self).__init__( |
| + page_set=story_set, |
| + name=name, |
| + url=url, |
| + shared_page_state_class=shared_page_state.SharedPageState, |
| + credentials_path='data/credentials.json') |
| + self._page_spec = page_spec |
| + |
| + @property |
| + def platform(self): |
| + return self.story_set.PLATFORM |
| + |
| + def _dumpWithInteraction(self, action_runner, text, do_gc=False): |
| + with action_runner.CreateInteraction(text): |
| + action_runner.Wait(3) |
| + if do_gc: |
| + action_runner.ForceGarbageCollection() |
| + action_runner.SimulateMemoryPressureNotification('critical') |
| + action_runner.Wait(3) |
| + if not action_runner.tab.browser.DumpMemory(): |
| + logging.error('Unable to get a memory dump for %s.', self.name) |
| + |
| + def _RunPageInteractions(self, action_runner): |
| + action_runner.Wait(60) |
| + if not action_runner.tab.browser.DumpMemory(): |
| + logging.error('Unable to get a memory dump for %s.', self.name) |
| + |
| + def _RunPageAndMoveToBackground(self, action_runner): |
| + action_runner.Wait(60) |
| + # Force V8 GC. |
| + action_runner.ForceGarbageCollection() |
| + action_runner.Wait(10) |
| + # Dump before moving the page to background. |
| + if not action_runner.tab.browser.DumpMemory(): |
| + logging.error('Unable to get a memory dump for %s.', self.name) |
| + action_runner.Wait(3) |
| + # Open blank tab (Move the page to background). |
| + action_runner.tab.browser.tabs.New() |
| + # Wait until purge-and-suspend |
| + # Needs "--purge-and-suspend-time=X and X < 20" |
| + action_runner.Wait(120) |
| + if not action_runner.tab.browser.DumpMemory(): |
| + logging.error('Unable to get a memory dump for %s.', self.name) |
| + |
| + def _RunPageAndMoveToBackgroundWithNoDump(self, action_runner): |
| + action_runner.Wait(60) |
| + action_runner.ForceGarbageCollection() |
| + action_runner.Wait(10) |
| + action_runner.tab.browser.tabs.New() |
| + action_runner.Wait(540) |
| + |
| + |
| + def RunPageInteractions(self, action_runner): |
| + action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| + if self._page_spec.post_load_hook: |
| + self._page_spec.post_load_hook(self.platform, action_runner) |
| + self._RunPageAndMoveToBackground(action_runner) |
| + #self._RunPageAndMoveToBackgroundWithNoDump(action_runner) |
| + |
| + def RunNavigateSteps(self, action_runner): |
| + if self._page_spec.login_hook: |
| + self._page_spec.login_hook(action_runner, self.credentials_path) |
| + super(MemoryTestPage, self).RunNavigateSteps(action_runner) |
| + |
| + |
| +def _LogIntoGoogleAccount(action_runner, credentials_path): |
| + google_login.LoginGoogleAccount(action_runner, 'googletest', credentials_path) |
| + |
| + |
| +def _LogIntoGoogleAccountAndSetUpGmailSession(action_runner, credentials_path): |
| + _LogIntoGoogleAccount(action_runner, credentials_path) |
| + |
| + # Navigating to https://mail.google.com immediately leads to an infinite |
| + # redirection loop due to a bug in WPR (see |
| + # https://github.com/chromium/web-page-replay/issues/70). We therefore first |
| + # navigate to a sub-URL to set up the session and hit the resulting |
| + # redirection loop. Afterwards, we can safely navigate to |
| + # https://mail.google.com. |
| + action_runner.Navigate( |
| + 'https://mail.google.com/mail/mu/mp/872/trigger_redirection_loop') |
| + action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| + |
| + |
| +def _LogIntoDropboxAccount(action_runner, credentials_path): |
| + dropbox_login.LoginAccount(action_runner, 'dropbox', credentials_path) |
| + |
| + |
| +def _CloseInboxInterstitialAndWaitUntilGmailReady(platform, action_runner): |
| + if platform == 'desktop': |
| + # Wait until the UI loads. |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.getElementById("loading").style.display === "none"') |
| + elif platform == 'mobile': |
| + # Close the "Get Inbox by Gmail" interstitial. |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.querySelector("#isppromo a") !== null') |
| + action_runner.ExecuteJavaScript( |
| + 'document.querySelector("#isppromo a").click()') |
| + # Wait until the UI loads. |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.getElementById("apploadingdiv").style.height === "0px"') |
| + |
| + |
| +def _WaitUntilBubblesReady(_, action_runner): |
| + # The #logo element is removed right before the main menu is displayed. |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.getElementById("logo") === null') |
| + |
| + |
| +def _WaitUntilSpyChaseReady(_, action_runner): |
| + # The background of the game canvas is set when the "Tap screen to play" |
| + # caption is displayed. |
| + action_runner.WaitForJavaScriptCondition( |
| + 'document.querySelector("#game canvas").style.background !== ""') |
| + |
| + |
| +def _WaitUntilFlickrReady(_, action_runner): |
| + # Wait until the 'Recently tagged' view loads. |
| + action_runner.WaitForJavaScriptCondition(''' |
| + document.querySelector( |
| + '.search-photos-everyone-trending-view .photo-list-view') !== null''') |
| + |
| + |
| +class _PageSpec(object): |
| + |
| + def __init__(self, name, url, login_hook=None, post_load_hook=None): |
| + assert isinstance(url, (dict, str)) |
| + self._name = name |
| + self._url = url |
| + self._login_hook = login_hook |
| + self._post_load_hook = post_load_hook |
| + |
| + @property |
| + def name(self): |
| + return self._name |
| + |
| + @property |
| + def url(self): |
| + return self._url |
| + |
| + @property |
| + def login_hook(self): |
| + return self._login_hook |
| + |
| + @property |
| + def post_load_hook(self): |
| + return self._post_load_hook |
| + |
| + |
| +_SINGLE_PAGE_SPECS = { |
| + # Search and e-commerce. |
| + 'search': [ |
| + _PageSpec( |
| + name='google', |
| + url='https://www.google.com/#hl=en&q=science'), |
| + _PageSpec( |
| + name='baidu', |
| + url='https://www.baidu.com/s?word=google'), |
| + _PageSpec( |
| + name='yahoo', |
| + url='https://search.yahoo.com/search;_ylt=?p=google'), |
| + _PageSpec( |
| + name='amazon', |
| + url='https://www.amazon.com/s/?field-keywords=nexus'), |
| + # "ali_trackid" in the URL suppresses "Download app" interstitial. |
| + _PageSpec( |
| + name='taobao', |
| + url={'desktop': 'https://world.taobao.com/', |
| + 'mobile': 'http://m.intl.taobao.com/?ali_trackid'}), |
| + _PageSpec( |
| + name='yandex', |
| + url='https://yandex.ru/touchsearch?text=science'), |
| + # Redirects to the "http://" version. |
| + _PageSpec( |
| + name='ebay', |
| + url='https://www.ebay.com/sch/i.html?_nkw=headphones'), |
| + ], |
| + |
| + # Social networks. |
| + 'social': [ |
| + # Using Facebook login often causes "404 Not Found" with WPR. |
| + _PageSpec( |
| + name='facebook', |
| + url='https://www.facebook.com/rihanna'), |
| + _PageSpec( |
| + name='twitter', |
| + url='https://www.twitter.com/justinbieber?skip_interstitial=true'), |
| + # Due to the deterministic date injected by WPR (February 2008), the |
| + # cookie set by https://vk.com immediately expires, so the page keeps |
| + # refreshing indefinitely on mobile |
| + # (see https://github.com/chromium/web-page-replay/issues/71). |
| + _PageSpec( |
| + name='vk', |
| + url={'desktop': 'https://vk.com/sbeatles'}), |
| + _PageSpec( |
| + name='instagram', |
| + url='https://www.instagram.com/selenagomez/'), |
| + _PageSpec( |
| + name='pinterest', |
| + url='https://uk.pinterest.com/categories/popular/'), |
| + # Redirects to the "http://" version. |
| + _PageSpec( |
| + name='tumblr', |
| + url='https://50thousand.tumblr.com/'), |
| + ], |
| + |
| + # News, discussion and knowledge portals and blogs. |
| + 'news': [ |
| + # Redirects to the "http://" version. |
| + _PageSpec( |
| + name='bbc', |
| + url='https://www.bbc.co.uk/news/world-asia-china-36189636'), |
| + # Using "https://" shows "Your connection is not private". |
| + _PageSpec( |
| + name='cnn', |
| + url=( |
| + 'http://edition.cnn.com/2016/05/02/health/three-habitable-planets-earth-dwarf-star/index.html')), |
| + _PageSpec( |
| + name='reddit', |
| + url={'desktop': ( |
| + 'https://www.reddit.com/r/AskReddit/comments/4hi90e/whats_your_best_wedding_horror_story/'), |
| + 'mobile': ( |
| + 'https://m.reddit.com/r/AskReddit/comments/4hi90e/whats_your_best_wedding_horror_story/')}), |
| + # Using "https://" hangs and shows "This site can't be reached". |
| + _PageSpec( |
| + name='qq', |
| + url='http://news.qq.com/a/20160503/003186.htm'), |
| + # Using "https://" leads to missing images and scripts on mobile (due |
| + # to mixed content). The desktop page |
| + # (http://news.sohu.com/20160503/n447433356.shtml) almost always fails |
| + # to completely load due to |
| + # https://github.com/chromium/web-page-replay/issues/74. |
| + _PageSpec( |
| + name='sohu', |
| + url={'mobile': 'http://m.sohu.com/n/447433356/'}), |
| + _PageSpec( |
| + name='wikipedia', |
| + url='https://en.wikipedia.org/wiki/Science'), |
| + ], |
| + |
| + # Audio and video. |
| + 'media': [ |
| + # No way to disable autoplay on desktop. |
| + _PageSpec( |
| + name='youtube', |
| + url='https://www.youtube.com/watch?v=QGfhS1hfTWw&autoplay=false'), |
| + # The side panel with related videos doesn't show on desktop due to |
| + # https://github.com/chromium/web-page-replay/issues/74. |
| + _PageSpec( |
| + name='dailymotion', |
| + url=( |
| + 'https://www.dailymotion.com/video/x489k7d_street-performer-shows-off-slinky-skills_fun?autoplay=false')), |
| + _PageSpec( |
| + name='google_images', |
| + url='https://www.google.co.uk/search?tbm=isch&q=love'), |
| + # No way to disable autoplay on desktop. Album artwork doesn't load due |
| + # to https://github.com/chromium/web-page-replay/issues/73. |
| + _PageSpec( |
| + name='soundcloud', |
| + url='https://soundcloud.com/lifeofdesiigner/desiigner-panda'), |
| + _PageSpec( |
| + name='9gag', |
| + url='https://www.9gag.com/'), |
| + _PageSpec( |
| + name='flickr', |
| + url='https://www.flickr.com/photos/tags/farm', |
| + post_load_hook=_WaitUntilFlickrReady), |
| + ], |
| + |
| + # Online tools (documents, emails, storage, ...). |
| + 'tools': [ |
| + _PageSpec( |
| + name='docs', |
| + url=( |
| + 'https://docs.google.com/document/d/1GvzDP-tTLmJ0myRhUAfTYWs3ZUFilUICg8psNHyccwQ/edit?usp=sharing')), |
| + _PageSpec( |
| + name='gmail', |
| + url='https://mail.google.com/mail/', |
| + login_hook=_LogIntoGoogleAccountAndSetUpGmailSession, |
| + post_load_hook=_CloseInboxInterstitialAndWaitUntilGmailReady), |
| + _PageSpec( |
| + name='maps', |
| + url='https://www.google.com/maps/place/London,+UK/'), |
| + _PageSpec( |
| + name='stackoverflow', |
| + url=( |
| + 'https://stackoverflow.com/questions/36827659/compiling-an-application-for-use-in-highly-radioactive-environments')), |
| + _PageSpec( |
| + name='dropbox', |
| + url='https://www.dropbox.com', |
| + login_hook=_LogIntoDropboxAccount), |
| + _PageSpec( |
| + name='weather', |
| + url='https://weather.com/en-GB/weather/today/l/USCA0286:1:US'), |
| + _PageSpec( |
| + name='drive', |
| + url='https://drive.google.com/drive/my-drive', |
| + login_hook=_LogIntoGoogleAccount), |
| + ], |
| + |
| + # In-browser games (HTML5 and Flash). |
| + 'games': [ |
| + _PageSpec( |
| + name='bubbles', |
| + url=( |
| + 'https://games.cdn.famobi.com/html5games/s/smarty-bubbles/v010/?fg_domain=play.famobi.com&fg_uid=d8f24956-dc91-4902-9096-a46cb1353b6f&fg_pid=4638e320-4444-4514-81c4-d80a8c662371&fg_beat=620'), |
| + post_load_hook=_WaitUntilBubblesReady), |
| + # Using "https://" hangs and shows "This site can't be reached". |
| + _PageSpec( |
| + name='lazors', |
| + url='http://www8.games.mobi/games/html5/lazors/lazors.html'), |
| + # Using "https://" shows "Your connection is not private". |
| + _PageSpec( |
| + name='spychase', |
| + url='http://playstar.mobi/games/spychase/index.php', |
| + post_load_hook=_WaitUntilSpyChaseReady), |
| + # Desktop only (requires Flash). Using "https://" causes |
| + # "404 Not Found" during WPR recording. |
| + _PageSpec( |
| + name='miniclip', |
| + url={'desktop': 'http://www.miniclip.com/games/en/'}), |
| + # Desktop only (requires Flash). |
| + _PageSpec( |
| + name='alphabetty', |
| + url={'desktop': 'https://king.com/play/alphabetty'}), |
| + ], |
| +} |
| + |
| +class MemoryTestPageSet(story.StorySet): |
| + |
| + PLATFORM = NotImplemented |
| + |
| + def __init__(self): |
| + super(MemoryTestPageSet, self).__init__() |
| + |
| + param = os.getenv("MEMORY_TEST_PARAM") |
| + |
| + for group_name, page_specs in iter(_SINGLE_PAGE_SPECS.items()): |
| + if param is not None and group_name != param: |
| + continue |
| + for page_spec in page_specs: |
| + url = page_spec.url |
| + if isinstance(url, dict): |
| + url = url.get(self.PLATFORM) |
| + if url is None: |
| + continue # URL not supported on the platform. |
| + self.AddStory(MemoryTestPage(self, group_name, url, page_spec)) |