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 | 25 |
26 from utils import host_path_finder | |
27 | |
28 try: | 26 try: |
29 from pylib import pexpect | 27 from pylib import pexpect |
30 except: | 28 except: |
31 pexpect = None | 29 pexpect = None |
32 | 30 |
33 sys.path.append(os.path.join( | 31 sys.path.append(os.path.join( |
34 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 32 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
35 import adb_interface | 33 import adb_interface |
36 import am_instrument_parser | 34 import am_instrument_parser |
37 import errors | 35 import errors |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 if stats.device == 'mmcblk0': | 1436 if stats.device == 'mmcblk0': |
1439 return { | 1437 return { |
1440 'num_reads': stats.num_reads_issued, | 1438 'num_reads': stats.num_reads_issued, |
1441 'num_writes': stats.num_writes_completed, | 1439 'num_writes': stats.num_writes_completed, |
1442 'read_ms': stats.ms_spent_reading, | 1440 'read_ms': stats.ms_spent_reading, |
1443 'write_ms': stats.ms_spent_writing, | 1441 'write_ms': stats.ms_spent_writing, |
1444 } | 1442 } |
1445 logging.warning('Could not find disk IO stats.') | 1443 logging.warning('Could not find disk IO stats.') |
1446 return None | 1444 return None |
1447 | 1445 |
1448 def PurgeUnpinnedAshmem(self): | |
1449 """Purges the unpinned ashmem memory for the whole system. | |
1450 | |
1451 This can be used to make memory measurements more stable in particular. | |
1452 """ | |
1453 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') | |
1454 if not host_path: | |
1455 raise Exception('Could not find the purge_ashmem binary.') | |
1456 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
1457 self.PushIfNeeded(host_path, device_path) | |
1458 if self.RunShellCommand(device_path, log_result=True): | |
1459 return | |
1460 raise Exception('Error while purging ashmem.') | |
1461 | |
1462 def GetMemoryUsageForPid(self, pid): | 1446 def GetMemoryUsageForPid(self, pid): |
1463 """Returns the memory usage for given pid. | 1447 """Returns the memory usage for given pid. |
1464 | 1448 |
1465 Args: | 1449 Args: |
1466 pid: The pid number of the specific process running on device. | 1450 pid: The pid number of the specific process running on device. |
1467 | 1451 |
1468 Returns: | 1452 Returns: |
1469 A tuple containg: | 1453 A tuple containg: |
1470 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1454 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. |
1471 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, | 1455 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... |
1713 """ | 1697 """ |
1714 def __init__(self, output): | 1698 def __init__(self, output): |
1715 self._output = output | 1699 self._output = output |
1716 | 1700 |
1717 def write(self, data): | 1701 def write(self, data): |
1718 data = data.replace('\r\r\n', '\n') | 1702 data = data.replace('\r\r\n', '\n') |
1719 self._output.write(data) | 1703 self._output.write(data) |
1720 | 1704 |
1721 def flush(self): | 1705 def flush(self): |
1722 self._output.flush() | 1706 self._output.flush() |
OLD | NEW |