| 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 inspect | 12 import inspect |
| 13 import logging | 13 import logging |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import shlex | 16 import shlex |
| 17 import signal | 17 import signal |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 import tempfile | 20 import tempfile |
| 21 import time | 21 import time |
| 22 | 22 |
| 23 import cmd_helper | 23 import cmd_helper |
| 24 import constants | 24 import constants |
| 25 import screenshot | 25 import screenshot |
| 26 import system_properties | 26 import system_properties |
| 27 | 27 |
| 28 from utils import host_path_finder | |
| 29 | |
| 30 try: | 28 try: |
| 31 from pylib import pexpect | 29 from pylib import pexpect |
| 32 except: | 30 except: |
| 33 pexpect = None | 31 pexpect = None |
| 34 | 32 |
| 35 sys.path.append(os.path.join( | 33 sys.path.append(os.path.join( |
| 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 34 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
| 37 import adb_interface | 35 import adb_interface |
| 38 import am_instrument_parser | 36 import am_instrument_parser |
| 39 import errors | 37 import errors |
| (...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 if stats.device == 'mmcblk0': | 1492 if stats.device == 'mmcblk0': |
| 1495 return { | 1493 return { |
| 1496 'num_reads': stats.num_reads_issued, | 1494 'num_reads': stats.num_reads_issued, |
| 1497 'num_writes': stats.num_writes_completed, | 1495 'num_writes': stats.num_writes_completed, |
| 1498 'read_ms': stats.ms_spent_reading, | 1496 'read_ms': stats.ms_spent_reading, |
| 1499 'write_ms': stats.ms_spent_writing, | 1497 'write_ms': stats.ms_spent_writing, |
| 1500 } | 1498 } |
| 1501 logging.warning('Could not find disk IO stats.') | 1499 logging.warning('Could not find disk IO stats.') |
| 1502 return None | 1500 return None |
| 1503 | 1501 |
| 1504 def PurgeUnpinnedAshmem(self): | |
| 1505 """Purges the unpinned ashmem memory for the whole system. | |
| 1506 | |
| 1507 This can be used to make memory measurements more stable in particular. | |
| 1508 """ | |
| 1509 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') | |
| 1510 if not host_path: | |
| 1511 raise Exception('Could not find the purge_ashmem binary.') | |
| 1512 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
| 1513 self.PushIfNeeded(host_path, device_path) | |
| 1514 if self.RunShellCommand(device_path, log_result=True): | |
| 1515 return | |
| 1516 raise Exception('Error while purging ashmem.') | |
| 1517 | |
| 1518 def GetMemoryUsageForPid(self, pid): | 1502 def GetMemoryUsageForPid(self, pid): |
| 1519 """Returns the memory usage for given pid. | 1503 """Returns the memory usage for given pid. |
| 1520 | 1504 |
| 1521 Args: | 1505 Args: |
| 1522 pid: The pid number of the specific process running on device. | 1506 pid: The pid number of the specific process running on device. |
| 1523 | 1507 |
| 1524 Returns: | 1508 Returns: |
| 1525 A tuple containg: | 1509 A tuple containg: |
| 1526 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1510 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. |
| 1527 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, | 1511 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... |
| 1769 """ | 1753 """ |
| 1770 def __init__(self, output): | 1754 def __init__(self, output): |
| 1771 self._output = output | 1755 self._output = output |
| 1772 | 1756 |
| 1773 def write(self, data): | 1757 def write(self, data): |
| 1774 data = data.replace('\r\r\n', '\n') | 1758 data = data.replace('\r\r\n', '\n') |
| 1775 self._output.write(data) | 1759 self._output.write(data) |
| 1776 | 1760 |
| 1777 def flush(self): | 1761 def flush(self): |
| 1778 self._output.flush() | 1762 self._output.flush() |
| OLD | NEW |