[Android] Switch to DeviceUtils versions of GetMemoryUsageForPid and __str__.

BUG=267773

Review URL: https://codereview.chromium.org/404993004

git-svn-id: http://src.chromium.org/svn/trunk/src/build@285097 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
jbudorick@chromium.org 2014-07-24 01:03:49 +00:00
Родитель 828fa9ecf5
Коммит 19d4bf2ffb
11 изменённых файлов: 120 добавлений и 15 удалений

Просмотреть файл

@ -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|.
"""

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)

Просмотреть файл

@ -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,

Просмотреть файл

@ -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(

Просмотреть файл

@ -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 = {}

Просмотреть файл

@ -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:

Просмотреть файл

@ -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:

Просмотреть файл

@ -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()

Просмотреть файл

@ -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,