Skip to content

Instantly share code, notes, and snippets.

@joshthecoder
Created January 8, 2013 03:19
Show Gist options
  • Save joshthecoder/4480892 to your computer and use it in GitHub Desktop.
Save joshthecoder/4480892 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn;
function Log(level, pid, message) {
this.level = level;
this.pid = pid;
this.message = message;
}
process.stdout.write(['time', 'mem_freed', 'allocated', 'size'].join('\t') + '\n');
function onLog(log) {
if (log.pid != process.argv[2]) return;
if (log.message.indexOf('GC_')) return;
var parts = log.message.match(/GC_([A-Z_]*) freed ([0-9]*)K, [0-9]*% free ([0-9]*)K\/([0-9]*)K/);
if (!parts) return;
process.stdout.write(process.hrtime()[0] + '\t');
process.stdout.write(parts.slice(2).join('\t') + '\n');
}
function parseLogLine(line) {
var parts = line.match(/([VDWE])\(([0-9 ]*)\)(.*)/);
if (!parts) return null;
var log = new Log(parts[1], parts[2].trim(), parts[3].trim());
onLog(log);
}
var logcat = spawn('adb', ['logcat', '-v', 'process']);
logcat.stdout.on('data', function(data) {
data.toString().trim().split(/\r?\n/).forEach(parseLogLine);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment