blob: aef9de34d6244e6ea46b0c8e51fe437c95ee8f97 [file] [log] [blame]
Etienne Bergeronfcd03962017-06-12 19:01:301# 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.
4import logging
5import py_utils
6
7from telemetry.page import page as page_module
8from telemetry.page import shared_page_state
Juan A. Navarro Perez6879ad22017-08-12 07:29:089from telemetry import story as story_module
Etienne Bergeronfcd03962017-06-12 19:01:3010
11_DUMP_WAIT_TIME = 3
12_ITERATIONS = 10
13
Juan A. Navarro Perez6879ad22017-08-12 07:29:0814
15class 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 Bergeronfcd03962017-06-12 19:01:3021class 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 Perez6879ad22017-08-12 07:29:0826 shared_page_state_class=DesktopMemorySharedState,
ashleymarie335063f2017-06-13 18:50:3327 name=url)
Etienne Bergeronfcd03962017-06-12 19:01:3028
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 Perez6879ad22017-08-12 07:29:0855class DesktopMemoryPageSet(story_module.StorySet):
Etienne Bergeronfcd03962017-06-12 19:01:3056
57 """ Desktop sites with interesting memory characteristics """
58
59 def __init__(self):
ashleymariec3c82af2017-06-14 02:21:5460 super(DesktopMemoryPageSet, self).__init__()
Etienne Bergeronfcd03962017-06-12 19:01:3061
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))