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

Unified Diff: build/android/pylib/device/device_utils.py

Issue 1077173002: [Android] Tune DeviceUtils commands that are prone to large outputs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perezju comments Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/device/device_errors.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3ad767b51951c59f526be272d2dac5e38cb0a2a5..8fc2f6b687624dad758afeb99ba1b2c8e663b824 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -574,6 +574,28 @@ class DeviceUtils(object):
else:
return output
+ def _RunPipedShellCommand(self, script, **kwargs):
+ PIPESTATUS_LEADER = 'PIPESTATUS: '
+
+ script += '; echo "%s${PIPESTATUS[@]}"' % PIPESTATUS_LEADER
+ output = self.RunShellCommand(script, **kwargs)
+ pipestatus_line = output[-1]
+
+ if not pipestatus_line.startswith(PIPESTATUS_LEADER):
+ logging.error('Pipe exit statuses of shell script missing.')
+ raise device_errors.AdbShellCommandFailedError(
+ script, output, status=None,
+ device_serial=self.adb.GetDeviceSerial())
+
+ output = output[:-1]
+ statuses = [
+ int(s) for s in pipestatus_line[len(PIPESTATUS_LEADER):].split()]
+ if any(statuses):
+ raise device_errors.AdbShellCommandFailedError(
+ script, output, status=statuses,
+ device_serial=self.adb.GetDeviceSerial())
+ return output
+
@decorators.WithTimeoutAndRetriesFromInstance()
def KillAll(self, process_name, signum=9, as_root=False, blocking=False,
timeout=None, retries=None):
@@ -595,7 +617,7 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- pids = self._GetPidsImpl(process_name)
+ pids = self.GetPids(process_name)
if not pids:
raise device_errors.CommandFailedError(
'No process "%s"' % process_name, str(self))
@@ -605,7 +627,7 @@ class DeviceUtils(object):
if blocking:
wait_period = 0.1
- while self._GetPidsImpl(process_name):
+ while self.GetPids(process_name):
time.sleep(wait_period)
return len(pids)
@@ -1020,7 +1042,7 @@ class DeviceUtils(object):
else:
logging.warning('Could not determine size of %s.', device_path)
- if size is None or size <= self._MAX_ADB_OUTPUT_LENGTH:
+ if 0 < size <= self._MAX_ADB_OUTPUT_LENGTH:
return _JoinLines(self.RunShellCommand(
['cat', device_path], as_root=as_root, check_return=True))
elif as_root and self.NeedsSU():
@@ -1355,11 +1377,20 @@ class DeviceUtils(object):
CommandTimeoutError on timeout.
DeviceUnreachableError on missing device.
"""
- return self._GetPidsImpl(process_name)
-
- def _GetPidsImpl(self, process_name):
procs_pids = {}
- for line in self.RunShellCommand('ps', check_return=True):
+ try:
+ ps_output = self._RunPipedShellCommand(
+ cmd_helper.SingleQuote('ps | grep -F %s' % process_name),
+ check_return=False)
perezju 2015/04/14 14:13:35 nit: I'm ok with this, but maybe _RunPipedShellCom
jbudorick 2015/04/14 16:56:13 After our offline discussion, I realized that chec
+ except device_errors.AdbShellCommandFailedError as e:
+ if e.status and not e.status[0]:
+ # If ps succeeded but grep failed, there were no processes with the
+ # given name.
+ return procs_pids
+ else:
+ raise
+
+ for line in ps_output:
try:
ps_data = line.split()
if process_name in ps_data[-1]:
@@ -1431,10 +1462,9 @@ class DeviceUtils(object):
'Size', 'Rss', 'Pss', 'Shared_Clean', 'Shared_Dirty', 'Private_Clean',
'Private_Dirty')
- showmap_out = self.RunShellCommand(
- ['showmap', str(pid)], as_root=True, check_return=True)
- if not showmap_out:
- raise device_errors.CommandFailedError('No output from showmap')
+ showmap_out = self._RunPipedShellCommand(
+ 'showmap %d | grep TOTAL' % int(pid),
+ as_root=True, check_return=False)
split_totals = showmap_out[-1].split()
if (not split_totals
« no previous file with comments | « build/android/pylib/device/device_errors.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698