Skip to content

Snapshot meminfo once for Optimize prompt RAM annotations#16

Merged
bryanroscoe merged 1 commit into
mainfrom
fix/optimize-prompt-memory-display
May 8, 2026
Merged

Snapshot meminfo once for Optimize prompt RAM annotations#16
bryanroscoe merged 1 commit into
mainfrom
fix/optimize-prompt-memory-display

Conversation

@bryanroscoe
Copy link
Copy Markdown
Owner

The Optimize prompt sometimes silently dropped the `(using X MB RAM)` annotation even for apps that were demonstrably using significant memory — observed case: Plex showing 845 MB on the Health Report and nothing on the Optimize line ~30 seconds later.

Cause

`Get-AppMemoryUsage` ran a per-app `dumpsys meminfo $Package | grep 'TOTAL PSS'` and matched a single regex against the result. Format drift between Android versions, multi-process apps where the totals row uses a different column layout, and `grep` exit-code-1 propagation through `adb shell` all caused intermittent regex misses → `$null` return → annotation skipped.

The Health Report code already takes a more robust path: one system-wide `dumpsys meminfo` call, parsed client-side from the `Total PSS by process:` section. Plex showed up correctly there.

Change

  • Replace `Get-AppMemoryUsage` with `Get-AppMemoryMap`: one `dumpsys meminfo` call returning `@{ pkg = MB }`. Sums processes that share a base package (e.g. `com.foo` and `com.foo:worker`) so the number matches what the user already saw on the Health Report.
  • `Run-Task` snapshots the map once before the per-app loop (Optimize mode only) and looks up `$memoryMap[$pkg]`.
  • Net effect: fewer ADB roundtrips, consistent numbers between the two screens, no missing annotations.

Verification

  • `make lint` — Syntax OK
  • `make test` — 121 passed / 4 skipped / 0 failed
  • On-device verification not run; the user's Shield was UNAUTHORIZED at fix time, so this hasn't been exercised against real `dumpsys` output. Best effort.

The optimize prompt was silently dropping the "(using X MB RAM)" line
for some apps, including ones that the Health Report had just shown
using significant RAM (Plex at ~845 MB in one observed case).

Cause: Get-AppMemoryUsage ran one `dumpsys meminfo $Package | grep
'TOTAL PSS'` per app, then matched a single regex against the result.
Format drift between Android versions, multi-process apps where TOTAL
PSS sits in a different column layout, and grep/adb-shell exit-code
quirks all caused intermittent miss-then-null returns. The Health
Report avoids this by parsing system-wide `dumpsys meminfo` output
client-side from the "Total PSS by process" section.

Replace the per-app function with Get-AppMemoryMap which:
- Runs `dumpsys meminfo` once per Run-Task invocation
- Parses the same "Total PSS by process" lines the Health Report uses
- Sums all processes that share a base package (e.g. com.foo and
  com.foo:worker) so the displayed total matches what users see on
  the Health Report
- Returns @{} on any failure so callers can lookup safely

Run-Task now snapshots the map once at the top (Optimize mode only)
and looks up `$memoryMap[$pkg]` in the per-app loop. Net effect:
fewer ADB roundtrips, consistent numbers between Health Report and
Optimize prompt, no missing annotations on running apps.
@bryanroscoe bryanroscoe merged commit df70dd5 into main May 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant