Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

android-performance

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

android-performance - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

13

index.js

@@ -1,16 +0,3 @@

/* ================================================================
* android-performance by xdf(xudafeng[at]126.com)
*
* first created at : Thu Jun 30 2016 09:58:47 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';
module.exports = require('./lib/android-performance');

216

lib/android-performance.js

@@ -1,14 +0,1 @@

/* ================================================================
* android-performance by xdf(xudafeng[at]126.com)
*
* first created at : Thu Jun 30 2016 09:58:47 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';

@@ -54,3 +41,2 @@

var cb = args[0];
promise.then(data => {

@@ -71,6 +57,12 @@ cb.call(this, null, data);

var cmd = `dumpsys meminfo ${name}`;
var parser = function(data) {
return _.find(data.split('\n'), function(line) {
return _.startsWith(line.trim(), 'TOTAL ');
}).trim().split(/\s+/g);
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
resolve(data);
var sec = parser(data);
resolve(sec[1]);
}).catch(err => {

@@ -83,5 +75,38 @@ reject(`exec ${cmd} error with: ${err}`);

var cb = args[1];
promise.then(data => {
var sec = parser(data);
cb.call(this, null, sec[1]);
}).catch(err => {
cb.call(this, err);
});
} else {
return promise;
}
};
AndroidPerformance.prototype.getPid = function() {
var args = Array.prototype.slice.call(arguments);
var name = args[0];
var cmd = `ps`;
var parser = function(data) {
return _.find(data.split('\n'), function(line) {
return line.includes(name);
}).trim().split(/\s+/g);
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
var sec = parser(data);
resolve(sec[1]);
}).catch(err => {
reject(`exec ${cmd} error with: ${err}`);
});
});
if (args.length > 1) {
var cb = args[1];
promise.then(data => {
cb.call(this, null, data);
var sec = parser(data);
cb.call(this, null, sec[1]);
}).catch(err => {

@@ -95,2 +120,161 @@ cb.call(this, err);

AndroidPerformance.prototype.getThreadCountByPid = function() {
var args = Array.prototype.slice.call(arguments);
var pid = args[0];
var cmd = `cat /proc/${pid}/status`;
var parser = function(data) {
return _.find(data.split('\n'), function(line) {
return line.includes('Threads');
}).trim().split(/\s+/g);
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
var sec = parser(data);
resolve(sec[1]);
}).catch(err => {
reject(`exec ${cmd} error with: ${err}`);
});
});
if (args.length > 1) {
var cb = args[1];
promise.then(data => {
var sec = parser(data);
cb.call(this, null, sec[1]);
}).catch(err => {
cb.call(this, err);
});
} else {
return promise;
}
};
AndroidPerformance.prototype.getUidByPid = function() {
var args = Array.prototype.slice.call(arguments);
var pid = args[0];
var cmd = `cat /proc/${pid}/status`;
var parser = function(data) {
return _.find(data.split('\n'), function(line) {
return line.includes('Uid');
}).trim().split(/\s+/g);
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
var sec = parser(data);
resolve(sec[1]);
}).catch(err => {
reject(`exec ${cmd} error with: ${err}`);
});
});
if (args.length > 1) {
var cb = args[1];
promise.then(data => {
var sec = parser(data);
cb.call(this, null, sec[1]);
}).catch(err => {
cb.call(this, err);
});
} else {
return promise;
}
};
AndroidPerformance.prototype.getTrafficByUid = function() {
var args = Array.prototype.slice.call(arguments);
var uid = args[0];
var cmd = `cat /proc/net/xt_qtaguid/stats`;
var parser = function(data) {
var res = {
wifi: {
rcv: 0,
snd: 0
},
mobile: {
rcv: 0,
snd: 0
}
};
var uidx, typex, rcvx, sndx;
_.forEach(data.split('\n'), function(line) {
var token = line.trim().split(/\s+/g);
if (token[0] === 'idx') {
uidx = _.indexOf(token, 'uid_tag_int');
typex = _.indexOf(token, 'iface');
rcvx = _.indexOf(token, 'rx_bytes');
sndx = _.indexOf(token, 'tx_bytes');
} else if (token[uidx] === uid) {
if (token[typex].includes('wlan')) {
res.wifi.rcv += token[rcvx];
res.wifi.snd += token[sndx];
} else {
res.mobile.rcv += token[rcvx];
res.mobile.rcv += token[sndx];
}
}
});
return res;
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
var res = parser(data);
resolve(res);
}).catch(err => {
reject(`exec ${cmd} error with: ${err}`);
});
});
if (args.length > 1) {
var cb = args[1];
promise.then(data => {
var res = parser(data);
cb.call(this, null, res);
}).catch(err => {
cb.call(this, err);
});
} else {
return promise;
}
};
AndroidPerformance.prototype.getCPUByPid = function() {
var args = Array.prototype.slice.call(arguments);
var pid = args[0];
var cmd = `top -n 1`;
var parser = function(data) {
return _.find(data.split('\n'), function(line) {
return line.includes(pid);
}).trim().split(/\s+/g);
};
var promise = new Promise((resolve, reject) => {
this.adb.shell(cmd).then(data => {
var sec = parser(data);
resolve(sec[2]);
}).catch(err => {
reject(`exec ${cmd} error with: ${err}`);
});
});
if (args.length > 1) {
var cb = args[1];
promise.then(data => {
var sec = parser(data);
cb.call(this, null, sec[2]);
}).catch(err => {
cb.call(this, err);
});
} else {
return promise;
}
};
module.exports = AndroidPerformance;

@@ -1,14 +0,1 @@

/* ================================================================
* android-performance by xdf(xudafeng[at]126.com)
*
* first created at : Thu Jun 30 2016 09:58:47 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';

@@ -15,0 +2,0 @@

{
"name": "android-performance",
"version": "0.1.0",
"version": "1.0.0",
"description": "Node.js wrapper to android performance with adb",

@@ -15,3 +15,3 @@ "keywords": [

"type": "git",
"url": "git://github.com/xudafeng/android-performance.git"
"url": "git://github.com/macacajs/android-performance.git"
},

@@ -37,7 +37,4 @@ "dependencies": {

],
"homepage": "https://github.com/xudafeng/android-performance",
"author": "xudafeng",
"email": "xudafeng@126.com",
"blog": "http://xdf.me",
"homepage": "https://github.com/macacajs/android-performance",
"license": "MIT"
}

@@ -11,6 +11,6 @@ # android-performance

[npm-url]: https://npmjs.org/package/android-performance
[travis-image]: https://img.shields.io/travis/xudafeng/android-performance.svg?style=flat-square
[travis-url]: https://travis-ci.org/xudafeng/android-performance
[coveralls-image]: https://img.shields.io/coveralls/xudafeng/android-performance.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/xudafeng/android-performance?branch=master
[travis-image]: https://img.shields.io/travis/macacajs/android-performance.svg?style=flat-square
[travis-url]: https://travis-ci.org/macacajs/android-performance
[coveralls-image]: https://img.shields.io/coveralls/macacajs/android-performance.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/macacajs/android-performance?branch=master
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square

@@ -32,3 +32,1 @@ [node-url]: http://nodejs.org/download/

The MIT License (MIT)
Copyright (c) 2015 xdf

@@ -1,14 +0,1 @@

/* ================================================================
* android-performance by xdf(xudafeng[at]126.com)
*
* first created at : Thu Jun 30 2016 09:58:47 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';

@@ -36,3 +23,3 @@

it('should get meminfo success', function *() {
it('should get meminfo success', function*() {
var perf = new AndroidPerformance();

@@ -43,2 +30,42 @@ yield perf.initDevice();

});
it('should get pid success', function*() {
var perf = new AndroidPerformance();
yield perf.initDevice();
var res = yield perf.getPid('com.android.settings');
console.log(res);
});
it('should get threadcount success', function*() {
var perf = new AndroidPerformance();
yield perf.initDevice();
var pid = yield perf.getPid('com.android.settings');
var res = yield perf.getThreadCountByPid(pid);
console.log(res);
});
it('should get uid success', function*() {
var perf = new AndroidPerformance();
yield perf.initDevice();
var pid = yield perf.getPid('com.android.settings');
var uid = yield perf.getUidByPid(pid);
console.log(uid);
});
it('should get traffic success', function*() {
var perf = new AndroidPerformance();
yield perf.initDevice();
var pid = yield perf.getPid('com.android.settings');
var uid = yield perf.getUidByPid(pid);
var res = yield perf.getTrafficByUid(uid);
console.log(res);
});
it('should get CPU success', function*() {
var perf = new AndroidPerformance();
yield perf.initDevice();
var pid = yield perf.getPid('com.android.settings');
var res = yield perf.getCPUByPid(pid);
console.log(res);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc