Chromium Code Reviews| Index: build/android/pylib/android_commands.py |
| diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
| index 1741619276ce56042a9a3df6f3b004fed1ebe3ad..a155ee105d3c628f6e7319df78f452097e3489ad 100644 |
| --- a/build/android/pylib/android_commands.py |
| +++ b/build/android/pylib/android_commands.py |
| @@ -1409,6 +1409,60 @@ class AndroidCommands(object): |
| logging.warning('Could not find disk IO stats.') |
| return None |
| + @staticmethod |
| + 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.
|
| + """Returns the most likely correct full path for the given file name. |
| + |
| + Returns: The full path that was found or throws an exception if no path |
| + could be found. |
| + """ |
| + candidate_path = None |
| + self_detected_build_type = None |
| + out_dir = os.path.join( |
| + constants.DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out')) |
| + |
| + if constants.BuildTypeIsSet(): |
| + candidate_path = os.path.join( |
| + out_dir, constants.GetBuildType(), file_name) |
| + else: |
| + release_path = os.path.join(out_dir, 'Release', file_name) |
| + debug_path = os.path.join(out_dir, 'Debug', file_name) |
| + |
| + if os.path.exists(release_path): |
| + if os.path.exists(debug_path): |
| + # Retain the most recent file. |
| + release_path_mtime = time.ctime(os.path.getmtime(release_path)) |
| + debug_path_mtime = time.ctime(os.path.getmtime(debug_path)) |
| + if release_path_mtime > debug_path_mtime: |
| + constants.SetBuildType('Release') |
| + return release_path |
| + constants.SetBuildType('Debug') |
| + return debug_path |
| + candidate_path = release_path |
| + self_detected_build_type = 'Release' |
| + else: |
| + candidate_path = debug_path |
| + self_detected_build_type = 'Debug' |
| + |
| + if not os.path.exists(candidate_path): |
| + raise Exception('File %s does not exist' % candidate_path) |
| + |
| + if self_detected_build_type: |
| + constants.SetBuildType(build_type) |
| + logging.warning('Build type set to ' + self_detected_build_type) |
| + return candidate_path |
| + |
| + def _PurgeUnpinnedAshmem(self): |
| + """Purges the unpinned ashmem memory for the whole system. |
| + |
| + This can be used to make memory measurements more stable in particular. |
| + """ |
| + host_path = AndroidCommands._GetExistingHostOutputPath('purge_ashmem') |
| + device_path = os.path.join(constants.TEST_EXECUTABLE_DIR, 'purge_ashmem') |
| + self.PushIfNeeded(host_path, device_path) |
| + if not self.RunShellCommand(device_path, log_result=True): |
| + logging.warning('Could not purge ashmem. Measurement might be unstable.') |
| + |
| def GetMemoryUsageForPid(self, pid): |
| """Returns the memory usage for given pid. |
| @@ -1425,6 +1479,7 @@ class AndroidCommands(object): |
| """ |
| usage_dict = collections.defaultdict(int) |
| smaps = collections.defaultdict(dict) |
| + self._PurgeUnpinnedAshmem() |
| current_smap = '' |
| for line in self.GetProtectedFileContents('/proc/%s/smaps' % pid, |
| log_result=False): |