Chromium Code Reviews| 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 | 7 import os |
| 8 import tempfile | |
| 8 from urlparse import urlparse | 9 from urlparse import urlparse |
| 9 | 10 |
| 10 import pyauto_functional # Must be imported before pyauto | 11 import pyauto_functional # Must be imported before pyauto |
| 11 import pyauto | 12 import pyauto |
| 12 import pyauto_utils | 13 import pyauto_utils |
| 13 import remote_inspector_client | 14 import remote_inspector_client |
| 14 import webpagereplay | 15 import webpagereplay |
| 15 | 16 |
| 16 | 17 |
| 17 class DevToolsNativeMemorySnapshotTest(pyauto.PyUITest): | 18 class DevToolsTestBase(pyauto.PyUITest): |
| 18 """Test for tracking unknown share in the DevTools native memory snapshots. | 19 """Base class for DevTools tests that use replay server |
|
dennis_jeffrey
2012/10/04 01:16:33
add period at end of sentence.
yurys
2012/10/04 15:07:47
Done.
| |
| 19 | 20 |
| 20 This test navigates the browser to a test page, then takes native memory | 21 This class allows to navigate the browser to a test page and take native |
| 21 snapshot over remote debugging protocol and prints render process private | 22 memory snapshot over remote debugging protocol. |
| 22 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 | |
| 24 instrumentation. | |
| 25 | 23 |
| 26 The test uses Web Page Replay server as a proxy that allows to replay | 24 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 | 25 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 | 26 real web sites. See webpagereplay.ReplayServer documentation to learn how |
| 29 to record new page archives. | 27 to record new page archives. |
| 30 """ | 28 """ |
| 31 | 29 |
| 32 # DevTools test pages live in src/data/devtools rather than | 30 # DevTools test pages live in src/data/devtools rather than |
| 33 # src/chrome/test/data | 31 # src/chrome/test/data |
| 34 DATA_PATH = os.path.abspath( | 32 DATA_PATH = os.path.abspath( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 51 # Set up a remote inspector client associated with tab 0. | 49 # Set up a remote inspector client associated with tab 0. |
| 52 logging.info('Setting up connection to remote inspector...') | 50 logging.info('Setting up connection to remote inspector...') |
| 53 self._remote_inspector_client = ( | 51 self._remote_inspector_client = ( |
| 54 remote_inspector_client.RemoteInspectorClient()) | 52 remote_inspector_client.RemoteInspectorClient()) |
| 55 logging.info('Connection to remote inspector set up successfully.') | 53 logging.info('Connection to remote inspector set up successfully.') |
| 56 | 54 |
| 57 def tearDown(self): | 55 def tearDown(self): |
| 58 logging.info('Terminating connection to remote inspector...') | 56 logging.info('Terminating connection to remote inspector...') |
| 59 self._remote_inspector_client.Stop() | 57 self._remote_inspector_client.Stop() |
| 60 logging.info('Connection to remote inspector terminated.') | 58 logging.info('Connection to remote inspector terminated.') |
| 61 super(DevToolsNativeMemorySnapshotTest, self).tearDown() | 59 super(DevToolsTestBase, self).tearDown() |
| 62 | 60 |
| 63 def testNytimes(self): | 61 def RunTestWithUrl(self, url): |
| 64 self._RunTestWithUrl('http://www.nytimes.com/') | 62 """Navigates browser to given URL and takes native memory snapshot.""" |
| 65 | |
| 66 def testCnn(self): | |
| 67 self._RunTestWithUrl('http://www.cnn.com/') | |
| 68 | |
| 69 def testGoogle(self): | |
| 70 self._RunTestWithUrl('http://www.google.com/') | |
| 71 | |
| 72 def _RunTestWithUrl(self, url): | |
| 73 """Dumps native memory snapshot data for given page.""" | |
| 74 replay_options = None | 63 replay_options = None |
| 75 hostname = urlparse(url).hostname | 64 hostname = urlparse(url).hostname |
| 76 archive_path = os.path.join(self.DATA_PATH, hostname + '.wpr') | 65 archive_path = os.path.join(self.DATA_PATH, hostname + '.wpr') |
| 77 with webpagereplay.ReplayServer(archive_path, replay_options): | 66 with webpagereplay.ReplayServer(archive_path, replay_options): |
| 78 self.NavigateToURL(url) | 67 self.NavigateToURL(url) |
| 79 snapshot = self._remote_inspector_client.GetProcessMemoryDistribution() | 68 snapshot = self._remote_inspector_client.GetProcessMemoryDistribution() |
| 80 total = snapshot.GetProcessPrivateMemorySize() | 69 logging.info('Got snapshot for url: %s' % url) |
| 81 unknown = snapshot.GetUnknownSize() | 70 self.PrintTestResult(hostname, snapshot) |
| 82 logging.info('Got data for url: %s, total size = %d, unknown size = %d '% | |
| 83 (url, total, unknown)) | |
| 84 | 71 |
| 85 graph_name = 'DevTools Native Snapshot - ' + hostname | 72 def PrintTestResult(self, hostname, snapshot): |
| 86 pyauto_utils.PrintPerfResult(graph_name, 'Total', total, 'bytes') | 73 pass |
|
dennis_jeffrey
2012/10/04 01:16:33
maybe add a comment that says this is expected to
yurys
2012/10/04 15:07:47
Done.
| |
| 87 pyauto_utils.PrintPerfResult(graph_name, 'Unknown', unknown, 'bytes') | |
| 88 | 74 |
| 89 | |
| 90 if __name__ == '__main__': | |
| 91 pyauto_functional.Main() | |
| OLD | NEW |