summaryrefslogtreecommitdiff
path: root/cppreopts
diff options
context:
space:
mode:
authorWei Wang <wvw@google.com>2016-07-18 11:41:18 -0700
committerWei Wang <wvw@google.com>2016-07-19 10:24:58 -0700
commit757d341496d8c7e69420eb51c82be2d2bc694079 (patch)
tree05696118d8fcd9ac7743ce08fe11759be2d597c3 /cppreopts
parenta63cf1023bd41ed01906c8d30445bb39238937f2 (diff)
downloadextras-757d341496d8c7e69420eb51c82be2d2bc694079.tar.gz
cppreopts: parallel cppreopts to improve performance
Bug: 30118894 Bug: 30189706 Change-Id: I0ed0c69873313a3bfaf2e1ff217da59b0f8929c1
Diffstat (limited to 'cppreopts')
-rw-r--r--cppreopts/cppreopts.sh59
1 files changed, 35 insertions, 24 deletions
diff --git a/cppreopts/cppreopts.sh b/cppreopts/cppreopts.sh
index 4c72e941..87982067 100644
--- a/cppreopts/cppreopts.sh
+++ b/cppreopts/cppreopts.sh
@@ -17,31 +17,13 @@
# 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