Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Created December 26, 2014 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dweinstein/00888f48c6dbff6387fd to your computer and use it in GitHub Desktop.
Save dweinstein/00888f48c6dbff6387fd to your computer and use it in GitHub Desktop.
procstat for android parser for adbkit
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