Chromium Code Reviews| Index: chrome/test/functional/devtools_instrumented_objects_check.py |
| diff --git a/chrome/test/functional/devtools_instrumented_objects_check.py b/chrome/test/functional/devtools_instrumented_objects_check.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..8b61015f02ef221514ca47e0c461cbde075b4fe2 |
| --- /dev/null |
| +++ b/chrome/test/functional/devtools_instrumented_objects_check.py |
| @@ -0,0 +1,76 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| +import os |
| +import tempfile |
| + |
| +import devtools_test_base |
| +import pyauto_functional # Must be imported before pyauto |
| +import pyauto |
| +import pyauto_utils |
| + |
| + |
| +class DevToolsInstrumentedObjectsCheck(devtools_test_base.DevToolsTestBase): |
| + """Test for checking that all instrumented objects are allocated by tcmalloc. |
| + |
| + This test navigates the browser to a test page, then takes native memory |
| + snapshot over remote debugging protocol and prints the number of objects |
| + that were counted by the DevTools memory instrumentation and how many of |
| + them have not been allocated by tcmalloc. Ideally the latter number should |
| + be 0. |
| + |
| + The test starts browser with HEAPPROFILE environment variable to enable |
| + tcmalloc heap profiler which is required by the memory instrumentation to |
| + check which of the instrumented objects have actually been allocated on the |
| + heap. |
| + |
| + The test uses Web Page Replay server as a proxy that allows to replay |
| + the same state of the test pages and avoid heavy network traffic on the |
| + real web sites. See webpagereplay.ReplayServer documentation to learn how |
| + to record new page archives. |
| + """ |
| + |
| + def setUp(self): |
| + # Make sure Chrome is started with tcmalloc heap profiler enabled. Dump |
| + # profiles into a temporary directory that will be destroyed when the test |
| + # completes. |
| + self._tempdir = tempfile.mkdtemp(prefix='devtools-test') |
| + os.environ['HEAPPROFILE'] = os.path.join(self._tempdir, 'heap-profile.') |
| + # We are not going to use dumped profile so set the interval big enough |
|
dennis_jeffrey
2012/10/04 01:16:33
add period at end of sentence
yurys
2012/10/04 15:07:47
Done.
|
| + os.environ['HEAP_PROFILE_TIME_INTERVAL'] = str(60 * 60) |
|
dennis_jeffrey
2012/10/04 01:16:33
is there a way to turn off the profile dump rather
yurys
2012/10/04 15:07:47
If the environment variable is omitted then the pr
|
| + super(DevToolsInstrumentedObjectsCheck, self).setUp() |
| + |
| + def tearDown(self): |
| + super(DevToolsInstrumentedObjectsCheck, self).tearDown() |
| + del os.environ['HEAPPROFILE'] |
| + del os.environ['HEAP_PROFILE_TIME_INTERVAL'] |
| + if self._tempdir: |
| + pyauto_utils.RemovePath(self._tempdir) |
| + |
| + def testNytimes(self): |
| + self.RunTestWithUrl('http://www.nytimes.com/') |
| + |
| + def testCnn(self): |
| + self.RunTestWithUrl('http://www.cnn.com/') |
| + |
| + def testGoogle(self): |
| + self.RunTestWithUrl('http://www.google.com/') |
| + |
| + def PrintTestResult(self, hostname, snapshot): |
| + total = snapshot.GetProcessPrivateMemorySize() |
| + counted_objects = snapshot.GetInstrumentedObjectsCount() |
| + counted_unknown_objects = snapshot.GetNumberOfInstrumentedObjectsNotInHeap() |
| + logging.info('Got data for: %s, objects count = %d (unknown = %d) ' % |
| + (hostname, counted_objects, counted_unknown_objects)) |
| + graph_name = 'DevTools Instrumented Objects - ' + hostname |
| + pyauto_utils.PrintPerfResult(graph_name, 'Reported instrumented objects', |
| + counted_objects, 'objects') |
| + pyauto_utils.PrintPerfResult(graph_name, 'Not allocated by tcmalloc', |
| + counted_unknown_objects, 'objects') |
| + |
| + |
| +if __name__ == '__main__': |
| + pyauto_functional.Main() |