OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import logging |
| 7 import os |
| 8 import tempfile |
| 9 |
| 10 import devtools_test_base |
| 11 import pyauto_functional # Must be imported before pyauto |
| 12 import pyauto |
| 13 import pyauto_utils |
| 14 |
| 15 |
| 16 class DevToolsInstrumentedObjectsCheck(devtools_test_base.DevToolsTestBase): |
| 17 """Test for checking that all instrumented objects are allocated by tcmalloc. |
| 18 |
| 19 This test navigates the browser to a test page, then takes native memory |
| 20 snapshot over remote debugging protocol and prints the number of objects |
| 21 that were counted by the DevTools memory instrumentation and how many of |
| 22 them have not been allocated by tcmalloc. Ideally the latter number should |
| 23 be 0. |
| 24 |
| 25 The test starts browser with HEAPPROFILE environment variable to enable |
| 26 tcmalloc heap profiler which is required by the memory instrumentation to |
| 27 check which of the instrumented objects have actually been allocated on the |
| 28 heap. |
| 29 |
| 30 The test uses Web Page Replay server as a proxy that allows to replay |
| 31 the same state of the test pages and avoid heavy network traffic on the |
| 32 real web sites. See webpagereplay.ReplayServer documentation to learn how |
| 33 to record new page archives. |
| 34 """ |
| 35 |
| 36 def setUp(self): |
| 37 # Make sure Chrome is started with tcmalloc heap profiler enabled. Dump |
| 38 # profiles into a temporary directory that will be destroyed when the test |
| 39 # completes. |
| 40 self._tempdir = tempfile.mkdtemp(prefix='devtools-test') |
| 41 os.environ['HEAPPROFILE'] = os.path.join(self._tempdir, 'heap-profile.') |
| 42 super(DevToolsInstrumentedObjectsCheck, self).setUp() |
| 43 |
| 44 def tearDown(self): |
| 45 super(DevToolsInstrumentedObjectsCheck, self).tearDown() |
| 46 del os.environ['HEAPPROFILE'] |
| 47 if self._tempdir: |
| 48 pyauto_utils.RemovePath(self._tempdir) |
| 49 |
| 50 def testNytimes(self): |
| 51 self.RunTestWithUrl('http://www.nytimes.com/') |
| 52 |
| 53 def testCnn(self): |
| 54 self.RunTestWithUrl('http://www.cnn.com/') |
| 55 |
| 56 def testGoogle(self): |
| 57 self.RunTestWithUrl('http://www.google.com/') |
| 58 |
| 59 def PrintTestResult(self, hostname, snapshot): |
| 60 total = snapshot.GetProcessPrivateMemorySize() |
| 61 counted_objects = snapshot.GetInstrumentedObjectsCount() |
| 62 counted_unknown_objects = snapshot.GetNumberOfInstrumentedObjectsNotInHeap() |
| 63 if not counted_objects or not counted_unknown_objects: |
| 64 logging.info('No information about number of instrumented objects.') |
| 65 return |
| 66 logging.info('Got data for: %s, objects count = %d (unknown = %d) ' % |
| 67 (hostname, counted_objects, counted_unknown_objects)) |
| 68 graph_name = 'DevTools Instrumented Objects - ' + hostname |
| 69 pyauto_utils.PrintPerfResult(graph_name, 'Reported instrumented objects', |
| 70 counted_objects, 'objects') |
| 71 pyauto_utils.PrintPerfResult(graph_name, 'Not allocated by tcmalloc', |
| 72 counted_unknown_objects, 'objects') |
| 73 |
| 74 |
| 75 if __name__ == '__main__': |
| 76 pyauto_functional.Main() |
OLD | NEW |