arunoda / node-usage

process usage lookup with nodejs
MIT License
389 stars 93 forks source link

Why is the ps memory output getting multiplied by 1024? #44

Open DylanShea opened 9 years ago

DylanShea commented 9 years ago

https://github.com/arunoda/node-usage/blob/master/lib/providers/ps.js#L37

    return {
      memory: parseInt(result[1]) * 1024,
      memoryInfo: {
        rss: parseFloat(result[1]) * 1024,
        vsize: parseFloat(result[2]) * 1024
      },
      cpu: parseFloat(result[3])
    };

From the README.md

{
    memory: 100065280, // in no of bytes
    memoryInfo: {
        rss: 15966208, // resident size memory in bytes
        vsize: 3127906304 // virtual memory size in bytes
    },
    cpu: 10.6 // in percentage
}

The ps output for both linux and osx is in bytes already. Why are the values being returned with a 1024 multiplier?

jportela commented 9 years ago

According to the man pages, they are in units of 1024 bytes, as per #9

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ps.1.html

On OSX this value is OK, for linux I believe it is using another provider: https://github.com/arunoda/node-usage/blob/master/lib/providers/linux.js