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

Side by Side 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: 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 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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 blocking: A boolean indicating whether we should wait until all processes 586 blocking: A boolean indicating whether we should wait until all processes
587 with the given |process_name| are dead. 587 with the given |process_name| are dead.
588 timeout: timeout in seconds 588 timeout: timeout in seconds
589 retries: number of retries 589 retries: number of retries
590 590
591 Raises: 591 Raises:
592 CommandFailedError if no process was killed. 592 CommandFailedError if no process was killed.
593 CommandTimeoutError on timeout. 593 CommandTimeoutError on timeout.
594 DeviceUnreachableError on missing device. 594 DeviceUnreachableError on missing device.
595 """ 595 """
596 pids = self._GetPidsImpl(process_name) 596 pids = self.GetPids(process_name)
597 if not pids: 597 if not pids:
598 raise device_errors.CommandFailedError( 598 raise device_errors.CommandFailedError(
599 'No process "%s"' % process_name, str(self)) 599 'No process "%s"' % process_name, str(self))
600 600
601 cmd = ['kill', '-%d' % signum] + pids.values() 601 cmd = ['kill', '-%d' % signum] + pids.values()
602 self.RunShellCommand(cmd, as_root=as_root, check_return=True) 602 self.RunShellCommand(cmd, as_root=as_root, check_return=True)
603 603
604 if blocking: 604 if blocking:
605 wait_period = 0.1 605 wait_period = 0.1
606 while self._GetPidsImpl(process_name): 606 while self.GetPids(process_name):
607 time.sleep(wait_period) 607 time.sleep(wait_period)
608 608
609 return len(pids) 609 return len(pids)
610 610
611 @decorators.WithTimeoutAndRetriesFromInstance() 611 @decorators.WithTimeoutAndRetriesFromInstance()
612 def StartActivity(self, intent_obj, blocking=False, trace_file_name=None, 612 def StartActivity(self, intent_obj, blocking=False, trace_file_name=None,
613 force_stop=False, timeout=None, retries=None): 613 force_stop=False, timeout=None, retries=None):
614 """Start package's activity on the device. 614 """Start package's activity on the device.
615 615
616 Args: 616 Args:
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 for line in ls_out: 1013 for line in ls_out:
1014 m = self._LS_RE.match(line) 1014 m = self._LS_RE.match(line)
1015 if m and m.group('name') == posixpath.basename(device_path): 1015 if m and m.group('name') == posixpath.basename(device_path):
1016 size = int(m.group('size')) 1016 size = int(m.group('size'))
1017 break 1017 break
1018 else: 1018 else:
1019 logging.warning('Could not determine size of %s.', device_path) 1019 logging.warning('Could not determine size of %s.', device_path)
1020 1020
1021 if size is None or size <= self._MAX_ADB_OUTPUT_LENGTH: 1021 if size is None or size <= self._MAX_ADB_OUTPUT_LENGTH:
1022 return _JoinLines(self.RunShellCommand( 1022 return _JoinLines(self.RunShellCommand(
1023 ['cat', device_path], as_root=as_root, check_return=True)) 1023 ['cat', device_path], as_root=as_root, check_return=True,
1024 large_output=(not bool(size))))
perezju 2015/04/13 09:58:32 I don't think this makes much sense, and introduce
rnephew (Wrong account) 2015/04/13 17:21:04 In at least the /proc/ fs on the device, and proba
jbudorick 2015/04/13 17:44:29 This doesn't make much sense because what it's rea
1024 elif as_root and self.NeedsSU(): 1025 elif as_root and self.NeedsSU():
1025 with device_temp_file.DeviceTempFile(self.adb) as device_temp: 1026 with device_temp_file.DeviceTempFile(self.adb) as device_temp:
1026 self.RunShellCommand(['cp', device_path, device_temp.name], 1027 self.RunShellCommand(['cp', device_path, device_temp.name],
1027 as_root=True, check_return=True) 1028 as_root=True, check_return=True)
1028 return self._ReadFileWithPull(device_temp.name) 1029 return self._ReadFileWithPull(device_temp.name)
1029 else: 1030 else:
1030 return self._ReadFileWithPull(device_path) 1031 return self._ReadFileWithPull(device_path)
1031 1032
1032 def _WriteFileWithPush(self, device_path, contents): 1033 def _WriteFileWithPush(self, device_path, contents):
1033 with tempfile.NamedTemporaryFile() as host_temp: 1034 with tempfile.NamedTemporaryFile() as host_temp:
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 retries: number of retries 1347 retries: number of retries
1347 1348
1348 Returns: 1349 Returns:
1349 A dict mapping process name to PID for each process that contained the 1350 A dict mapping process name to PID for each process that contained the
1350 provided |process_name|. 1351 provided |process_name|.
1351 1352
1352 Raises: 1353 Raises:
1353 CommandTimeoutError on timeout. 1354 CommandTimeoutError on timeout.
1354 DeviceUnreachableError on missing device. 1355 DeviceUnreachableError on missing device.
1355 """ 1356 """
1356 return self._GetPidsImpl(process_name)
1357
1358 def _GetPidsImpl(self, process_name):
1359 procs_pids = {} 1357 procs_pids = {}
1360 for line in self.RunShellCommand('ps', check_return=True): 1358 for line in self.RunShellCommand('ps', check_return=True,
1359 large_output=True):
perezju 2015/04/13 09:58:32 This is precisely one of the things I really think
jbudorick 2015/04/13 17:44:29 Done.
1361 try: 1360 try:
1362 ps_data = line.split() 1361 ps_data = line.split()
1363 if process_name in ps_data[-1]: 1362 if process_name in ps_data[-1]:
1364 procs_pids[ps_data[-1]] = ps_data[1] 1363 procs_pids[ps_data[-1]] = ps_data[1]
1365 except IndexError: 1364 except IndexError:
1366 pass 1365 pass
1367 return procs_pids 1366 return procs_pids
1368 1367
1369 @decorators.WithTimeoutAndRetriesFromInstance() 1368 @decorators.WithTimeoutAndRetriesFromInstance()
1370 def TakeScreenshot(self, host_path=None, timeout=None, retries=None): 1369 def TakeScreenshot(self, host_path=None, timeout=None, retries=None):
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 logging.exception('Error getting memory usage from status') 1422 logging.exception('Error getting memory usage from status')
1424 1423
1425 return result 1424 return result
1426 1425
1427 def _GetMemoryUsageForPidFromSmaps(self, pid): 1426 def _GetMemoryUsageForPidFromSmaps(self, pid):
1428 SMAPS_COLUMNS = ( 1427 SMAPS_COLUMNS = (
1429 'Size', 'Rss', 'Pss', 'Shared_Clean', 'Shared_Dirty', 'Private_Clean', 1428 'Size', 'Rss', 'Pss', 'Shared_Clean', 'Shared_Dirty', 'Private_Clean',
1430 'Private_Dirty') 1429 'Private_Dirty')
1431 1430
1432 showmap_out = self.RunShellCommand( 1431 showmap_out = self.RunShellCommand(
1433 ['showmap', str(pid)], as_root=True, check_return=True) 1432 ['showmap', str(pid)], as_root=True, check_return=True,
1433 large_output=True)
perezju 2015/04/13 09:58:32 How about: 'showmap {{pid}} | grep TOTAL'
jbudorick 2015/04/13 17:44:29 Done.
1434 if not showmap_out: 1434 if not showmap_out:
1435 raise device_errors.CommandFailedError('No output from showmap') 1435 raise device_errors.CommandFailedError('No output from showmap')
1436 1436
1437 split_totals = showmap_out[-1].split() 1437 split_totals = showmap_out[-1].split()
1438 if (not split_totals 1438 if (not split_totals
1439 or len(split_totals) != 9 1439 or len(split_totals) != 9
1440 or split_totals[-1] != 'TOTAL'): 1440 or split_totals[-1] != 'TOTAL'):
1441 raise device_errors.CommandFailedError( 1441 raise device_errors.CommandFailedError(
1442 'Invalid output from showmap: %s' % '\n'.join(showmap_out)) 1442 'Invalid output from showmap: %s' % '\n'.join(showmap_out))
1443 1443
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 """Returns client cache.""" 1531 """Returns client cache."""
1532 if client_name not in self._client_caches: 1532 if client_name not in self._client_caches:
1533 self._client_caches[client_name] = {} 1533 self._client_caches[client_name] = {}
1534 return self._client_caches[client_name] 1534 return self._client_caches[client_name]
1535 1535
1536 def _ClearCache(self): 1536 def _ClearCache(self):
1537 """Clears all caches.""" 1537 """Clears all caches."""
1538 for client in self._client_caches: 1538 for client in self._client_caches:
1539 self._client_caches[client].clear() 1539 self._client_caches[client].clear()
1540 self._cache.clear() 1540 self._cache.clear()
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