Skip to content

Instantly share code, notes, and snippets.

@ykrkn
Created October 14, 2013 15:24
Show Gist options
  • Save ykrkn/6977391 to your computer and use it in GitHub Desktop.
Save ykrkn/6977391 to your computer and use it in GitHub Desktop.
// run top -p<PID> -b -d 1.0 > tmpfile
// code for prepare below
var fs = require('fs');
var FILESRC;
var PID;
var SEPARATOR=",";
process.argv.forEach(function(val, index, array) {
// console.log(index + ': ' + val);
if(index == 2){ FILESRC = val; }
if(index == 3){ PID = val; }
});
var dst = fs.readFileSync(FILESRC, {encoding:'utf8'}).split("\n").filter(function(it){
if(0 == it.indexOf(PID)) return true;
return false;
}).map(function(it){
var res = it.split(/\s+/);
res[5] = res[5].replace("m", "");
return res.join(SEPARATOR);
});
console.log(dst.join("\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment