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:
irisandClaude Opus 5 committed 2026-08-30 13:09:46 -04:00
1 parent 5d77599f3f
commit e379edfc1b
2 files changed
+36 -4

No files matched your search

+27 -2
View File
@@ -69,8 +69,33 @@ if [ -z "${ANDROID_SERIAL:-}" ]; then
devices | start-server | kill-server | version | help | connect | disconnect) ;;
*)
if [ "$named" = false ]; then
serial=$(avd_serial "$real" "$(project_avd)" || true)
[ -n "$serial" ] && target=(-s "$serial")
avd=$(project_avd)
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
;;
esac
+9 -2
View File
@@ -59,8 +59,15 @@ cmd_list() {
found=false
while IFS=$'\t' read -r serial name; do
found=true
port=${serial#emulator-}
rss=$(ps -eo rss,args | awk -v p="-port $port" '$0 ~ p && $0 ~ /qemu-system/ {print int($1/1024); exit}')
# Matched on the AVD name the emulator was started with, which is
# 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}"
done < <(running_avds "$adb")
[ "$found" = true ] || echo " (none attached)"