Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 1 | # Copyright 2017 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 | import logging |
| 5 | import py_utils |
| 6 | |
| 7 | from telemetry.page import page as page_module |
| 8 | from telemetry.page import shared_page_state |
Juan A. Navarro Perez | 6879ad2 | 2017-08-12 07:29:08 | [diff] [blame] | 9 | from telemetry import story as story_module |
Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 10 | |
| 11 | _DUMP_WAIT_TIME = 3 |
| 12 | _ITERATIONS = 10 |
| 13 | |
Juan A. Navarro Perez | 6879ad2 | 2017-08-12 07:29:08 | [diff] [blame] | 14 | |
| 15 | class DesktopMemorySharedState(shared_page_state.SharedDesktopPageState): |
| 16 | def ShouldStopBrowserAfterStoryRun(self, story): |
| 17 | del story |
| 18 | return False # Keep the same browser instance open across stories. |
| 19 | |
| 20 | |
Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 21 | class DesktopMemoryPage(page_module.Page): |
| 22 | |
| 23 | def __init__(self, url, page_set): |
| 24 | super(DesktopMemoryPage, self).__init__( |
| 25 | url=url, page_set=page_set, |
Juan A. Navarro Perez | 6879ad2 | 2017-08-12 07:29:08 | [diff] [blame] | 26 | shared_page_state_class=DesktopMemorySharedState, |
ashleymarie | 335063f | 2017-06-13 18:50:33 | [diff] [blame] | 27 | name=url) |
Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 28 | |
| 29 | def _DumpMemory(self, action_runner, phase): |
| 30 | with action_runner.CreateInteraction(phase): |
| 31 | action_runner.Wait(_DUMP_WAIT_TIME) |
| 32 | action_runner.ForceGarbageCollection() |
| 33 | action_runner.SimulateMemoryPressureNotification('critical') |
| 34 | action_runner.Wait(_DUMP_WAIT_TIME) |
| 35 | action_runner.tab.browser.DumpMemory() |
| 36 | |
| 37 | def RunPageInteractions(self, action_runner): |
| 38 | self._DumpMemory(action_runner, 'pre') |
| 39 | for _ in xrange(_ITERATIONS): |
| 40 | action_runner.ReloadPage() |
| 41 | |
| 42 | tabs = action_runner.tab.browser.tabs |
| 43 | for _ in xrange(_ITERATIONS): |
| 44 | new_tab = tabs.New() |
| 45 | new_tab.action_runner.Navigate(self._url) |
| 46 | try: |
| 47 | new_tab.action_runner.WaitForNetworkQuiescence() |
| 48 | except py_utils.TimeoutException: |
| 49 | logging.warning('WaitForNetworkQuiescence() timeout') |
| 50 | new_tab.Close() |
| 51 | |
| 52 | self._DumpMemory(action_runner, 'post') |
| 53 | |
| 54 | |
Juan A. Navarro Perez | 6879ad2 | 2017-08-12 07:29:08 | [diff] [blame] | 55 | class DesktopMemoryPageSet(story_module.StorySet): |
Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 56 | |
| 57 | """ Desktop sites with interesting memory characteristics """ |
| 58 | |
| 59 | def __init__(self): |
ashleymarie | c3c82af | 2017-06-14 02:21:54 | [diff] [blame] | 60 | super(DesktopMemoryPageSet, self).__init__() |
Etienne Bergeron | fcd0396 | 2017-06-12 19:01:30 | [diff] [blame] | 61 | |
| 62 | urls_list = [ |
| 63 | 'http://www.google.com', |
| 64 | "http://www.live.com", |
| 65 | "http://www.youtube.com", |
| 66 | "http://www.wikipedia.org", |
| 67 | "http://www.flickr.com/", |
| 68 | "http://www.cnn.com/", |
| 69 | "http://www.adobe.com/", |
| 70 | "http://www.aol.com/", |
| 71 | "http://www.cnet.com/", |
| 72 | "http://www.godaddy.com/", |
| 73 | "http://www.walmart.com/", |
| 74 | "http://www.skype.com/", |
| 75 | ] |
| 76 | |
| 77 | for url in urls_list: |
| 78 | self.AddStory(DesktopMemoryPage(url, self)) |