Aim at the right emulator, and measure the right process
Two corrections from driving these against a live machine. A bare adb call made from a checkout whose own emulator is down was still handed through to whatever single device was attached -- which is another session's emulator, installing over the app they are looking at and taking their foreground, and looking like it worked. It now refuses and says which serials belong to whom. A physical phone belongs to no checkout and is left alone, which is why this asks for AVD names rather than counting devices. `emu list` was reporting 6 MB for a 3.8 GB emulator: it matched on a -port that is not in the process's command line at all, and the line it did match was the shell running the ps. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5d77599f3f
commit
e379edfc1b
2 files changed
+36
-4
No files matched your search
@@ -69,8 +69,33 @@ if [ -z "${ANDROID_SERIAL:-}" ]; then
|
|||||||
devices | start-server | kill-server | version | help | connect | disconnect) ;;
|
devices | start-server | kill-server | version | help | connect | disconnect) ;;
|
||||||
*)
|
*)
|
||||||
if [ "$named" = false ]; then
|
if [ "$named" = false ]; then
|
||||||
serial=$(avd_serial "$real" "$(project_avd)" || true)
|
avd=$(project_avd)
|
||||||
[ -n "$serial" ] && target=(-s "$serial")
|
serial=$(avd_serial "$real" "$avd" || true)
|
||||||
|
if [ -n "$serial" ]; then
|
||||||
|
target=(-s "$serial")
|
||||||
|
else
|
||||||
|
# This checkout's emulator is not running, and something
|
||||||
|
# else's is. Handing the call through would drive their
|
||||||
|
# device -- installing over the app they are looking at,
|
||||||
|
# or taking their foreground -- and it would look like it
|
||||||
|
# worked. A physical phone is not somebody's checkout and
|
||||||
|
# is left alone, which is why this asks for the AVD name
|
||||||
|
# rather than counting devices.
|
||||||
|
others=$(running_avds "$real" | awk -F'\t' -v mine="$avd" '$2 != mine')
|
||||||
|
if [ -n "$others" ]; then
|
||||||
|
{
|
||||||
|
echo "adb: '$avd' is not running, and these emulators belong to other checkouts:"
|
||||||
|
echo "$others" | while IFS=$'\t' read -r s n; do
|
||||||
|
printf ' %-16s %s\n' "$s" "$n"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
echo " emu up start this checkout's own"
|
||||||
|
echo " adb -s SERIAL ... or say which you meant"
|
||||||
|
echo " ANDROID_SERIAL=SERIAL for a run of them"
|
||||||
|
} >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -59,8 +59,15 @@ cmd_list() {
|
|||||||
found=false
|
found=false
|
||||||
while IFS=$'\t' read -r serial name; do
|
while IFS=$'\t' read -r serial name; do
|
||||||
found=true
|
found=true
|
||||||
port=${serial#emulator-}
|
# Matched on the AVD name the emulator was started with, which is
|
||||||
rss=$(ps -eo rss,args | awk -v p="-port $port" '$0 ~ p && $0 ~ /qemu-system/ {print int($1/1024); exit}')
|
# what its process actually carries -- there is no -port in that
|
||||||
|
# command line, and the console port in the serial does not appear
|
||||||
|
# in it. Filtered on the process *name* rather than on the whole
|
||||||
|
# line, so this cannot match the shell running it: that shell's
|
||||||
|
# command line contains this pattern, and a `ps | awk` that matches
|
||||||
|
# itself reports the size of the shell.
|
||||||
|
rss=$(ps -eo rss=,comm=,args= |
|
||||||
|
awk -v want="-avd $name" '$2 ~ /^qemu-system/ && index($0, want) {print int($1/1024); exit}')
|
||||||
printf ' %-16s %-24s %s\n' "$serial" "$name" "${rss:+$rss MB}"
|
printf ' %-16s %-24s %s\n' "$serial" "$name" "${rss:+$rss MB}"
|
||||||
done < <(running_avds "$adb")
|
done < <(running_avds "$adb")
|
||||||
[ "$found" = true ] || echo " (none attached)"
|
[ "$found" = true ] || echo " (none attached)"
|
||||||
|
|||||||
Reference in new issue
Block a user