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 | |
25 from utils import host_path_finder | |
26 | |
24 try: | 27 try: |
25 from pylib import pexpect | 28 from pylib import pexpect |
26 except: | 29 except: |
27 pexpect = None | 30 pexpect = None |
28 | 31 |
29 sys.path.append(os.path.join( | 32 sys.path.append(os.path.join( |
30 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 33 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
31 import adb_interface | 34 import adb_interface |
32 import am_instrument_parser | 35 import am_instrument_parser |
33 import errors | 36 import errors |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 if stats.device == 'mmcblk0': | 1405 if stats.device == 'mmcblk0': |
1403 return { | 1406 return { |
1404 'num_reads': stats.num_reads_issued, | 1407 'num_reads': stats.num_reads_issued, |
1405 'num_writes': stats.num_writes_completed, | 1408 'num_writes': stats.num_writes_completed, |
1406 'read_ms': stats.ms_spent_reading, | 1409 'read_ms': stats.ms_spent_reading, |
1407 'write_ms': stats.ms_spent_writing, | 1410 'write_ms': stats.ms_spent_writing, |
1408 } | 1411 } |
1409 logging.warning('Could not find disk IO stats.') | 1412 logging.warning('Could not find disk IO stats.') |
1410 return None | 1413 return None |
1411 | 1414 |
1415 def _PurgeUnpinnedAshmem(self): | |
bulach
2013/11/05 16:25:14
probably best to make this public and let callers
Philippe
2013/11/05 16:37:42
Yeah, good idea. I don't think many clients will n
| |
1416 """Purges the unpinned ashmem memory for the whole system. | |
1417 | |
1418 This can be used to make memory measurements more stable in particular. | |
1419 """ | |
1420 host_path = host_path_finder.GetMostRecentHostPath('purge_ashmem') | |
1421 if host_path: | |
1422 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
1423 self.PushIfNeeded(host_path, device_path) | |
1424 if self.RunShellCommand(device_path, log_result=True): | |
1425 return | |
1426 logging.error('Could not purge ashmem. Measurement might be unstable.') | |
1427 | |
1412 def GetMemoryUsageForPid(self, pid): | 1428 def GetMemoryUsageForPid(self, pid): |
1413 """Returns the memory usage for given pid. | 1429 """Returns the memory usage for given pid. |
1414 | 1430 |
1415 Args: | 1431 Args: |
1416 pid: The pid number of the specific process running on device. | 1432 pid: The pid number of the specific process running on device. |
1417 | 1433 |
1418 Returns: | 1434 Returns: |
1419 A tuple containg: | 1435 A tuple containg: |
1420 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1436 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. |
1421 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, | 1437 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, |
1422 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, | 1438 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, |
1423 KernelPageSize, MMUPageSize, Nvidia (tablet only). | 1439 KernelPageSize, MMUPageSize, Nvidia (tablet only). |
1424 [1]: Detailed /proc/[PID]/smaps information. | 1440 [1]: Detailed /proc/[PID]/smaps information. |
1425 """ | 1441 """ |
1426 usage_dict = collections.defaultdict(int) | 1442 usage_dict = collections.defaultdict(int) |
1427 smaps = collections.defaultdict(dict) | 1443 smaps = collections.defaultdict(dict) |
1444 self._PurgeUnpinnedAshmem() | |
1428 current_smap = '' | 1445 current_smap = '' |
1429 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, | 1446 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, |
1430 log_result=False): | 1447 log_result=False): |
1431 items = line.split() | 1448 items = line.split() |
1432 # See man 5 proc for more details. The format is: | 1449 # See man 5 proc for more details. The format is: |
1433 # address perms offset dev inode pathname | 1450 # address perms offset dev inode pathname |
1434 if len(items) > 5: | 1451 if len(items) > 5: |
1435 current_smap = ' '.join(items[5:]) | 1452 current_smap = ' '.join(items[5:]) |
1436 elif len(items) > 3: | 1453 elif len(items) > 3: |
1437 current_smap = ' '.join(items[3:]) | 1454 current_smap = ' '.join(items[3:]) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1654 """ | 1671 """ |
1655 def __init__(self, output): | 1672 def __init__(self, output): |
1656 self._output = output | 1673 self._output = output |
1657 | 1674 |
1658 def write(self, data): | 1675 def write(self, data): |
1659 data = data.replace('\r\r\n', '\n') | 1676 data = data.replace('\r\r\n', '\n') |
1660 self._output.write(data) | 1677 self._output.write(data) |
1661 | 1678 |
1662 def flush(self): | 1679 def flush(self): |
1663 self._output.flush() | 1680 self._output.flush() |
OLD | NEW |