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 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1402 if stats.device == 'mmcblk0': | 1402 if stats.device == 'mmcblk0': |
1403 return { | 1403 return { |
1404 'num_reads': stats.num_reads_issued, | 1404 'num_reads': stats.num_reads_issued, |
1405 'num_writes': stats.num_writes_completed, | 1405 'num_writes': stats.num_writes_completed, |
1406 'read_ms': stats.ms_spent_reading, | 1406 'read_ms': stats.ms_spent_reading, |
1407 'write_ms': stats.ms_spent_writing, | 1407 'write_ms': stats.ms_spent_writing, |
1408 } | 1408 } |
1409 logging.warning('Could not find disk IO stats.') | 1409 logging.warning('Could not find disk IO stats.') |
1410 return None | 1410 return None |
1411 | 1411 |
1412 @staticmethod | |
1413 def _GetExistingHostOutputPath(file_name): | |
bulach
2013/11/04 20:22:06
perhaps we should make the following a public API?
Philippe
2013/11/05 09:22:13
Agreed. I moved this to utils/host_path_finder.py.
| |
1414 """Returns the most likely correct full path for the given file name. | |
1415 | |
1416 Returns: The full path that was found or throws an exception if no path | |
1417 could be found. | |
1418 """ | |
1419 candidate_path = None | |
1420 self_detected_build_type = None | |
1421 out_dir = os.path.join( | |
1422 constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out')) | |
1423 | |
1424 if constants.BuildTypeIsSet(): | |
1425 candidate_path = os.path.join( | |
1426 out_dir, constants.GetBuildType(), file_name) | |
1427 else: | |
1428 release_path = os.path.join(out_dir, 'Release', file_name) | |
1429 debug_path = os.path.join(out_dir, 'Debug', file_name) | |
1430 | |
1431 if os.path.exists(release_path): | |
1432 if os.path.exists(debug_path): | |
1433 # Retain the most recent file. | |
1434 release_path_mtime = time.ctime(os.path.getmtime(release_path)) | |
1435 debug_path_mtime = time.ctime(os.path.getmtime(debug_path)) | |
1436 if release_path_mtime > debug_path_mtime: | |
1437 constants.SetBuildType('Release') | |
1438 return release_path | |
1439 constants.SetBuildType('Debug') | |
1440 return debug_path | |
1441 candidate_path = release_path | |
1442 self_detected_build_type = 'Release' | |
1443 else: | |
1444 candidate_path = debug_path | |
1445 self_detected_build_type = 'Debug' | |
1446 | |
1447 if not os.path.exists(candidate_path): | |
1448 raise Exception('File %s does not exist' % candidate_path) | |
1449 | |
1450 if self_detected_build_type: | |
1451 constants.SetBuildType(build_type) | |
1452 logging.warning('Build type set to ' + self_detected_build_type) | |
1453 return candidate_path | |
1454 | |
1455 def _PurgeUnpinnedAshmem(self): | |
1456 """Purges the unpinned ashmem memory for the whole system. | |
1457 | |
1458 This can be used to make memory measurements more stable in particular. | |
1459 """ | |
1460 host_path = AndroidCommands._GetExistingHostOutputPath('purge_ashmem') | |
1461 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
1462 self.PushIfNeeded(host_path, device_path) | |
1463 if not self.RunShellCommand(device_path, log_result=True): | |
1464 logging.warning('Could not purge ashmem. Measurement might be unstable.') | |
1465 | |
1412 def GetMemoryUsageForPid(self, pid): | 1466 def GetMemoryUsageForPid(self, pid): |
1413 """Returns the memory usage for given pid. | 1467 """Returns the memory usage for given pid. |
1414 | 1468 |
1415 Args: | 1469 Args: |
1416 pid: The pid number of the specific process running on device. | 1470 pid: The pid number of the specific process running on device. |
1417 | 1471 |
1418 Returns: | 1472 Returns: |
1419 A tuple containg: | 1473 A tuple containg: |
1420 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1474 [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, | 1475 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, |
1422 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, | 1476 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, |
1423 KernelPageSize, MMUPageSize, Nvidia (tablet only). | 1477 KernelPageSize, MMUPageSize, Nvidia (tablet only). |
1424 [1]: Detailed /proc/[PID]/smaps information. | 1478 [1]: Detailed /proc/[PID]/smaps information. |
1425 """ | 1479 """ |
1426 usage_dict = collections.defaultdict(int) | 1480 usage_dict = collections.defaultdict(int) |
1427 smaps = collections.defaultdict(dict) | 1481 smaps = collections.defaultdict(dict) |
1482 self._PurgeUnpinnedAshmem() | |
1428 current_smap = '' | 1483 current_smap = '' |
1429 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, | 1484 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, |
1430 log_result=False): | 1485 log_result=False): |
1431 items = line.split() | 1486 items = line.split() |
1432 # See man 5 proc for more details. The format is: | 1487 # See man 5 proc for more details. The format is: |
1433 # address perms offset dev inode pathname | 1488 # address perms offset dev inode pathname |
1434 if len(items) > 5: | 1489 if len(items) > 5: |
1435 current_smap = ' '.join(items[5:]) | 1490 current_smap = ' '.join(items[5:]) |
1436 elif len(items) > 3: | 1491 elif len(items) > 3: |
1437 current_smap = ' '.join(items[3:]) | 1492 current_smap = ' '.join(items[3:]) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1654 """ | 1709 """ |
1655 def __init__(self, output): | 1710 def __init__(self, output): |
1656 self._output = output | 1711 self._output = output |
1657 | 1712 |
1658 def write(self, data): | 1713 def write(self, data): |
1659 data = data.replace('\r\r\n', '\n') | 1714 data = data.replace('\r\r\n', '\n') |
1660 self._output.write(data) | 1715 self._output.write(data) |
1661 | 1716 |
1662 def flush(self): | 1717 def flush(self): |
1663 self._output.flush() | 1718 self._output.flush() |
OLD | NEW |