OSDN Git Service

cppreopts: parallel cppreopts to improve performance
authorWei Wang <wvw@google.com>
Mon, 18 Jul 2016 18:41:18 +0000 (11:41 -0700)
committerWei Wang <wvw@google.com>
Tue, 19 Jul 2016 17:24:58 +0000 (10:24 -0700)
Bug: 30118894
Bug: 30189706
Change-Id: I0ed0c69873313a3bfaf2e1ff217da59b0f8929c1

cppreopts/cppreopts.sh

index 4c72e94..8798206 100644 (file)
 # create files with 644 (global read) permissions.
 umask 022
 
-if [ $# -ne 1 ]; then
-  log -p e -t cppreopts "Usage: cppreopts <preopts-mount-point>"
-  exit 1
-fi
-
-# Where the system_b is mounted that contains the preopt'd files
-mountpoint=$1
-
-if ! test -f ${mountpoint}/system-other-odex-marker ; then
-  log -p i -t cppreopts "system_other partition does not appear have been built to contain preopted files."
-  exit 1
-fi
-
-log -p i -t cppreopts "cppreopts from ${mountpoint}"
-# For each odex file.
-find ${mountpoint} -type f -name "*.odex" | while read odex_file; do
-  real_odex_name=${odex_file/${mountpoint}/\/system}
-  dest_name=$(preopt2cachename ${real_odex_name})
+# Helper function to copy files
+function do_copy() {
+  odex_file=$1
+  dest_name=$2
   # Move to a temporary file so we can do a rename and have the preopted file
   # appear atomically in the filesystem.
   temp_dest_name=${dest_name}.tmp
-  if ! test $? -eq 0 ; then
-    log -p i -t cppreopts "Unable to figure out destination for ${odex_file}"
-    continue
-  fi
   if ! cp ${odex_file} ${temp_dest_name} ; then
     log -p w -t cppreopts "Unable to copy odex file ${odex_file} to ${temp_dest_name}!"
   else
@@ -53,6 +35,35 @@ find ${mountpoint} -type f -name "*.odex" | while read odex_file; do
       log -p i -t cppreopts "Renamed temporary odex file from ${temp_dest_name} to ${dest_name}"
     fi
   fi
-done
+}
+
+if [ $# -eq 1 ]; then
+  # Where the system_b is mounted that contains the preopt'd files
+  mountpoint=$1
+
+  if ! test -f ${mountpoint}/system-other-odex-marker ; then
+    log -p i -t cppreopts "system_other partition does not appear have been built to contain preopted files."
+    exit 1
+  fi
 
-exit 0
+  log -p i -t cppreopts "cppreopts from ${mountpoint}"
+  # For each odex file do the copy task
+  # NOTE: this implementation will break in any path with spaces to favor
+  # background copy tasks
+  for odex_file in $(find ${mountpoint} -type f -name "*.odex"); do
+    real_odex_name=${odex_file/${mountpoint}/\/system}
+    dest_name=$(preopt2cachename ${real_odex_name})
+    if ! test $? -eq 0 ; then
+      log -p i -t cppreopts "Unable to figure out destination for ${odex_file}"
+      continue
+    fi
+    # Copy files in background to speed things up
+    do_copy ${odex_file} ${dest_name} &
+  done
+  # Wait for jobs to finish
+  wait
+  exit 0
+else
+  log -p e -t cppreopts "Usage: cppreopts <preopts-mount-point>"
+  exit 1
+fi