Snapshot meminfo once for Optimize prompt RAM annotations#16
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Verification