Created
December 26, 2014 16:18
-
-
Save dweinstein/00888f48c6dbff6387fd to your computer and use it in GitHub Desktop.
procstat for android parser for adbkit
This file contains 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
var _ = require('lodash'); | |
var Promise = require('bluebird'); | |
var readAll = require('adbkit').util.readAll; | |
var RE_COLSEP = /\ +/g; | |
var RE_CPU = /^cpu[0-9]*$/; | |
module.exports = function(client, serial) { | |
return client.shell(serial, "cat /proc/stat") | |
.then(readAll) | |
.then(function (output) { | |
return _.chain(output.toString('utf8').split("\n")) | |
.without('', "\n", ' ') | |
.transform(function (accum, line, key) { | |
var cols = line.split(RE_COLSEP); | |
var type = cols.shift(); | |
if (RE_CPU.test(type)) { | |
accum.push({ | |
type: type, | |
user: +cols[0] || 0, | |
nice: +cols[1] || 0, | |
system: +cols[2] || 0, | |
idle: +cols[3] || 0, | |
iowait: +cols[4] || 0, | |
irq: +cols[5] || 0, | |
softirq: +cols[6] || 0, | |
steal: +cols[7] || 0, | |
guest: +cols[8] || 0, | |
guestnice: +cols[9] || 0, | |
line: {linenum: key, raw: line} | |
}); | |
} | |
}, []).value(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment