OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 self._device = device | 246 self._device = device |
247 self._logcat = None | 247 self._logcat = None |
248 self.logcat_process = None | 248 self.logcat_process = None |
249 self._logcat_tmpoutfile = None | 249 self._logcat_tmpoutfile = None |
250 self._pushed_files = [] | 250 self._pushed_files = [] |
251 self._device_utc_offset = None | 251 self._device_utc_offset = None |
252 self._potential_push_size = 0 | 252 self._potential_push_size = 0 |
253 self._actual_push_size = 0 | 253 self._actual_push_size = 0 |
254 self._external_storage = '' | 254 self._external_storage = '' |
255 self._util_wrapper = '' | 255 self._util_wrapper = '' |
256 self._purge_ashmem_binary_was_pushed = False | |
256 | 257 |
257 def _LogShell(self, cmd): | 258 def _LogShell(self, cmd): |
258 """Logs the adb shell command.""" | 259 """Logs the adb shell command.""" |
259 if self._device: | 260 if self._device: |
260 device_repr = self._device[-4:] | 261 device_repr = self._device[-4:] |
261 else: | 262 else: |
262 device_repr = '????' | 263 device_repr = '????' |
263 logging.info('[%s]> %s', device_repr, cmd) | 264 logging.info('[%s]> %s', device_repr, cmd) |
264 | 265 |
265 def Adb(self): | 266 def Adb(self): |
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1428 if stats.device == 'mmcblk0': | 1429 if stats.device == 'mmcblk0': |
1429 return { | 1430 return { |
1430 'num_reads': stats.num_reads_issued, | 1431 'num_reads': stats.num_reads_issued, |
1431 'num_writes': stats.num_writes_completed, | 1432 'num_writes': stats.num_writes_completed, |
1432 'read_ms': stats.ms_spent_reading, | 1433 'read_ms': stats.ms_spent_reading, |
1433 'write_ms': stats.ms_spent_writing, | 1434 'write_ms': stats.ms_spent_writing, |
1434 } | 1435 } |
1435 logging.warning('Could not find disk IO stats.') | 1436 logging.warning('Could not find disk IO stats.') |
1436 return None | 1437 return None |
1437 | 1438 |
1439 def _PushPurgeAshmemBinaryIfNeeded(self): | |
1440 """Pushes the ashmem binary once at construction if needed.""" | |
1441 if not self._purge_ashmem_binary_was_pushed: | |
1442 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') | |
1443 if not host_path: | |
1444 raise Exception('Could not find the purge_ashmem binary.') | |
1445 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
1446 self.PushIfNeeded(host_path, device_path) | |
1447 self._purge_ashmem_binary_was_pushed = True | |
1448 | |
1438 def PurgeUnpinnedAshmem(self): | 1449 def PurgeUnpinnedAshmem(self): |
bulach
2013/11/28 13:31:24
I think both _PushPurgeAshmemBinaryIfNeeded and Pu
Philippe
2013/11/28 17:03:04
Yeah, agreed :)
| |
1439 """Purges the unpinned ashmem memory for the whole system. | 1450 """Purges the unpinned ashmem memory for the whole system. |
1440 | 1451 |
1441 This can be used to make memory measurements more stable in particular. | 1452 This can be used to make memory measurements more stable in particular. |
1442 """ | 1453 """ |
1443 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') | 1454 self._PushPurgeAshmemBinaryIfNeeded() |
1444 if not host_path: | |
1445 raise Exception('Could not find the purge_ashmem binary.') | |
1446 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | 1455 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') |
1447 self.PushIfNeeded(host_path, device_path) | |
1448 if self.RunShellCommand(device_path, log_result=True): | 1456 if self.RunShellCommand(device_path, log_result=True): |
1449 return | 1457 return |
1450 raise Exception('Error while purging ashmem.') | 1458 raise Exception('Error while purging ashmem.') |
1451 | 1459 |
1452 def GetMemoryUsageForPid(self, pid): | 1460 def GetMemoryUsageForPid(self, pid): |
1453 """Returns the memory usage for given pid. | 1461 """Returns the memory usage for given pid. |
1454 | 1462 |
1455 Args: | 1463 Args: |
1456 pid: The pid number of the specific process running on device. | 1464 pid: The pid number of the specific process running on device. |
1457 | 1465 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1703 """ | 1711 """ |
1704 def __init__(self, output): | 1712 def __init__(self, output): |
1705 self._output = output | 1713 self._output = output |
1706 | 1714 |
1707 def write(self, data): | 1715 def write(self, data): |
1708 data = data.replace('\r\r\n', '\n') | 1716 data = data.replace('\r\r\n', '\n') |
1709 self._output.write(data) | 1717 self._output.write(data) |
1710 | 1718 |
1711 def flush(self): | 1719 def flush(self): |
1712 self._output.flush() | 1720 self._output.flush() |
OLD | NEW |