diff options
author | jbudorick@chromium.org <jbudorick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 01:03:49 +0000 |
---|---|---|
committer | jbudorick@chromium.org <jbudorick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-24 01:03:49 +0000 |
commit | 0af49a8f2b05ecca92f3ae64ded123bdafe07c1a (patch) | |
tree | 3d35ef7161144d021efce7228a4d02f19f0b9e55 | |
parent | 9b64ef2c039bb1a23660a36e7ae1fdb42afccec4 (diff) | |
download | chromium_src-0af49a8f2b05ecca92f3ae64ded123bdafe07c1a.zip chromium_src-0af49a8f2b05ecca92f3ae64ded123bdafe07c1a.tar.gz chromium_src-0af49a8f2b05ecca92f3ae64ded123bdafe07c1a.tar.bz2 |
[Android] Switch to DeviceUtils versions of GetMemoryUsageForPid and __str__.
BUG=267773
Review URL: https://codereview.chromium.org/404993004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285097 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | build/android/pylib/device/device_utils.py | 64 | ||||
-rwxr-xr-x | build/android/pylib/device/device_utils_test.py | 42 | ||||
-rw-r--r-- | build/android/pylib/forwarder.py | 8 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_package_exe.py | 2 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_runner.py | 2 | ||||
-rw-r--r-- | build/android/pylib/host_driven/test_runner.py | 2 | ||||
-rw-r--r-- | build/android/pylib/instrumentation/test_runner.py | 5 | ||||
-rw-r--r-- | build/android/pylib/perf/thermal_throttle.py | 2 | ||||
-rw-r--r-- | build/android/pylib/screenshot.py | 4 | ||||
-rw-r--r-- | build/android/pylib/valgrind_tools.py | 2 | ||||
-rwxr-xr-x | build/android/tombstones.py | 2 | ||||
-rw-r--r-- | tools/memory_inspector/memory_inspector/backends/android/android_backend.py | 2 | ||||
-rw-r--r-- | tools/profile_chrome/perf_controller.py | 5 | ||||
-rw-r--r-- | tools/profile_chrome/systrace_controller.py | 6 | ||||
-rw-r--r-- | tools/telemetry/telemetry/core/forwarders/android_forwarder.py | 2 | ||||
-rw-r--r-- | tools/telemetry/telemetry/core/platform/android_platform_backend.py | 2 |
16 files changed, 129 insertions, 23 deletions
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py index 33d6351..5018b9c 100644 --- a/build/android/pylib/device/device_utils.py +++ b/build/android/pylib/device/device_utils.py @@ -83,8 +83,10 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Returns: True if the device is online, False otherwise. + Raises: CommandTimeoutError on timeout. """ @@ -97,8 +99,10 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Returns: True if adbd has root privileges, False otherwise. + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -113,6 +117,7 @@ class DeviceUtils(object): Returns: Same as for |HasRoot|. + Raises: Same as for |HasRoot|. """ @@ -125,6 +130,7 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError if root could not be enabled. CommandTimeoutError on timeout. @@ -140,8 +146,10 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Returns: The device's path to its SD card. + Raises: CommandFailedError if the external storage path could not be determined. CommandTimeoutError on timeout. @@ -165,6 +173,7 @@ class DeviceUtils(object): wifi: A boolean indicating if we should wait for wifi to come up or not. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError on failure. CommandTimeoutError if one of the component waits times out. @@ -184,6 +193,7 @@ class DeviceUtils(object): Args: wifi: Same as for |WaitUntilFullyBooted|. timeout: timeout in seconds + Raises: Same as for |WaitUntilFullyBooted|. """ @@ -210,6 +220,7 @@ class DeviceUtils(object): block: A boolean indicating if we should wait for the reboot to complete. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -234,6 +245,7 @@ class DeviceUtils(object): reinstall: A boolean indicating if we should keep any existing app data. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError if the installation fails. CommandTimeoutError if the installation times out. @@ -283,8 +295,10 @@ class DeviceUtils(object): with root privileges. timeout: timeout in seconds retries: number of retries + Returns: The output of the command. + Raises: CommandFailedError if check_return is True and the return code is nozero. CommandTimeoutError on timeout. @@ -308,8 +322,10 @@ class DeviceUtils(object): check_return: Same as for |RunShellCommand|. as_root: Same as for |RunShellCommand|. timeout: timeout in seconds + Raises: Same as for |RunShellCommand|. + Returns: Same as for |RunShellCommand|. """ @@ -342,6 +358,7 @@ class DeviceUtils(object): with the given |process_name| are dead. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError if no process was killed. CommandTimeoutError on timeout. @@ -378,6 +395,7 @@ class DeviceUtils(object): before starting it. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError if the activity could not be started. CommandTimeoutError on timeout. @@ -402,6 +420,7 @@ class DeviceUtils(object): intent: An Intent to broadcast. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -421,6 +440,7 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -435,6 +455,7 @@ class DeviceUtils(object): package: A string containing the name of the package to stop. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -449,6 +470,7 @@ class DeviceUtils(object): package: A string containing the name of the package to stop. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -465,6 +487,7 @@ class DeviceUtils(object): keycode: A integer keycode to send to the device. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -488,6 +511,7 @@ class DeviceUtils(object): the device. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError on failure. CommandTimeoutError on timeout. @@ -504,8 +528,10 @@ class DeviceUtils(object): device. timeout: timeout in seconds retries: number of retries + Returns: True if the file exists on the device, False otherwise. + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -520,8 +546,10 @@ class DeviceUtils(object): Args: device_path: Same as for |FileExists|. + Returns: True if the file exists on the device, False otherwise. + Raises: Same as for |FileExists|. """ @@ -538,6 +566,7 @@ class DeviceUtils(object): the host. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError on failure. CommandTimeoutError on timeout. @@ -559,8 +588,10 @@ class DeviceUtils(object): root privileges. timeout: timeout in seconds retries: number of retries + Returns: The contents of the file at |device_path| as a list of lines. + Raises: CommandFailedError if the file can't be read. CommandTimeoutError on timeout. @@ -589,6 +620,7 @@ class DeviceUtils(object): root privileges. timeout: timeout in seconds retries: number of retries + Raises: CommandFailedError if the file could not be written on the device. CommandTimeoutError on timeout. @@ -611,8 +643,10 @@ class DeviceUtils(object): to list. timeout: timeout in seconds retries: number of retries + Returns: The contents of the directory specified by |device_path|. + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -628,6 +662,7 @@ class DeviceUtils(object): or disabled. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. """ @@ -642,8 +677,10 @@ class DeviceUtils(object): the device. timeout: timeout in seconds retries: number of retries + Returns: The value of the device's |property_name| property. + Raises: CommandTimeoutError on timeout. """ @@ -660,6 +697,7 @@ class DeviceUtils(object): device. timeout: timeout in seconds retries: number of retries + Raises: CommandTimeoutError on timeout. """ @@ -675,9 +713,11 @@ class DeviceUtils(object): process_name: A string containing the process name to get the PIDs for. timeout: timeout in seconds retries: number of retries + Returns: A dict mapping process name to PID for each process that contained the provided |process_name|. + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. @@ -701,8 +741,10 @@ class DeviceUtils(object): screenshot to. If None, a file name will be generated. timeout: timeout in seconds retries: number of retries + Returns: The name of the file on the host to which the screenshot was saved. + Raises: CommandFailedError on failure. CommandTimeoutError on timeout. @@ -717,14 +759,35 @@ class DeviceUtils(object): Args: timeout: timeout in seconds retries: number of retries + Returns: A dict containing |num_reads|, |num_writes|, |read_ms|, and |write_ms|. + Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ return self.old_interface.GetIoStats() + @decorators.WithTimeoutAndRetriesFromInstance() + def GetMemoryUsageForPid(self, pid, timeout=None, retries=None): + """Gets the memory usage for the given PID. + + Args: + pid: PID of the process. + timeout: timeout in seconds + retries: number of retries + + Returns: + A 2-tuple containing: + - A dict containing the overall memory usage statistics for the PID. + - A dict containing memory usage statistics broken down by mapping. + + Raises: + CommandTimeoutError on timeout. + """ + return self.old_interface.GetMemoryUsageForPid(pid) + def __str__(self): """Returns the device serial.""" return self.old_interface.GetDevice() @@ -742,6 +805,7 @@ class DeviceUtils(object): all attached devices will be used. async: If true, returns a Parallelizer that runs operations asynchronously. + Returns: A Parallelizer operating over |devices|. """ diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py index bd671d1..b6a99d2 100755 --- a/build/android/pylib/device/device_utils_test.py +++ b/build/android/pylib/device/device_utils_test.py @@ -1443,6 +1443,48 @@ class DeviceUtilsGetIOStatsTest(DeviceUtilsOldImplTest): self.device.GetIOStats()) +class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsOldImplTest): + + def setUp(self): + super(DeviceUtilsGetMemoryUsageForPidTest, self).setUp() + self.device.old_interface._privileged_command_runner = ( + self.device.old_interface.RunShellCommand) + self.device.old_interface._protected_file_access_method_initialized = True + + def testGetMemoryUsageForPid_validPid(self): + with self.assertCallsSequence([ + ("adb -s 0123456789abcdef shell 'showmap 1234'", + '100 101 102 103 104 105 106 107 TOTAL\r\n'), + ("adb -s 0123456789abcdef shell " + "'cat \"/proc/1234/status\" 2> /dev/null'", + 'VmHWM: 1024 kB') + ]): + self.assertEqual( + { + 'Size': 100, + 'Rss': 101, + 'Pss': 102, + 'Shared_Clean': 103, + 'Shared_Dirty': 104, + 'Private_Clean': 105, + 'Private_Dirty': 106, + 'VmHWM': 1024 + }, + self.device.GetMemoryUsageForPid(1234)) + + def testGetMemoryUsageForPid_invalidPid(self): + with self.assertCalls( + "adb -s 0123456789abcdef shell 'showmap 4321'", + 'cannot open /proc/4321/smaps: No such file or directory\r\n'): + self.assertEqual({}, self.device.GetMemoryUsageForPid(4321)) + + +class DeviceUtilsStrTest(DeviceUtilsOldImplTest): + def testStr_noAdbCalls(self): + with self.assertNoAdbCalls(): + self.assertEqual('0123456789abcdef', str(self.device)) + + if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) unittest.main(verbosity=2) diff --git a/build/android/pylib/forwarder.py b/build/android/pylib/forwarder.py index be67d7d..c5d4f59 100644 --- a/build/android/pylib/forwarder.py +++ b/build/android/pylib/forwarder.py @@ -89,7 +89,7 @@ class Forwarder(object): instance = Forwarder._GetInstanceLocked(tool) instance._InitDeviceLocked(device, tool) - device_serial = device.old_interface.Adb().GetSerialNumber() + device_serial = str(device) redirection_commands = [ ['--serial-id=' + device_serial, '--map', str(device), str(host)] for device, host in port_pairs] @@ -147,7 +147,7 @@ class Forwarder(object): with _FileLock(Forwarder._LOCK_PATH): if not Forwarder._instance: return - adb_serial = device.old_interface.Adb().GetSerialNumber() + adb_serial = str(device) if adb_serial not in Forwarder._instance._initialized_devices: return port_map = Forwarder._GetInstanceLocked( @@ -224,7 +224,7 @@ class Forwarder(object): Note that the global lock must be acquired before calling this method. """ instance = Forwarder._GetInstanceLocked(None) - serial = device.old_interface.Adb().GetSerialNumber() + serial = str(device) serial_with_port = (serial, device_port) if not serial_with_port in instance._device_to_host_port_map: logging.error('Trying to unmap non-forwarded port %d' % device_port) @@ -286,7 +286,7 @@ class Forwarder(object): tool: Tool class to use to get wrapper, if necessary, for executing the forwarder (see valgrind_tools.py). """ - device_serial = device.old_interface.Adb().GetSerialNumber() + device_serial = str(device) if device_serial in self._initialized_devices: return Forwarder._KillDeviceLocked(device, tool) diff --git a/build/android/pylib/gtest/test_package_exe.py b/build/android/pylib/gtest/test_package_exe.py index 9714c42..5f82aad 100644 --- a/build/android/pylib/gtest/test_package_exe.py +++ b/build/android/pylib/gtest/test_package_exe.py @@ -123,7 +123,7 @@ class TestPackageExecutable(TestPackage): #override def SpawnTestProcess(self, device): - args = ['adb', '-s', device.old_interface.GetDevice(), 'shell', 'sh', + args = ['adb', '-s', str(device), 'shell', 'sh', constants.TEST_EXECUTABLE_DIR + '/chrome_test_runner.sh'] logging.info(args) return pexpect.spawn(args[0], args[1:], logfile=sys.stdout) diff --git a/build/android/pylib/gtest/test_runner.py b/build/android/pylib/gtest/test_runner.py index c9a6044..faffe8f 100644 --- a/build/android/pylib/gtest/test_runner.py +++ b/build/android/pylib/gtest/test_runner.py @@ -131,7 +131,7 @@ class TestRunner(base_test_runner.BaseTestRunner): # crashed without outputting the CRASHED marker (crbug.com/175538). if not self.device.IsOnline(): raise device_errors.DeviceUnreachableError( - 'Device %s went offline.' % self.device.old_interface.GetDevice()) + 'Device %s went offline.' % str(self.device)) if full_test_name: results.AddResult(base_test_result.BaseTestResult( full_test_name, base_test_result.ResultType.CRASH, diff --git a/build/android/pylib/host_driven/test_runner.py b/build/android/pylib/host_driven/test_runner.py index 7072763..b61fa40 100644 --- a/build/android/pylib/host_driven/test_runner.py +++ b/build/android/pylib/host_driven/test_runner.py @@ -85,7 +85,7 @@ class HostDrivenTestRunner(base_test_runner.BaseTestRunner): exception_raised = False try: - test.SetUp(self.device.old_interface.GetDevice(), self.shard_index, + test.SetUp(str(self.device), self.shard_index, self._push_deps, self._cleanup_test_files) except Exception: logging.exception( diff --git a/build/android/pylib/instrumentation/test_runner.py b/build/android/pylib/instrumentation/test_runner.py index 923a3fd..d9ccb26 100644 --- a/build/android/pylib/instrumentation/test_runner.py +++ b/build/android/pylib/instrumentation/test_runner.py @@ -98,7 +98,7 @@ class TestRunner(base_test_runner.BaseTestRunner): # once across test runners. if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): logging.warning('Already copied test files to device %s, skipping.', - self.device.old_interface.GetDevice()) + str(self.device)) return test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) @@ -125,8 +125,7 @@ class TestRunner(base_test_runner.BaseTestRunner): TestRunner._DEVICE_DATA_DIR, dst_layer)) self.tool.CopyFiles() - TestRunner._DEVICE_HAS_TEST_FILES[ - self.device.old_interface.GetDevice()] = True + TestRunner._DEVICE_HAS_TEST_FILES[str(self.device)] = True def _GetInstrumentationArgs(self): ret = {} diff --git a/build/android/pylib/perf/thermal_throttle.py b/build/android/pylib/perf/thermal_throttle.py index a125e72..24e1ff4c 100644 --- a/build/android/pylib/perf/thermal_throttle.py +++ b/build/android/pylib/perf/thermal_throttle.py @@ -99,7 +99,7 @@ class ThermalThrottle(object): if not self._detector: return False has_been_throttled = False - serial_number = self._device.old_interface.GetDevice() + serial_number = str(self._device) log = self._device.RunShellCommand('dmesg -c') degree_symbol = unichr(0x00B0) for line in log: diff --git a/build/android/pylib/screenshot.py b/build/android/pylib/screenshot.py index d69bb9a..e21d756 100644 --- a/build/android/pylib/screenshot.py +++ b/build/android/pylib/screenshot.py @@ -38,8 +38,8 @@ class VideoRecorder(object): self._is_started = False self._args = ['adb'] - if self._device.old_interface.GetDevice(): - self._args += ['-s', self._device.old_interface.GetDevice()] + if str(self._device): + self._args += ['-s', str(self._device)] self._args += ['shell', 'screenrecord', '--verbose'] self._args += ['--bit-rate', str(megabits_per_second * 1000 * 1000)] if size: diff --git a/build/android/pylib/valgrind_tools.py b/build/android/pylib/valgrind_tools.py index f11ab03..69f351a 100644 --- a/build/android/pylib/valgrind_tools.py +++ b/build/android/pylib/valgrind_tools.py @@ -117,7 +117,7 @@ class AddressSanitizerTool(BaseTool): """Copies ASan tools to the device.""" subprocess.call([os.path.join(DIR_SOURCE_ROOT, 'tools/android/asan/asan_device_setup.sh'), - '--device', self._device.old_interface.GetDevice(), + '--device', str(self._device), '--lib', self._lib, '--extra-options', AddressSanitizerTool.EXTRA_OPTIONS]) self._device.WaitUntilFullyBooted() diff --git a/build/android/tombstones.py b/build/android/tombstones.py index e7549ff..3c1624b 100755 --- a/build/android/tombstones.py +++ b/build/android/tombstones.py @@ -150,7 +150,7 @@ def _GetTombstonesForDevice(device, options): device_now = _GetDeviceDateTime(device) for tombstone_file, tombstone_time in tombstones: - ret += [{'serial': device.old_interface.Adb().GetSerialNumber(), + ret += [{'serial': str(device), 'device_now': device_now, 'time': tombstone_time, 'file': tombstone_file, diff --git a/tools/memory_inspector/memory_inspector/backends/android/android_backend.py b/tools/memory_inspector/memory_inspector/backends/android/android_backend.py index bf10d5d..f38c2de 100644 --- a/tools/memory_inspector/memory_inspector/backends/android/android_backend.py +++ b/tools/memory_inspector/memory_inspector/backends/android/android_backend.py @@ -165,7 +165,7 @@ class AndroidDevice(backends.Device): backend=backend, settings=backends.Settings(AndroidDevice._SETTINGS_KEYS)) self.underlying_device = underlying_device - self._id = underlying_device.old_interface.GetDevice() + self._id = str(underlying_device) self._name = underlying_device.GetProp('ro.product.model') self._sys_stats = None self._last_device_stats = None diff --git a/tools/profile_chrome/perf_controller.py b/tools/profile_chrome/perf_controller.py index c2cef2c..2b94960 100644 --- a/tools/profile_chrome/perf_controller.py +++ b/tools/profile_chrome/perf_controller.py @@ -51,8 +51,9 @@ class _PerfProfiler(object): self._device.old_interface, prefix='perf_output') self._log_file = tempfile.TemporaryFile() - device_param = (['-s', self._device.old_interface.GetDevice()] - if self._device.old_interface.GetDevice() else []) + # TODO(jbudorick) Look at providing a way to unhandroll this once the + # adb rewrite has fully landed. + device_param = (['-s', str(self._device)] if str(self._device) else []) cmd = ['adb'] + device_param + \ ['shell', perf_binary, 'record', '--output', self._output_file.name] + _PERF_OPTIONS diff --git a/tools/profile_chrome/systrace_controller.py b/tools/profile_chrome/systrace_controller.py index 387ea9f..5265834 100644 --- a/tools/profile_chrome/systrace_controller.py +++ b/tools/profile_chrome/systrace_controller.py @@ -56,11 +56,11 @@ class SystraceController(controllers.BaseController): return output_name def _RunATraceCommand(self, command): - # TODO(jbudorick) can this be made work with DeviceUtils? # We use a separate interface to adb because the one from AndroidCommands # isn't re-entrant. - device_param = (['-s', self._device.old_interface.GetDevice()] - if self._device.old_interface.GetDevice() else []) + # TODO(jbudorick) Look at providing a way to unhandroll this once the + # adb rewrite has fully landed. + device_param = (['-s', str(self._device)] if str(self._device) else []) cmd = ['adb'] + device_param + ['shell', 'atrace', '--%s' % command] + \ _SYSTRACE_OPTIONS + self._categories return cmd_helper.GetCmdOutput(cmd) diff --git a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py index eb56079..df6dd45 100644 --- a/tools/telemetry/telemetry/core/forwarders/android_forwarder.py +++ b/tools/telemetry/telemetry/core/forwarders/android_forwarder.py @@ -321,7 +321,7 @@ doit & """Returns the IP addresses on all connected devices. Excludes interface |excluded_iface| on the selected device. """ - my_device = self._device.old_interface.GetDevice() + my_device = str(self._device) addresses = [] for device_serial in adb_commands.GetAttachedDevices(): device = adb_commands.AdbCommands(device_serial).device() diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend.py b/tools/telemetry/telemetry/core/platform/android_platform_backend.py index 0537b42..da73e40 100644 --- a/tools/telemetry/telemetry/core/platform/android_platform_backend.py +++ b/tools/telemetry/telemetry/core/platform/android_platform_backend.py @@ -137,7 +137,7 @@ class AndroidPlatformBackend( raise Exception('Error while purging ashmem: ' + '\n'.join(output)) def GetMemoryStats(self, pid): - memory_usage = self._device.old_interface.GetMemoryUsageForPid(pid) + memory_usage = self._device.GetMemoryUsageForPid(pid) return {'ProportionalSetSize': memory_usage['Pss'] * 1024, 'SharedDirty': memory_usage['Shared_Dirty'] * 1024, 'PrivateDirty': memory_usage['Private_Dirty'] * 1024, |