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

Side by Side Diff: build/android/pylib/android_commands.py

Issue 97133002: Add instance-level in-memory cache for PushIfNeeded(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 self._device = device 246 self._device = device
247 self._logcat = None 247 self._logcat = None
248 self.logcat_process = None 248 self.logcat_process = None
249 self._logcat_tmpoutfile = None 249 self._logcat_tmpoutfile = None
250 self._pushed_files = [] 250 self._pushed_files = []
251 self._device_utc_offset = None 251 self._device_utc_offset = None
252 self._potential_push_size = 0 252 self._potential_push_size = 0
253 self._actual_push_size = 0 253 self._actual_push_size = 0
254 self._external_storage = '' 254 self._external_storage = ''
255 self._util_wrapper = '' 255 self._util_wrapper = ''
256 self._push_if_needed_cache = {}
256 257
257 def _LogShell(self, cmd): 258 def _LogShell(self, cmd):
258 """Logs the adb shell command.""" 259 """Logs the adb shell command."""
259 if self._device: 260 if self._device:
260 device_repr = self._device[-4:] 261 device_repr = self._device[-4:]
261 else: 262 else:
262 device_repr = '????' 263 device_repr = '????'
263 logging.info('[%s]> %s', device_repr, cmd) 264 logging.info('[%s]> %s', device_repr, cmd)
264 265
265 def Adb(self): 266 def Adb(self):
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 """Pushes |host_path| to |device_path|. 911 """Pushes |host_path| to |device_path|.
911 912
912 Works for files and directories. This method skips copying any paths in 913 Works for files and directories. This method skips copying any paths in
913 |test_data_paths| that already exist on the device with the same hash. 914 |test_data_paths| that already exist on the device with the same hash.
914 915
915 All pushed files can be removed by calling RemovePushedFiles(). 916 All pushed files can be removed by calling RemovePushedFiles().
916 """ 917 """
917 MAX_INDIVIDUAL_PUSHES = 50 918 MAX_INDIVIDUAL_PUSHES = 50
918 assert os.path.exists(host_path), 'Local path not found %s' % host_path 919 assert os.path.exists(host_path), 'Local path not found %s' % host_path
919 920
921 # See if the file on the host changed since the last push (if any) and
922 # return early if it didn't. Note that this shortcut assumes that the tests
923 # on the device don't modify the files.
924 if host_path in self._push_if_needed_cache:
craigdh 2013/12/02 17:09:36 What about when |host_path| is a directory? Updati
Philippe 2013/12/02 17:16:43 Good catch :) I had forgotten that |host_path| cou
craigdh 2013/12/02 18:20:19 It should be pretty easy to do with os.walk(). Do
Philippe 2013/12/03 10:31:31 My main concern was precisely that I have no immed
925 host_path_mtime = self._push_if_needed_cache[host_path]
926 if host_path_mtime == os.stat(host_path).st_mtime:
927 return
928
920 def GetHostSize(path): 929 def GetHostSize(path):
921 return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0]) 930 return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0])
922 931
923 size = GetHostSize(host_path) 932 size = GetHostSize(host_path)
924 self._pushed_files.append(device_path) 933 self._pushed_files.append(device_path)
925 self._potential_push_size += size 934 self._potential_push_size += size
926 935
927 changed_files = self.GetFilesChanged(host_path, device_path) 936 changed_files = self.GetFilesChanged(host_path, device_path)
928 logging.info('Found %d files that need to be pushed to %s', 937 logging.info('Found %d files that need to be pushed to %s',
929 len(changed_files), device_path) 938 len(changed_files), device_path)
930 if not changed_files: 939 if not changed_files:
931 return 940 return
932 941
933 def Push(host, device): 942 def Push(host, device):
934 # NOTE: We can't use adb_interface.Push() because it hardcodes a timeout 943 # NOTE: We can't use adb_interface.Push() because it hardcodes a timeout
935 # of 60 seconds which isn't sufficient for a lot of users of this method. 944 # of 60 seconds which isn't sufficient for a lot of users of this method.
936 push_command = 'push %s %s' % (host, device) 945 push_command = 'push %s %s' % (host, device)
937 self._LogShell(push_command) 946 self._LogShell(push_command)
938 947
939 # Retry push with increasing backoff if the device is busy. 948 # Retry push with increasing backoff if the device is busy.
940 retry = 0 949 retry = 0
941 while True: 950 while True:
942 output = self._adb.SendCommand(push_command, timeout_time=30 * 60) 951 output = self._adb.SendCommand(push_command, timeout_time=30 * 60)
943 if _HasAdbPushSucceeded(output): 952 if _HasAdbPushSucceeded(output):
953 self._push_if_needed_cache[host] = os.stat(host).st_mtime
944 return 954 return
945 if retry < 3: 955 if retry < 3:
946 retry += 1 956 retry += 1
947 wait_time = 5 * retry 957 wait_time = 5 * retry
948 logging.error('Push failed, retrying in %d seconds: %s' % 958 logging.error('Push failed, retrying in %d seconds: %s' %
949 (wait_time, output)) 959 (wait_time, output))
950 time.sleep(wait_time) 960 time.sleep(wait_time)
951 else: 961 else:
952 raise Exception('Push failed: %s' % output) 962 raise Exception('Push failed: %s' % output)
953 963
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 """ 1723 """
1714 def __init__(self, output): 1724 def __init__(self, output):
1715 self._output = output 1725 self._output = output
1716 1726
1717 def write(self, data): 1727 def write(self, data):
1718 data = data.replace('\r\r\n', '\n') 1728 data = data.replace('\r\r\n', '\n')
1719 self._output.write(data) 1729 self._output.write(data)
1720 1730
1721 def flush(self): 1731 def flush(self):
1722 self._output.flush() 1732 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698