Chromium Code Reviews| Index: build/android/pylib/device/device_utils.py |
| diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
| index f201ef36b8bf04fa20881109d11c6225f8322bfb..a06491e7f6dd59fff4d4679261368eb04cb50701 100644 |
| --- a/build/android/pylib/device/device_utils.py |
| +++ b/build/android/pylib/device/device_utils.py |
| @@ -736,7 +736,7 @@ class DeviceUtils(object): |
| CommandTimeoutError on timeout. |
| DeviceUnreachableError on missing device. |
| """ |
| - pids = self.GetPids(process_name) |
| + pids = [pid for (_, pid) in self._GetProcessPidPairs(process_name)] |
| if not pids: |
| if quiet: |
| return 0 |
| @@ -744,13 +744,13 @@ class DeviceUtils(object): |
| raise device_errors.CommandFailedError( |
| 'No process "%s"' % process_name, str(self)) |
| - cmd = ['kill', '-%d' % signum] + pids.values() |
| + cmd = ['kill', '-%d' % signum] + pids |
| self.RunShellCommand(cmd, as_root=as_root, check_return=True) |
| if blocking: |
| # TODO(perezu): use timeout_retry.WaitFor |
| wait_period = 0.1 |
| - while self.GetPids(process_name): |
| + while self._GetProcessPidPairs(process_name): |
| time.sleep(wait_period) |
| return len(pids) |
| @@ -1564,26 +1564,23 @@ class DeviceUtils(object): |
| """ |
| return self.GetProp('ro.product.cpu.abi') |
| - @decorators.WithTimeoutAndRetriesFromInstance() |
| - def GetPids(self, process_name, timeout=None, retries=None): |
| - """Returns the PIDs of processes with the given name. |
| + def _GetProcessPidPairs(self, process_name): |
|
jbudorick
2015/07/24 17:10:56
I think I'd prefer making a breaking change to the
|
| + """Returns a list of (process, pid) pairs for all matching processes. |
| Note that the |process_name| is often the package name. |
| Args: |
| process_name: A string containing the process name to get the PIDs for. |
| - timeout: timeout in seconds |
| - retries: number of retries |
| Returns: |
| - A dict mapping process name to PID for each process that contained the |
| + A list with (process, pid) pairs for all processes that contained the |
| provided |process_name|. |
| Raises: |
| CommandTimeoutError on timeout. |
| DeviceUnreachableError on missing device. |
| """ |
| - procs_pids = {} |
| + procs_pids = [] |
| try: |
| ps_output = self._RunPipedShellCommand( |
| 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name)) |
| @@ -1599,12 +1596,37 @@ class DeviceUtils(object): |
| try: |
| ps_data = line.split() |
| if process_name in ps_data[-1]: |
| - procs_pids[ps_data[-1]] = ps_data[1] |
| + pid, process = ps_data[1], ps_data[-1] |
| + procs_pids.append((process, pid)) |
| except IndexError: |
| pass |
| return procs_pids |
| @decorators.WithTimeoutAndRetriesFromInstance() |
| + def GetPids(self, process_name, timeout=None, retries=None): |
| + """Returns the PIDs of processes with the given name. |
| + |
| + Note that the |process_name| is often the package name. |
| + |
| + If there are multiple instances of the same process, only one of the PIDs |
| + will be returned. |
| + |
| + Args: |
| + process_name: A string containing the process name to get the PIDs for. |
| + timeout: timeout in seconds |
| + retries: number of retries |
| + |
| + Returns: |
| + A dict mapping process name to PID for each process that contained the |
| + provided |process_name|. |
| + |
| + Raises: |
| + CommandTimeoutError on timeout. |
| + DeviceUnreachableError on missing device. |
| + """ |
| + return dict(self._GetProcessPidPairs(process_name)) |
| + |
| + @decorators.WithTimeoutAndRetriesFromInstance() |
| def TakeScreenshot(self, host_path=None, timeout=None, retries=None): |
| """Takes a screenshot of the device. |