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

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: Review comments. Created 5 years, 4 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
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = list(itertools.chain(*self.GetPids(process_name).values()))
740 if not pids: 740 if not pids:
741 if quiet: 741 if quiet:
742 return 0 742 return 0
743 else: 743 else:
744 raise device_errors.CommandFailedError( 744 raise device_errors.CommandFailedError(
745 'No process "%s"' % process_name, str(self)) 745 'No process "%s"' % process_name, str(self))
746 746
747 cmd = ['kill', '-%d' % signum] + pids.values() 747 cmd = ['kill', '-%d' % signum] + pids
748 self.RunShellCommand(cmd, as_root=as_root, check_return=True) 748 self.RunShellCommand(cmd, as_root=as_root, check_return=True)
749 749
750 if blocking: 750 if blocking:
751 # TODO(perezu): use timeout_retry.WaitFor 751 # TODO(perezu): use timeout_retry.WaitFor
752 wait_period = 0.1 752 wait_period = 0.1
753 while self.GetPids(process_name): 753 while self.GetPids(process_name):
754 time.sleep(wait_period) 754 time.sleep(wait_period)
755 755
756 return len(pids) 756 return len(pids)
757 757
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 """Returns the PIDs of processes with the given name. 1577 """Returns the PIDs of processes with the given name.
1578 1578
1579 Note that the |process_name| is often the package name. 1579 Note that the |process_name| is often the package name.
1580 1580
1581 Args: 1581 Args:
1582 process_name: A string containing the process name to get the PIDs for. 1582 process_name: A string containing the process name to get the PIDs for.
1583 timeout: timeout in seconds 1583 timeout: timeout in seconds
1584 retries: number of retries 1584 retries: number of retries
1585 1585
1586 Returns: 1586 Returns:
1587 A dict mapping process name to PID for each process that contained the 1587 A dict mapping process name to a list of PIDs for each process that
1588 provided |process_name|. 1588 contained the provided |process_name|.
1589 1589
1590 Raises: 1590 Raises:
1591 CommandTimeoutError on timeout. 1591 CommandTimeoutError on timeout.
1592 DeviceUnreachableError on missing device. 1592 DeviceUnreachableError on missing device.
1593 """ 1593 """
1594 procs_pids = {} 1594 procs_pids = collections.defaultdict(list)
1595 try: 1595 try:
1596 ps_output = self._RunPipedShellCommand( 1596 ps_output = self._RunPipedShellCommand(
1597 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name)) 1597 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name))
1598 except device_errors.AdbShellCommandFailedError as e: 1598 except device_errors.AdbShellCommandFailedError as e:
1599 if e.status and isinstance(e.status, list) and not e.status[0]: 1599 if e.status and isinstance(e.status, list) and not e.status[0]:
1600 # If ps succeeded but grep failed, there were no processes with the 1600 # If ps succeeded but grep failed, there were no processes with the
1601 # given name. 1601 # given name.
1602 return procs_pids 1602 return procs_pids
1603 else: 1603 else:
1604 raise 1604 raise
1605 1605
1606 for line in ps_output: 1606 for line in ps_output:
1607 try: 1607 try:
1608 ps_data = line.split() 1608 ps_data = line.split()
1609 if process_name in ps_data[-1]: 1609 if process_name in ps_data[-1]:
1610 procs_pids[ps_data[-1]] = ps_data[1] 1610 pid, process = ps_data[1], ps_data[-1]
1611 procs_pids[process].append(pid)
1611 except IndexError: 1612 except IndexError:
1612 pass 1613 pass
1613 return procs_pids 1614 return procs_pids
1614 1615
1615 @decorators.WithTimeoutAndRetriesFromInstance() 1616 @decorators.WithTimeoutAndRetriesFromInstance()
1616 def TakeScreenshot(self, host_path=None, timeout=None, retries=None): 1617 def TakeScreenshot(self, host_path=None, timeout=None, retries=None):
1617 """Takes a screenshot of the device. 1618 """Takes a screenshot of the device.
1618 1619
1619 Args: 1620 Args:
1620 host_path: A string containing the path on the host to save the 1621 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
1753 def HealthyDevices(cls): 1754 def HealthyDevices(cls):
1754 blacklist = device_blacklist.ReadBlacklist() 1755 blacklist = device_blacklist.ReadBlacklist()
1755 def blacklisted(adb): 1756 def blacklisted(adb):
1756 if adb.GetDeviceSerial() in blacklist: 1757 if adb.GetDeviceSerial() in blacklist:
1757 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) 1758 logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial())
1758 return True 1759 return True
1759 return False 1760 return False
1760 1761
1761 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() 1762 return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices()
1762 if not blacklisted(adb)] 1763 if not blacklisted(adb)]
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698