Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 1254843002: telemetry: Fix killing the perf profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change GetPids instead. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 a variety of device interactions based on adb. 5 """Provides a variety of device interactions based on adb.
6 6
7 Eventually, this will be based on adb_wrapper. 7 Eventually, this will be based on adb_wrapper.
8 """ 8 """
9 # pylint: disable=unused-argument 9 # pylint: disable=unused-argument
10 10
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 retries: number of retries 729 retries: number of retries
730 730
731 Returns: 731 Returns:
732 The number of processes attempted to kill. 732 The number of processes attempted to kill.
733 733
734 Raises: 734 Raises:
735 CommandFailedError if no process was killed and |quiet| is False. 735 CommandFailedError if no process was killed and |quiet| is False.
736 CommandTimeoutError on timeout. 736 CommandTimeoutError on timeout.
737 DeviceUnreachableError on missing device. 737 DeviceUnreachableError on missing device.
738 """ 738 """
739 pids = self.GetPids(process_name) 739 pids = [pid
740 for pids in self.GetPids(process_name).values()
741 for pid in pids]
perezju 2015/07/27 09:56:32 maybe just me, but I think this would be somewhat
Sami 2015/07/27 11:37:00 Thanks, I went for a little less efficient but com
740 if not pids: 742 if not pids:
741 if quiet: 743 if quiet:
742 return 0 744 return 0
743 else: 745 else:
744 raise device_errors.CommandFailedError( 746 raise device_errors.CommandFailedError(
745 'No process "%s"' % process_name, str(self)) 747 'No process "%s"' % process_name, str(self))
746 748
747 cmd = ['kill', '-%d' % signum] + pids.values() 749 cmd = ['kill', '-%d' % signum] + pids
748 self.RunShellCommand(cmd, as_root=as_root, check_return=True) 750 self.RunShellCommand(cmd, as_root=as_root, check_return=True)
749 751
750 if blocking: 752 if blocking:
751 # TODO(perezu): use timeout_retry.WaitFor 753 # TODO(perezu): use timeout_retry.WaitFor
752 wait_period = 0.1 754 wait_period = 0.1
753 while self.GetPids(process_name): 755 while self.GetPids(process_name):
754 time.sleep(wait_period) 756 time.sleep(wait_period)
755 757
756 return len(pids) 758 return len(pids)
757 759
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 """Returns the PIDs of processes with the given name. 1571 """Returns the PIDs of processes with the given name.
1570 1572
1571 Note that the |process_name| is often the package name. 1573 Note that the |process_name| is often the package name.
1572 1574
1573 Args: 1575 Args:
1574 process_name: A string containing the process name to get the PIDs for. 1576 process_name: A string containing the process name to get the PIDs for.
1575 timeout: timeout in seconds 1577 timeout: timeout in seconds
1576 retries: number of retries 1578 retries: number of retries
1577 1579
1578 Returns: 1580 Returns:
1579 A dict mapping process name to PID for each process that contained the 1581 A dict mapping process name to a list of PIDs for each process that
1580 provided |process_name|. 1582 contained the provided |process_name|.
1581 1583
1582 Raises: 1584 Raises:
1583 CommandTimeoutError on timeout. 1585 CommandTimeoutError on timeout.
1584 DeviceUnreachableError on missing device. 1586 DeviceUnreachableError on missing device.
1585 """ 1587 """
1586 procs_pids = {} 1588 procs_pids = collections.defaultdict(list)
1587 try: 1589 try:
1588 ps_output = self._RunPipedShellCommand( 1590 ps_output = self._RunPipedShellCommand(
1589 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name)) 1591 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name))
1590 except device_errors.AdbShellCommandFailedError as e: 1592 except device_errors.AdbShellCommandFailedError as e:
1591 if e.status and isinstance(e.status, list) and not e.status[0]: 1593 if e.status and isinstance(e.status, list) and not e.status[0]:
1592 # If ps succeeded but grep failed, there were no processes with the 1594 # If ps succeeded but grep failed, there were no processes with the
1593 # given name. 1595 # given name.
1594 return procs_pids 1596 return procs_pids
1595 else: 1597 else:
1596 raise 1598 raise
1597 1599
1598 for line in ps_output: 1600 for line in ps_output:
1599 try: 1601 try:
1600 ps_data = line.split() 1602 ps_data = line.split()
1601 if process_name in ps_data[-1]: 1603 if process_name in ps_data[-1]:
1602 procs_pids[ps_data[-1]] = ps_data[1] 1604 pid, process = ps_data[1], ps_data[-1]
1605 procs_pids[process].append(pid)
1603 except IndexError: 1606 except IndexError:
1604 pass 1607 pass
1605 return procs_pids 1608 return procs_pids
1606 1609
1607 @decorators.WithTimeoutAndRetriesFromInstance() 1610 @decorators.WithTimeoutAndRetriesFromInstance()
1608 def TakeScreenshot(self, host_path=None, timeout=None, retries=None): 1611 def TakeScreenshot(self, host_path=None, timeout=None, retries=None):
1609 """Takes a screenshot of the device. 1612 """Takes a screenshot of the device.
1610 1613
1611 Args: 1614 Args:
1612 host_path: A string containing the path on the host to save the 1615 host_path: A string containing the path on the host to save the
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 def HealthyDevices(cls): 1748 def HealthyDevices(cls):
1746 blacklist = device_blacklist.ReadBlacklist() 1749 blacklist = device_blacklist.ReadBlacklist()
1747 def blacklisted(adb): 1750 def blacklisted(adb):
1748 if adb.GetDeviceSerial() in blacklist: 1751 if adb.GetDeviceSerial() in blacklist:
1749 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) 1752 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial())
1750 return True 1753 return True
1751 return False 1754 return False
1752 1755
1753 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() 1756 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices()
1754 if not blacklisted(adb)] 1757 if not blacklisted(adb)]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698