How to get the amount of 'Compressed Memory', per process (from Terminal)?
Solution 1:
There's nothing magic about compressed memory. It's something that was added to 10.9 as one last step before the system swaps RAM out to storage. According to John Siracusa, this serves three major functions:
Memory compression is a triple play for Mavericks. It’s a performance win; compressing and decompressing data in RAM is much faster than reading from and writing to disk, even an SSD. It’s an energy win; the less time spent moving data between RAM and disk, the more time the system can spend in its idle state. And finally, it’s a capability win; Mavericks can handle much more demanding workloads than previous versions of OS X before crying uncle.
As to getting at the details from the command line - that may be elusive. The overall compression numbers are easy with a pair of tools:
memory_pressure
vm_stat
I don't think any invocation of ps
will do the trick, but maybe someone can correct that. You can see the implementation details on this thread: vm_compressor_mode (vm.compressor_mode) values for enabled compressed memory in OS X
The best I can get you is to look at all "swapped and/or compressed" memory using the vmmap
command. Basically, before swapping, the memory regions marked for swapping are compressed. If that saves enough space to alleviate the swap algorithm, no swap happens. If not, the compressed regions are swapped to storage.
vmmap -swapped [PID]
You'd have to handle the addition of the regions and I'm not sure if the activity monitor reports all swapped and compressed in the column you mentioned but that's something you might be able to figure out by inspection and/or using Instruments from Xcode to correlate what you see from the command line with activity monitor for some processes.
Solution 2:
It works for me :
VAR=`top -l 1 | awk '/processName/ {print $10 }'`
To get compressed + normal memory
VAR=`top -l 1 | awk '/processName/ {print $8 + $10 }'`