Dopo un po 'di frustrazione, credo di avere la risposta.
vm_stat è solo una parte dell'immagine, abbiamo anche bisogno di:
$ sysctl vm.page_pageable_internal_count
App Memory è quindi:
page_pageable_internal_count - Pages Purgable (from vm_stat)
Questo script Python ottiene tutto vm_stat, bit di sysctl, stampa tutto in modo molto carino. Le ultime 6 righe danno gli stessi numeri di Activity Monitor.
#!/usr/bin/python
import sys
import subprocess
import re
f = 0.00000000093132257 # 1/(1024*1024*1024) Converts bytes to GB
# vm_stat (get all results)
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0]
vmLines = vm.split('\n')
sep = re.compile(':[\s]+')
vmStats = {}
for row in range(1,len(vmLines)-2):
rowText = vmLines[row].strip()
rowElements = sep.split(rowText)
vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096
# sysctl (just get a couple of numbers)
sy = subprocess.Popen(['sysctl','vm.page_pageable_internal_count'], stdout=subprocess.PIPE).communicate()[0]
p1 = sy.find(':')
page_pageable_internal_count = float(sy[p1+1:50]) * 4096
sy = subprocess.Popen(['sysctl','vm.swapusage'], stdout=subprocess.PIPE).communicate()[0]
p1 = sy.find('used')
p2 = sy.find('M',p1)
swapUsed = float(sy[p1+7:p2]) # This is Mbytes
appMemory = page_pageable_internal_count - vmStats["Pages purgeable"]
print 'Wired Memory:\t\t%9.3f GB' % ( vmStats["Pages wired down"] * f )
print 'Active Memory:\t\t%9.3f GB' % ( vmStats["Pages active"] * f )
print 'Inactive Memory:\t%9.3f GB' % ( vmStats["Pages inactive"] * f )
print 'Speculative:\t\t%9.3f GB' % ( vmStats["Pages speculative"] * f )
print 'Throttled:\t\t%9.3f GB' % ( vmStats["Pages throttled"] * f )
print 'Free Memory:\t\t%9.3f GB' % ( vmStats["Pages free"] * f )
print 'Compressor:\t\t%9.3f GB' % ( vmStats["Pages occupied by compressor"] * f )
print 'Total:\t\t\t%9.3f GB' % ( (vmStats["Pages free"] + vmStats["Pages wired down"] + vmStats["Pages active"] + vmStats["Pages inactive"] + vmStats["Pages speculative"] + vmStats["Pages throttled"] + vmStats["Pages occupied by compressor"]) * f )
print ''
print 'Compressed:\t\t%9.3f GB' % ( vmStats["Pages stored in compressor"] * f )
print 'Purgeable:\t\t%9.3f GB' % ( vmStats["Pages purgeable"] * f )
print 'File-backed:\t\t%9.3f GB' % ( vmStats["File-backed pages"] * f )
print 'Anonymous:\t\t%9.3f GB' % ( vmStats["Anonymous pages"] * f )
print ''
print 'Pageable Internal:\t%9.3f GB' % (page_pageable_internal_count * f)
print ''
print 'App Memory:\t\t%9.3f GB' % ( appMemory * f )
print 'Wired Memory:\t\t%9.3f GB' % ( vmStats["Pages wired down"] * f )
print 'Compressor:\t\t%9.3f GB %9.3f MB' % ( vmStats["Pages occupied by compressor"] * f ,vmStats["Pages occupied by compressor"] * 1/(1024*1024) )
print 'Memory Used:\t\t%9.3f GB' % ( (appMemory + vmStats["Pages wired down"] + vmStats["Pages occupied by compressor"] ) * f )
print 'Cached Files:\t\t%9.3f GB' % ( (vmStats["File-backed pages"] + vmStats["Pages purgeable"]) * f )
print 'Swap Used:\t\t%9.3f GB %9.3f MB' % ( swapUsed * 0.0009765625, swapUsed )
sys.exit(0);
I fattori di fondere strano sono perché un MB è 1024 * 1024 e un GB è 1024 * 1024 * 1024. Un GB non è 1000 volte un MB!
Ho avuto la maggior parte di questo script per qualche tempo. L'ultimo pezzo del puzzle è stato derivato da link