How to retrieve the memory pressure information from macOS

Is there a way to retrieve memory pressure information from macOS using Swift or C/C++?

In Activity Monitor, there’s a chart labeled “Memory Pressure” which provides a discrete metric of RAM usage:

Green = system memory usage is fine Yellow = moderate pressure Red = high memory pressure

I’d like to know how to programmatically access this metric.

Answered by DTS Engineer in 860658022

Check out the Dispatch memory pressure source.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Check out the Dispatch memory pressure source.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

there's some another way to read the current value instead of waiting for events?

Not that I’ve seen. Certainly, the vm.memory_pressure value you mentioned in your other thread is not the droid you’re looking for. If you want to see what that returns you can look at the implementation in Darwin; it’s clearly part of this equation, but it operates at a much lower level. Likewise for things like kern.memorystatus_level.

I think your best option is to assume that memory pressure is normal until you get an event via the Dispatch source.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to retrieve the memory pressure information from macOS
 
 
Q