| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import logging | 6 import logging |
| 7 import os | |
| 8 from urlparse import urlparse | |
| 9 | 7 |
| 8 import devtools_test_base |
| 10 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
| 11 import pyauto | 10 import pyauto |
| 12 import pyauto_utils | 11 import pyauto_utils |
| 13 import remote_inspector_client | |
| 14 import webpagereplay | |
| 15 | 12 |
| 16 | 13 |
| 17 class DevToolsNativeMemorySnapshotTest(pyauto.PyUITest): | 14 class DevToolsNativeMemorySnapshotTest(devtools_test_base.DevToolsTestBase): |
| 18 """Test for tracking unknown share in the DevTools native memory snapshots. | 15 """Test for tracking unknown share in the DevTools native memory snapshots. |
| 19 | 16 |
| 20 This test navigates the browser to a test page, then takes native memory | 17 This test navigates the browser to a test page, then takes native memory |
| 21 snapshot over remote debugging protocol and prints render process private | 18 snapshot over remote debugging protocol and prints render process private |
| 22 memory size and unknown size extracted from the snapshot. It is used to | 19 memory size and unknown size extracted from the snapshot. It is used to |
| 23 track size of the memory that is not counted by DevTools memory | 20 track size of the memory that is not counted by DevTools memory |
| 24 instrumentation. | 21 instrumentation. |
| 25 | 22 |
| 26 The test uses Web Page Replay server as a proxy that allows to replay | 23 The test uses Web Page Replay server as a proxy that allows to replay |
| 27 the same state of the test pages and avoid heavy network traffic on the | 24 the same state of the test pages and avoid heavy network traffic on the |
| 28 real web sites. See webpagereplay.ReplayServer documentation to learn how | 25 real web sites. See webpagereplay.ReplayServer documentation to learn how |
| 29 to record new page archives. | 26 to record new page archives. |
| 30 """ | 27 """ |
| 31 | |
| 32 # DevTools test pages live in src/data/devtools rather than | |
| 33 # src/chrome/test/data | |
| 34 DATA_PATH = os.path.abspath( | |
| 35 os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, | |
| 36 'data', 'devtools_test_pages')) | |
| 37 | |
| 38 def ExtraChromeFlags(self): | |
| 39 """Ensures Chrome is launched with custom flags. | |
| 40 | |
| 41 Returns: | |
| 42 A list of extra flags to pass to Chrome when it is launched. | |
| 43 """ | |
| 44 # Ensure Chrome enables remote debugging on port 9222. This is required to | |
| 45 # interact with Chrome's remote inspector. | |
| 46 extra_flags = ['--remote-debugging-port=9222'] + webpagereplay.CHROME_FLAGS | |
| 47 return (pyauto.PyUITest.ExtraChromeFlags(self) + extra_flags) | |
| 48 | |
| 49 def setUp(self): | |
| 50 pyauto.PyUITest.setUp(self) | |
| 51 # Set up a remote inspector client associated with tab 0. | |
| 52 logging.info('Setting up connection to remote inspector...') | |
| 53 self._remote_inspector_client = ( | |
| 54 remote_inspector_client.RemoteInspectorClient()) | |
| 55 logging.info('Connection to remote inspector set up successfully.') | |
| 56 | |
| 57 def tearDown(self): | |
| 58 logging.info('Terminating connection to remote inspector...') | |
| 59 self._remote_inspector_client.Stop() | |
| 60 logging.info('Connection to remote inspector terminated.') | |
| 61 super(DevToolsNativeMemorySnapshotTest, self).tearDown() | |
| 62 | |
| 63 def testNytimes(self): | 28 def testNytimes(self): |
| 64 self._RunTestWithUrl('http://www.nytimes.com/') | 29 self.RunTestWithUrl('http://www.nytimes.com/') |
| 65 | 30 |
| 66 def testCnn(self): | 31 def testCnn(self): |
| 67 self._RunTestWithUrl('http://www.cnn.com/') | 32 self.RunTestWithUrl('http://www.cnn.com/') |
| 68 | 33 |
| 69 def testGoogle(self): | 34 def testGoogle(self): |
| 70 self._RunTestWithUrl('http://www.google.com/') | 35 self.RunTestWithUrl('http://www.google.com/') |
| 71 | 36 |
| 72 def _RunTestWithUrl(self, url): | 37 def PrintTestResult(self, hostname, snapshot): |
| 73 """Dumps native memory snapshot data for given page.""" | |
| 74 replay_options = None | |
| 75 hostname = urlparse(url).hostname | |
| 76 archive_path = os.path.join(self.DATA_PATH, hostname + '.wpr') | |
| 77 with webpagereplay.ReplayServer(archive_path, replay_options): | |
| 78 self.NavigateToURL(url) | |
| 79 snapshot = self._remote_inspector_client.GetProcessMemoryDistribution() | |
| 80 total = snapshot.GetProcessPrivateMemorySize() | 38 total = snapshot.GetProcessPrivateMemorySize() |
| 81 unknown = snapshot.GetUnknownSize() | 39 unknown = snapshot.GetUnknownSize() |
| 82 logging.info('Got data for url: %s, total size = %d, unknown size = %d '% | 40 logging.info('Got data for: %s, total size = %d, unknown size = %d' % |
| 83 (url, total, unknown)) | 41 (hostname, total, unknown)) |
| 84 | |
| 85 graph_name = 'DevTools Native Snapshot - ' + hostname | 42 graph_name = 'DevTools Native Snapshot - ' + hostname |
| 86 pyauto_utils.PrintPerfResult(graph_name, 'Total', total, 'bytes') | 43 pyauto_utils.PrintPerfResult(graph_name, 'Total', total, 'bytes') |
| 87 pyauto_utils.PrintPerfResult(graph_name, 'Unknown', unknown, 'bytes') | 44 pyauto_utils.PrintPerfResult(graph_name, 'Unknown', unknown, 'bytes') |
| 88 | 45 |
| 89 | 46 |
| 90 if __name__ == '__main__': | 47 if __name__ == '__main__': |
| 91 pyauto_functional.Main() | 48 pyauto_functional.Main() |
| OLD | NEW |