| 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 |
| 11 import datetime | 11 import datetime |
| 12 import logging | 12 import logging |
| 13 import os | 13 import os |
| 14 import re | 14 import re |
| 15 import shlex | 15 import shlex |
| 16 import signal | 16 import signal |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 import tempfile | 19 import tempfile |
| 20 import time | 20 import time |
| 21 | 21 |
| 22 import cmd_helper | 22 import cmd_helper |
| 23 import constants | 23 import constants |
| 24 import screenshot | 24 import screenshot |
| 25 |
| 26 from utils import host_path_finder |
| 27 |
| 25 try: | 28 try: |
| 26 from pylib import pexpect | 29 from pylib import pexpect |
| 27 except: | 30 except: |
| 28 pexpect = None | 31 pexpect = None |
| 29 | 32 |
| 30 sys.path.append(os.path.join( | 33 sys.path.append(os.path.join( |
| 31 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 34 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 32 import adb_interface | 35 import adb_interface |
| 33 import am_instrument_parser | 36 import am_instrument_parser |
| 34 import errors | 37 import errors |
| (...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 if stats.device == 'mmcblk0': | 1414 if stats.device == 'mmcblk0': |
| 1412 return { | 1415 return { |
| 1413 'num_reads': stats.num_reads_issued, | 1416 'num_reads': stats.num_reads_issued, |
| 1414 'num_writes': stats.num_writes_completed, | 1417 'num_writes': stats.num_writes_completed, |
| 1415 'read_ms': stats.ms_spent_reading, | 1418 'read_ms': stats.ms_spent_reading, |
| 1416 'write_ms': stats.ms_spent_writing, | 1419 'write_ms': stats.ms_spent_writing, |
| 1417 } | 1420 } |
| 1418 logging.warning('Could not find disk IO stats.') | 1421 logging.warning('Could not find disk IO stats.') |
| 1419 return None | 1422 return None |
| 1420 | 1423 |
| 1424 def PurgeUnpinnedAshmem(self): |
| 1425 """Purges the unpinned ashmem memory for the whole system. |
| 1426 |
| 1427 This can be used to make memory measurements more stable in particular. |
| 1428 """ |
| 1429 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') |
| 1430 if not host_path: |
| 1431 raise Exception('Could not find the purge_ashmem binary.') |
| 1432 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') |
| 1433 self.PushIfNeeded(host_path, device_path) |
| 1434 if self.RunShellCommand(device_path, log_result=True): |
| 1435 return |
| 1436 raise Exception('Error while purging ashmem.') |
| 1437 |
| 1421 def GetMemoryUsageForPid(self, pid): | 1438 def GetMemoryUsageForPid(self, pid): |
| 1422 """Returns the memory usage for given pid. | 1439 """Returns the memory usage for given pid. |
| 1423 | 1440 |
| 1424 Args: | 1441 Args: |
| 1425 pid: The pid number of the specific process running on device. | 1442 pid: The pid number of the specific process running on device. |
| 1426 | 1443 |
| 1427 Returns: | 1444 Returns: |
| 1428 A tuple containg: | 1445 A tuple containg: |
| 1429 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1446 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. |
| 1430 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, | 1447 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 """ | 1689 """ |
| 1673 def __init__(self, output): | 1690 def __init__(self, output): |
| 1674 self._output = output | 1691 self._output = output |
| 1675 | 1692 |
| 1676 def write(self, data): | 1693 def write(self, data): |
| 1677 data = data.replace('\r\r\n', '\n') | 1694 data = data.replace('\r\r\n', '\n') |
| 1678 self._output.write(data) | 1695 self._output.write(data) |
| 1679 | 1696 |
| 1680 def flush(self): | 1697 def flush(self): |
| 1681 self._output.flush() | 1698 self._output.flush() |
| OLD | NEW |