Question

enter image description here

I would like to know if there is a command/API call (or set of commands/API calls) that calculates each of (Virtual Memory, File Cache and App Memory) parameters listed in the screen shot above.

Was it helpful?

Solution

You can use vm_stat and sysctl terminal commands. Although there was no straightforward way or documentation on how to extract the new attributes from these commands, we had to do some trial and error till we discovered the relations between parameters in the commands and the attribute we need to calculate.

The Steps are as the following:

  1. Run vm_stat
  2. Run "sysctl hw.memsize" and "sysctl vm.swapusage".
  3. The relationship between Memory usage which appears in Activity Monitor and previous commands are described in How to calc Memory usage in Mavericks programmatically.

Sample output from vm_stat:

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                               24428.
Pages active:                           1039653.
Pages inactive:                          626002.
Pages speculative:                       184530.
Pages throttled:                              0.
Pages wired down:                        156244.
Pages purgeable:                           9429.
"Translation faults":                  14335334.
Pages copy-on-write:                     557301.
Pages zero filled:                      5682527.
Pages reactivated:                           74.
Pages purged:                             52633.
File-backed pages:                       660167.
Anonymous pages:                        1190018.
Pages stored in compressor:                 644.
Pages occupied by compressor:               603.
Decompressions:                              18.
Compressions:                               859.
Pageins:                                 253589.
Pageouts:                                     0.
Swapins:                                      0.
Swapouts:                                     0.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top