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): | |
frankf
2013/11/04 18:17:06
If you decide to keep this, it should be moved to
| |
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 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(): | |
Philippe
2013/10/30 17:18:21
FYI, this condition is not always met which is why
craigdh
2013/10/31 00:10:13
My understanding is that the goal is to support ar
Philippe
2013/11/04 14:45:55
I will let Marcus comment on this :)
| |
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 build_type = 'Release' | |
1443 else: | |
1444 candidate_path = debug_path | |
1445 build_type = 'Debug' | |
digit1
2013/11/04 14:15:55
I'm ok with self-detection, but if you don't plan
Philippe
2013/11/04 14:45:55
Yeah good idea. We got bitten more than once with
| |
1446 | |
1447 if not os.path.exists(candidate_path): | |
1448 raise Exception('File %s does not exist' % candidate_path) | |
1449 | |
1450 if build_type: | |
1451 constants.SetBuildType(build_type) | |
1452 return candidate_path | |
1453 | |
1454 def _PurgeUnpinnedAshmem(self): | |
1455 """Purges the unpinned ashmem memory for the whole system. | |
1456 | |
1457 This can be used to make memory measurements more stable in particular. | |
1458 """ | |
1459 host_path = AndroidCommands._GetExistingHostOutputPath('purge_ashmem') | |
1460 device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') | |
1461 self.PushIfNeeded(host_path, device_path) | |
1462 if not self.RunShellCommand(device_path, log_result=True): | |
1463 logging.warning('Could not purge ashmem. Measurement might be unstable.') | |
1464 | |
1412 def GetMemoryUsageForPid(self, pid): | 1465 def GetMemoryUsageForPid(self, pid): |
1413 """Returns the memory usage for given pid. | 1466 """Returns the memory usage for given pid. |
1414 | 1467 |
1415 Args: | 1468 Args: |
1416 pid: The pid number of the specific process running on device. | 1469 pid: The pid number of the specific process running on device. |
1417 | 1470 |
1418 Returns: | 1471 Returns: |
1419 A tuple containg: | 1472 A tuple containg: |
1420 [0]: Dict of {metric:usage_kb}, for the process which has specified pid. | 1473 [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, | 1474 The metric keys which may be included are: Size, Rss, Pss, Shared_Clean, |
1422 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, | 1475 Shared_Dirty, Private_Clean, Private_Dirty, Referenced, Swap, |
1423 KernelPageSize, MMUPageSize, Nvidia (tablet only). | 1476 KernelPageSize, MMUPageSize, Nvidia (tablet only). |
1424 [1]: Detailed /proc/[PID]/smaps information. | 1477 [1]: Detailed /proc/[PID]/smaps information. |
1425 """ | 1478 """ |
1426 usage_dict = collections.defaultdict(int) | 1479 usage_dict = collections.defaultdict(int) |
1427 smaps = collections.defaultdict(dict) | 1480 smaps = collections.defaultdict(dict) |
1481 self._PurgeUnpinnedAshmem() | |
tonyg
2013/11/03 05:05:18
Telemetry calls GetMemoryUsageForPid, and before w
Philippe
2013/11/04 14:45:55
Thanks for the instructions Tony. I have just push
| |
1428 current_smap = '' | 1482 current_smap = '' |
1429 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, | 1483 for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, |
1430 log_result=False): | 1484 log_result=False): |
1431 items = line.split() | 1485 items = line.split() |
1432 # See man 5 proc for more details. The format is: | 1486 # See man 5 proc for more details. The format is: |
1433 # address perms offset dev inode pathname | 1487 # address perms offset dev inode pathname |
1434 if len(items) > 5: | 1488 if len(items) > 5: |
1435 current_smap = ' '.join(items[5:]) | 1489 current_smap = ' '.join(items[5:]) |
1436 elif len(items) > 3: | 1490 elif len(items) > 3: |
1437 current_smap = ' '.join(items[3:]) | 1491 current_smap = ' '.join(items[3:]) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1654 """ | 1708 """ |
1655 def __init__(self, output): | 1709 def __init__(self, output): |
1656 self._output = output | 1710 self._output = output |
1657 | 1711 |
1658 def write(self, data): | 1712 def write(self, data): |
1659 data = data.replace('\r\r\n', '\n') | 1713 data = data.replace('\r\r\n', '\n') |
1660 self._output.write(data) | 1714 self._output.write(data) |
1661 | 1715 |
1662 def flush(self): | 1716 def flush(self): |
1663 self._output.flush() | 1717 self._output.flush() |
OLD | NEW |