├── .appveyor.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package-lock.json ├── package.json └── test.js /.appveyor.yml: -------------------------------------------------------------------------------- 1 | build: off 2 | version: '{build}' 3 | environment: 4 | matrix: 5 | - nodejs_version: '8' 6 | - nodejs_version: '6' 7 | - nodejs_version: '4' 8 | platform: 9 | - x86 10 | - x64 11 | cache: 12 | - node_modules 13 | install: 14 | - ps: Install-Product node $env:nodejs_version 15 | - node --version 16 | - npm --version 17 | - npm install 18 | test_script: 19 | - npm test 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | docs/_api.md 5 | docs/CHANGELOG.md 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '8' 5 | - '6' 6 | - '4' 7 | os: 8 | - linux 9 | - osx 10 | cache: 11 | directories: 12 | - node_modules 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Antoine Bluchet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pidusage-tree 2 | ============= 3 | 4 | Combination of [pidusage](https://github.com/soyuka/pidusage) and [pidtree](https://github.com/simonepri/pidtree) 5 | 6 | ## Installation 7 | 8 | ``` 9 | npm install pidusage-tree --save 10 | ``` 11 | 12 | ## Usage 13 | 14 | ``` 15 | var pidusageTree = require('pidusage-tree') 16 | 17 | pidusageTree(process.pid, function(err, results) { 18 | 19 | }) 20 | 21 | // or as a promise 22 | 23 | var stats = await pidusageTree(process.pid) 24 | ``` 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var pidtree = require('pidtree') 2 | var pidusage = require('pidusage') 3 | 4 | module.exports = function (pid, cb) { 5 | return new Promise(function (resolve, reject) { 6 | pidtree(pid, {root: true}, function (err, pids) { 7 | if (err) { 8 | cb && cb(err) 9 | reject(err) 10 | return 11 | } 12 | 13 | pidusage(pids, function (err, stats) { 14 | if (err) { 15 | cb && cb(err) 16 | reject(err) 17 | return 18 | } 19 | 20 | cb && cb(null, stats) 21 | resolve(stats) 22 | }) 23 | }) 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pidusage-tree", 3 | "version": "2.0.4", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "pidtree": { 8 | "version": "0.3.0", 9 | "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.3.0.tgz", 10 | "integrity": "sha512-9CT4NFlDcosssyg8KVFltgokyKZIFjoBxw8CTGy+5F38Y1eQWrt8tRayiUOXE+zVKQnYu5BR8JjCtvK3BcnBhg==" 11 | }, 12 | "pidusage": { 13 | "version": "2.0.16", 14 | "resolved": "https://registry.npmjs.org/pidusage/-/pidusage-2.0.16.tgz", 15 | "integrity": "sha512-9dhSBxpGvvpyycCukU8CqTqJ+YT8aVZ/AI1/hGWhU5nAAOs0zYBYMyIYBU/grKeCYuTS26TVllIRvf5vAfsgvw==", 16 | "requires": { 17 | "safe-buffer": "^5.1.2" 18 | } 19 | }, 20 | "safe-buffer": { 21 | "version": "5.1.2", 22 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 23 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pidusage-tree", 3 | "version": "2.0.4", 4 | "description": "Process tree usage", 5 | "repository": "https://github.com/soyuka/pidusage-tree.git", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "node test.js" 9 | }, 10 | "keywords": [ 11 | "pidusage", 12 | "process", 13 | "pid" 14 | ], 15 | "author": "soyuka ", 16 | "license": "MIT", 17 | "dependencies": { 18 | "pidtree": "^0.3.0", 19 | "pidusage": "^2.0.16" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var pidusageTree = require('./') 2 | var child = require('child_process').exec 3 | 4 | function getP() { return child("node -e 'while (true);'", function() {}) } 5 | 6 | var processes = [getP(), getP(), getP()] 7 | 8 | function doTree(cb) { 9 | pidusageTree(process.pid, function (err, results) { 10 | console.log(results) 11 | var l = processes.length 12 | processes[l - 1].kill() 13 | processes.length = l - 1 14 | cb() 15 | }) 16 | } 17 | 18 | function loop() { 19 | doTree(function() { 20 | if (processes.length) { 21 | setTimeout(loop, 1000) 22 | } else { 23 | process.exit(0) 24 | } 25 | }) 26 | } 27 | 28 | setTimeout(loop, 1000) 29 | --------------------------------------------------------------------------------