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 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 """Returns the memory usage for given pid. | 1413 """Returns the memory usage for given pid. |
1414 | 1414 |
1415 Args: | 1415 Args: |
1416 pid: The pid number of the specific process running on device. | 1416 pid: The pid number of the specific process running on device. |
1417 | 1417 |
1418 Returns: | 1418 Returns: |
1419 A tuple containg: | 1419 A tuple containg: |
1420 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1420 [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, | 1421 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, |
1422 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, | 1422 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, |
1423 KernelPageSize, MMUPageSize, Nvidia (tablet only). | 1423 KernelPageSize, MMUPageSize, Nvidia (tablet only), VmHWM. |
1424 [1]: Detailed /proc/[PID]/smaps information. | 1424 [1]: Detailed /proc/[PID]/smaps information. |
1425 """ | 1425 """ |
1426 usage_dict = collections.defaultdict(int) | 1426 usage_dict = collections.defaultdict(int) |
1427 smaps = collections.defaultdict(dict) | 1427 smaps = collections.defaultdict(dict) |
1428 current_smap = '' | 1428 current_smap = '' |
1429 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, | 1429 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, |
1430 log_result=False): | 1430 log_result=False): |
1431 items = line.split() | 1431 items = line.split() |
1432 # See man 5 proc for more details. The format is: | 1432 # See man 5 proc for more details. The format is: |
1433 # address perms offset dev inode pathname | 1433 # address perms offset dev inode pathname |
(...skipping 14 matching lines...) Expand all Loading... |
1448 logging.warning('Could not find memory usage for pid ' + str(pid)) | 1448 logging.warning('Could not find memory usage for pid ' + str(pid)) |
1449 | 1449 |
1450 for line in self.GetProtectedFileContents('/d/nvmap/generic-0/clients', | 1450 for line in self.GetProtectedFileContents('/d/nvmap/generic-0/clients', |
1451 log_result=False): | 1451 log_result=False): |
1452 match = re.match(NVIDIA_MEMORY_INFO_RE, line) | 1452 match = re.match(NVIDIA_MEMORY_INFO_RE, line) |
1453 if match and match.group('pid') == pid: | 1453 if match and match.group('pid') == pid: |
1454 usage_bytes = int(match.group('usage_bytes')) | 1454 usage_bytes = int(match.group('usage_bytes')) |
1455 usage_dict['Nvidia'] = int(round(usage_bytes / 1000.0)) # kB | 1455 usage_dict['Nvidia'] = int(round(usage_bytes / 1000.0)) # kB |
1456 break | 1456 break |
1457 | 1457 |
| 1458 peak_value_kb = 0 |
| 1459 for line in self.GetProtectedFileContents('/proc/%s/status' % pid, |
| 1460 log_result=False): |
| 1461 if not line.startswith('VmHWM:'): # Format: 'VmHWM: +[0-9]+ kB' |
| 1462 continue |
| 1463 peak_value_kb = int(line.split(':')[1].strip().split(' ')[0]) |
| 1464 usage_dict['VmHWM'] = peak_value_kb |
| 1465 if not peak_value_kb: |
| 1466 logging.warning('Could not find memory peak value for pid ' + str(pid)) |
| 1467 |
1458 return (usage_dict, smaps) | 1468 return (usage_dict, smaps) |
1459 | 1469 |
1460 def GetMemoryUsageForPackage(self, package): | 1470 def GetMemoryUsageForPackage(self, package): |
1461 """Returns the memory usage for all processes whose name contains |pacakge|. | 1471 """Returns the memory usage for all processes whose name contains |pacakge|. |
1462 | 1472 |
1463 Args: | 1473 Args: |
1464 package: A string holding process name to lookup pid list for. | 1474 package: A string holding process name to lookup pid list for. |
1465 | 1475 |
1466 Returns: | 1476 Returns: |
1467 A tuple containg: | 1477 A tuple containg: |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 """ | 1664 """ |
1655 def __init__(self, output): | 1665 def __init__(self, output): |
1656 self._output = output | 1666 self._output = output |
1657 | 1667 |
1658 def write(self, data): | 1668 def write(self, data): |
1659 data = data.replace('\r\r\n', '\n') | 1669 data = data.replace('\r\r\n', '\n') |
1660 self._output.write(data) | 1670 self._output.write(data) |
1661 | 1671 |
1662 def flush(self): | 1672 def flush(self): |
1663 self._output.flush() | 1673 self._output.flush() |
OLD | NEW |