| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import sys | 8 import sys |
| 9 import time | 9 import time |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 def testExtensionProcessMemoryUsage(self): | 103 def testExtensionProcessMemoryUsage(self): |
| 104 """Test the memory usage of an extension process. | 104 """Test the memory usage of an extension process. |
| 105 | 105 |
| 106 This test periodically queries the system for the current memory usage | 106 This test periodically queries the system for the current memory usage |
| 107 of an extension process. The test will take measurements forever; you | 107 of an extension process. The test will take measurements forever; you |
| 108 must manually kill the test to terminate it. | 108 must manually kill the test to terminate it. |
| 109 """ | 109 """ |
| 110 if (self.LOG_TO_OUTPUT_FILE and | 110 if (self.LOG_TO_OUTPUT_FILE and |
| 111 os.path.exists(self.EXTENSION_PROCESS_OUTPUT_FILE)): | 111 os.path.exists(self.EXTENSION_PROCESS_OUTPUT_FILE)): |
| 112 os.remove(self.EXTENSION_PROCESS_OUTPUT_FILE) | 112 os.remove(self.EXTENSION_PROCESS_OUTPUT_FILE) |
| 113 self.InstallExtension(self.EXTENSION_LOCATION, False) | 113 self.InstallExtension(self.EXTENSION_LOCATION) |
| 114 # The PID is 0 until the extension has a chance to start up. | 114 # The PID is 0 until the extension has a chance to start up. |
| 115 self.WaitUntil( | 115 self.WaitUntil( |
| 116 lambda: self._GetPidOfExtensionProcessByName( | 116 lambda: self._GetPidOfExtensionProcessByName( |
| 117 self.EXTENSION_PROCESS_NAME) not in [0, None]) | 117 self.EXTENSION_PROCESS_NAME) not in [0, None]) |
| 118 self._LogMessage( | 118 self._LogMessage( |
| 119 self.EXTENSION_PROCESS_OUTPUT_FILE, | 119 self.EXTENSION_PROCESS_OUTPUT_FILE, |
| 120 'Memory usage for extension process with name: "%s"' % ( | 120 'Memory usage for extension process with name: "%s"' % ( |
| 121 self.EXTENSION_PROCESS_NAME)) | 121 self.EXTENSION_PROCESS_NAME)) |
| 122 | 122 |
| 123 # A user must manually kill this test to terminate the following loop. | 123 # A user must manually kill this test to terminate the following loop. |
| 124 while True: | 124 while True: |
| 125 pid = self._GetPidOfExtensionProcessByName(self.EXTENSION_PROCESS_NAME) | 125 pid = self._GetPidOfExtensionProcessByName(self.EXTENSION_PROCESS_NAME) |
| 126 usage = test_utils.GetMemoryUsageOfProcess(pid) | 126 usage = test_utils.GetMemoryUsageOfProcess(pid) |
| 127 current_time = time.asctime(time.localtime(time.time())) | 127 current_time = time.asctime(time.localtime(time.time())) |
| 128 self._LogMessage( | 128 self._LogMessage( |
| 129 self.EXTENSION_PROCESS_OUTPUT_FILE, | 129 self.EXTENSION_PROCESS_OUTPUT_FILE, |
| 130 self.MEASUREMENT_LOG_MESSAGE_TEMPLATE % (current_time, usage, pid)) | 130 self.MEASUREMENT_LOG_MESSAGE_TEMPLATE % (current_time, usage, pid)) |
| 131 time.sleep(self.NUM_SECONDS_BETWEEN_MEASUREMENTS) | 131 time.sleep(self.NUM_SECONDS_BETWEEN_MEASUREMENTS) |
| 132 | 132 |
| 133 | 133 |
| 134 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 135 pyauto_functional.Main() | 135 pyauto_functional.Main() |
| OLD | NEW |