 Chromium Code Reviews
 Chromium Code Reviews Issue 1254843002:
  telemetry: Fix killing the perf profiler  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1254843002:
  telemetry: Fix killing the perf profiler  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..6bed403a81883f73b4660297e1a1af24628ee2dc 100644 | 
| --- a/build/android/pylib/device/device_utils.py | 
| +++ b/build/android/pylib/device/device_utils.py | 
| @@ -736,7 +736,8 @@ class DeviceUtils(object): | 
| CommandTimeoutError on timeout. | 
| DeviceUnreachableError on missing device. | 
| """ | 
| - pids = self.GetPids(process_name) | 
| + pids = self.GetPids(process_name, multiple_instances=True) | 
| + pids = [pid for instances in pids.values() for pid in instances] | 
| if not pids: | 
| if quiet: | 
| return 0 | 
| @@ -744,13 +745,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.GetPids(process_name, multiple_instances=True): | 
| time.sleep(wait_period) | 
| return len(pids) | 
| @@ -1565,7 +1566,8 @@ class DeviceUtils(object): | 
| return self.GetProp('ro.product.cpu.abi') | 
| @decorators.WithTimeoutAndRetriesFromInstance() | 
| - def GetPids(self, process_name, timeout=None, retries=None): | 
| + def GetPids(self, process_name, timeout=None, retries=None, | 
| + multiple_instances=False): | 
| 
perezju
2015/07/24 14:03:10
I don't think John will like adding an extra optio
 
Sami
2015/07/24 14:36:40
Yeah I wasn't super happy about the flag either. T
 | 
| """Returns the PIDs of processes with the given name. | 
| Note that the |process_name| is often the package name. | 
| @@ -1574,16 +1576,20 @@ class DeviceUtils(object): | 
| process_name: A string containing the process name to get the PIDs for. | 
| timeout: timeout in seconds | 
| retries: number of retries | 
| + multiple_instances: Whether or not multiple instances of the same process | 
| + binary are supported. If True, the returned dict will have a list of | 
| + PIDs for each found process. If False, only a single matching PID | 
| + will be returned for each process. | 
| Returns: | 
| - A dict mapping process name to PID for each process that contained the | 
| - provided |process_name|. | 
| + A dict mapping process name to PID (or list of PIDs) for each process | 
| + that contained the provided |process_name|. | 
| Raises: | 
| CommandTimeoutError on timeout. | 
| DeviceUnreachableError on missing device. | 
| """ | 
| - procs_pids = {} | 
| + procs_pids = collections.defaultdict(list) if multiple_instances else {} | 
| try: | 
| ps_output = self._RunPipedShellCommand( | 
| 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name)) | 
| @@ -1599,7 +1605,11 @@ class DeviceUtils(object): | 
| try: | 
| ps_data = line.split() | 
| if process_name in ps_data[-1]: | 
| - procs_pids[ps_data[-1]] = ps_data[1] | 
| + binary_name = ps_data[-1] | 
| + if multiple_instances: | 
| + procs_pids[binary_name].append(ps_data[1]) | 
| + else: | 
| + procs_pids[binary_name] = ps_data[1] | 
| except IndexError: | 
| pass | 
| return procs_pids |