Speed up chroot process lookup in ART Buildbot tear-down script.
Instead of executing "adb shell readlink" on every file matching the
search pattern ("/proc/*/root") to find symbolic links to the chroot
dir, filter the output of "adb shell ls -ld" and iterate on that
sublist directly. Reduces the script execution time from 53s to 3s in
local testing.
Test: Rely on the ART Buildbot
Bug: 34729697
Change-Id: Ib2ce38b37cdcec43c2ea966c89d13de794e91380
diff --git a/tools/teardown-buildbot-device.sh b/tools/teardown-buildbot-device.sh
index be68b9f..6634fb4 100755
--- a/tools/teardown-buildbot-device.sh
+++ b/tools/teardown-buildbot-device.sh
@@ -42,15 +42,14 @@
# that started this process.
for_all_chroot_process() {
local action=$1
- for link in $(adb shell ls -d "/proc/*/root"); do
- local root=$(adb shell readlink "$link")
- if [[ "x$root" = "x$ART_TEST_CHROOT" ]]; then
- local dir=$(dirname "$link")
- local pid=$(basename "$dir")
- local cmdline=$(adb shell cat "$dir"/cmdline | tr '\000' ' ')
- $action "$pid" "$cmdline"
- fi
- done
+ adb shell ls -ld "/proc/*/root" \
+ | sed -n -e "s,^.* \\(/proc/.*/root\\) -> $ART_TEST_CHROOT\$,\\1,p" \
+ | while read link; do
+ local dir=$(dirname "$link")
+ local pid=$(basename "$dir")
+ local cmdline=$(adb shell cat "$dir"/cmdline | tr '\000' ' ')
+ $action "$pid" "$cmdline"
+ done
}
# display_process PID CMDLINE