From 6f9dc53652460ec1226e6557308dc0a830a83109 Mon Sep 17 00:00:00 2001 From: "pliard@chromium.org" Date: Tue, 10 Dec 2013 11:27:43 +0000 Subject: [PATCH] Add instance-level in-memory cache for PushIfNeeded(). This speeds up PushIfNeeded() execution times on a same instance of AndroidCommands for repetitive files. This can be achieved by mapping host file paths to their mtime at push time as tonyg@ pointed out although this assumes that the device doesn't modify the files. This is needed to make PurgeUnpinnedAshmem() reasonably fast to execute in Telemetry. This CL decreases by 40 secs the execution time of netsim.top_10 whem memory is measured for each page (and PurgeUnpinnedAshmem() is called before each measurement). BUG=323494,326929 R=bulach@chromium.org, craigdh@chromium.org, tonyg@chromium.org Review URL: https://codereview.chromium.org/97133002 git-svn-id: http://src.chromium.org/svn/trunk/src/build@239757 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- android/pylib/android_commands.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/android/pylib/android_commands.py b/android/pylib/android_commands.py index 95b193bbc..6bb993365 100644 --- a/android/pylib/android_commands.py +++ b/android/pylib/android_commands.py @@ -260,6 +260,7 @@ class AndroidCommands(object): self._util_wrapper = '' self._api_strict_mode = api_strict_mode self._system_properties = system_properties.SystemProperties(self.Adb()) + self._push_if_needed_cache = {} if not self._api_strict_mode: logging.warning( @@ -965,6 +966,15 @@ class AndroidCommands(object): MAX_INDIVIDUAL_PUSHES = 50 assert os.path.exists(host_path), 'Local path not found %s' % host_path + # See if the file on the host changed since the last push (if any) and + # return early if it didn't. Note that this shortcut assumes that the tests + # on the device don't modify the files. + if not os.path.isdir(host_path): + if host_path in self._push_if_needed_cache: + host_path_mtime = self._push_if_needed_cache[host_path] + if host_path_mtime == os.stat(host_path).st_mtime: + return + def GetHostSize(path): return int(cmd_helper.GetCmdOutput(['du', '-sb', path]).split()[0]) @@ -989,6 +999,8 @@ class AndroidCommands(object): while True: output = self._adb.SendCommand(push_command, timeout_time=30 * 60) if _HasAdbPushSucceeded(output): + if not os.path.isdir(host_path): + self._push_if_needed_cache[host] = os.stat(host).st_mtime return if retry < 3: retry += 1