Created
October 9, 2016 09:17
-
-
Save imyelo/afdfb8e2e41eb8ff26ba578bbb4039cf to your computer and use it in GitHub Desktop.
profiling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ENABLE = 'ENABLE' | |
;(function () { | |
if (process.env.PROFILING_HEAPDUMP === ENABLE) { | |
// heapdump | |
require('heapdump') | |
} | |
if (process.env.PROFILING_MEMORY_STAT === ENABLE) { | |
// usage | |
var colors = require('colors') | |
function beauty (mem) { | |
mem = parseInt(mem / (1024 * 1204), 10) | |
if (mem < 50) { | |
return colors.blue('' + mem) | |
} | |
if (mem > 70 && mem <= 100) { | |
return colors.yellow('' + mem) | |
} | |
if (mem > 100 && mem < 200) { | |
return ('' + mem).yellowBG.black.bold | |
} | |
if (mem > 200) { | |
return ('' + mem).red.bold | |
} | |
return colors.green('' + mem) | |
} | |
setInterval(function () { | |
var usage = process.memoryUsage() | |
console.log( | |
'process %s >> rss: %s mb, heapTotal: %s mb, heapUsed: %s mb', process.pid, beauty(usage.rss), beauty(usage.heapTotal), beauty(usage.heapUsed) | |
) | |
}, 1000 * 3) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment