Index: chrome/test/pyautolib/pyauto.py |
diff --git a/chrome/test/pyautolib/pyauto.py b/chrome/test/pyautolib/pyauto.py |
index c06517e5ff721d844c5e17d4bd7966bfb56845d8..9dba93cf9b0a0e33cd8ec4bac4864e77fa52b8cb 100755 |
--- a/chrome/test/pyautolib/pyauto.py |
+++ b/chrome/test/pyautolib/pyauto.py |
@@ -3628,7 +3628,7 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
return self.ExecuteJavascript(js, tab_index, windex) |
def HeapProfilerDump(self, process_type, reason, tab_index=0, windex=0): |
- """Dumps a heap profile. It works only on Linux and ChromeOS. |
+ """Dumps a heap profile. It works only on Linux and ChromeOS. |
We need an environment variable "HEAPPROFILE" set to a directory and a |
filename prefix, for example, "/tmp/prof". In a case of this example, |
@@ -3636,6 +3636,8 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
"/tmp/prof.(pid).0003.heap", and so on. Nothing happens when this |
function is called without the env. |
+ Also, this requires the --enable-memory-benchmarking command line flag. |
+ |
Args: |
process_type: A string which is one of 'browser' or 'renderer'. |
reason: A string which describes the reason for dumping a heap profile. |
@@ -3653,14 +3655,18 @@ class PyUITest(pyautolib.PyUITestBase, unittest.TestCase): |
""" |
assert process_type in ('browser', 'renderer') |
if self.IsLinux(): # IsLinux() also implies IsChromeOS(). |
- cmd_dict = { |
- 'command': 'HeapProfilerDump', |
- 'process_type': process_type, |
- 'reason': reason, |
- 'windex': windex, |
- 'tab_index': tab_index, |
- } |
- self._GetResultFromJSONRequest(cmd_dict) |
+ js = """ |
+ if (!chrome.memoryBenchmarking || |
+ !chrome.memoryBenchmarking.isHeapProfilerRunning()) { |
+ domAutomationController.send('memory benchmarking disabled'); |
+ } else { |
+ chrome.memoryBenchmarking.heapProfilerDump("%s", "%s"); |
+ domAutomationController.send('success'); |
+ } |
+ """ % (process_type, reason.replace('"', '\\"')) |
+ result = self.ExecuteJavascript(js, tab_index, windex) |
+ if result != 'success': |
+ raise JSONInterfaceError('Heap profiler dump failed: ' + result) |
else: |
logging.warn('Heap-profiling is not supported in this OS.') |