Open
Conversation
Uses hs.host.vmStat() to calculate physical memory usage by subtracting reclaimable pages (free, inactive, speculative, purgeable) from total memory. Also reports swap usage via sysctl when swap is active. Note: macOS does not expose the exact memory accounting used by Activity Monitor through public APIs, so this approximation may differ by up to ~1 GB. The discrepancy comes from IOKit/GPU allocations and per-process memory attribution that require private Apple frameworks to capture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
Oh hey there, long time no chat, old friend. I'll give this a review soon, I'll pull out my mac and test it. Thanks for stepping up to this challenge, my solution was going to be to write some objective-c to do it like psutil |
Author
|
Hello,No problem at all.I am afraid I do not have a whole load of programming knowhow, so this was helped by Claude Code. I tried to get it as best as I could but it seems that there are some values we just can't get, as you found. I figured it might be at least helpful to get an approximate value rather than nothing at all.Many thanks,Toby.PS, when you say Long Time No Chat, where might I know you from?Sent from my iPhoneOn 3 Mar 2026, at 17:10, Quin Gillespie ***@***.***> wrote:trypsynth left a comment (trypsynth/recmon#6)
Oh hey there, long time no chat, old friend. I'll give this a review soon, I'll pull out my mac and test it. Thanks for stepping up to this challenge, my solution was going to be to write some objective-c to do it like psutil
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
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.
Summary
ramUsage()function (Ctrl+Shift+2)hs.host.vmStat(), calculating used memory as total minus reclaimable pages (free, inactive, speculative, purgeable)sysctl vm.swapusagewhen swap is active; shows "0 bytes used" otherwiseExample output
Approach and limitations
macOS does not expose the exact memory accounting used by Activity Monitor through public APIs. Activity Monitor uses private per-process APIs (
task_info/phys_footprint) which capture IOKit/GPU memory allocations and per-process compressed memory attribution that aren't visible throughvm_statpage categories.This implementation uses
hs.host.vmStat()(which wraps the kernel'svm_statdata) and defines "used memory" as total physical memory minus pages the system can instantly reclaim (free + inactive + speculative + purgeable). In testing, this tracks within ~1 GB of Activity Monitor's "Memory Used" figure on a 16 GB system.Several alternative approaches were evaluated:
top -l 1PhysMem output: Over-counts by including cached files as "used"Test plan
🤖 Generated with Claude Code