-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cosmetics + speed up ci by removing benchs and adding back package-lock
Avoid using require() in the main function Improve method readability Add back examples Add package-lock back to speed up ci
- Loading branch information
abluchet
committed
Mar 19, 2018
1 parent
4789ae9
commit 8dbad5b
Showing
13 changed files
with
8,067 additions
and
160 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,3 @@ | ||
|
||
# Created by https://www.gitignore.io/api/linux,macos,windows,node | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### macOS ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
node_modules | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
|
||
# End of https://www.gitignore.io/api/linux,macos,windows,node | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,3 @@ os: | |
cache: | ||
directories: | ||
- node_modules | ||
after_success: | ||
- npm run bench |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,3 @@ install: | |
- npm install | ||
test_script: | ||
- npm test | ||
after_test: | ||
- npm run bench |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Example section | ||
|
||
## server.js | ||
|
||
Used to be tested with an HTTP benchmark tool like this one: https://github.com/wg/wrk. | ||
|
||
Start the server, run the tests on `localhost:8020` | ||
|
||
## stresstest.js | ||
|
||
Just start node stresstest.js (but be carefull though...) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var http = require('http') | ||
var pidusage = require('../') | ||
|
||
http.createServer(function (req, res) { | ||
res.writeHead(200) | ||
res.end('hello world\n') | ||
}).listen(8020) | ||
|
||
var interval = setInterval(function () { | ||
pidusage(process.pid, function (err, stat) { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log(stat) | ||
}) | ||
}, 100) | ||
|
||
process.on('exit', function () { | ||
clearInterval(interval) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var pusage = require('../') | ||
|
||
// stress test to compare with top or another tool | ||
console.log('This is my PID: %s', process.pid) | ||
|
||
// classic "drop somewhere"... yeah I'm a lazy guy | ||
var formatBytes = function (bytes, precision) { | ||
var kilobyte = 1024 | ||
var megabyte = kilobyte * 1024 | ||
var gigabyte = megabyte * 1024 | ||
var terabyte = gigabyte * 1024 | ||
|
||
if ((bytes >= 0) && (bytes < kilobyte)) { | ||
return bytes + ' B ' | ||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) { | ||
return (bytes / kilobyte).toFixed(precision) + ' KB ' | ||
} else if ((bytes >= megabyte) && (bytes < gigabyte)) { | ||
return (bytes / megabyte).toFixed(precision) + ' MB ' | ||
} else if ((bytes >= gigabyte) && (bytes < terabyte)) { | ||
return (bytes / gigabyte).toFixed(precision) + ' GB ' | ||
} else if (bytes >= terabyte) { | ||
return (bytes / terabyte).toFixed(precision) + ' TB ' | ||
} else { | ||
return bytes + ' B ' | ||
} | ||
} | ||
|
||
var i = 0 | ||
var bigMemoryLeak = [] | ||
|
||
var stress = function (cb) { | ||
var j = 500 | ||
var arr = [] | ||
|
||
while (j--) { | ||
arr[j] = [] | ||
|
||
for (var k = 0; k < 1000; k++) { | ||
arr[j][k] = {lorem: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum non odio venenatis, pretium ligula nec, fringilla ipsum. Sed a erat et sem blandit dignissim. Pellentesque sollicitudin felis eu mattis porta. Nullam nec nibh nisl. Phasellus convallis vulputate massa vitae fringilla. Etiam facilisis lectus in odio lacinia rutrum. Praesent facilisis vitae urna a suscipit. Aenean lacinia blandit lorem, et ullamcorper metus sagittis faucibus. Nam porta eros nisi, at adipiscing quam varius eu. Vivamus sed sem quis lorem varius posuere ut quis elit.'} | ||
} | ||
} | ||
|
||
bigMemoryLeak.push(arr) | ||
|
||
pusage(process.pid, function (err, stat) { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
console.log('Pcpu: %s', stat.cpu) | ||
console.log('Mem: %s', formatBytes(stat.memory)) | ||
|
||
if (i === 100) { | ||
return cb(null, true) | ||
} else if (stat.memory > 3e8) { | ||
console.log("That's enough right?") | ||
cb(null, true) | ||
} | ||
|
||
i++ | ||
return cb(null, false) | ||
}) | ||
} | ||
|
||
var interval = function () { | ||
return setTimeout(function () { | ||
stress(function (err, stop) { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
if (stop) { | ||
process.exit() | ||
} else { | ||
return interval() | ||
} | ||
}) | ||
}, 400) | ||
} | ||
|
||
setTimeout(function () { | ||
interval() | ||
}, 2000) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
'use strict' | ||
|
||
function pify (fn, arg1) { | ||
return new Promise(function (resolve, reject) { | ||
fn(arg1, function (err, data) { | ||
if (err) return reject(err) | ||
resolve(data) | ||
}) | ||
}) | ||
} | ||
|
||
var stats = require('./lib/stats') | ||
|
||
/** | ||
* Get pid informations. | ||
* @public | ||
* @param {Number|Number[]|String|String[]} pids A pid or a list of pids. | ||
* @param {Object} [options={}] Options object | ||
* @param {Function} [callback=undefined] Called when the statistics are ready. | ||
* If not provided a promise is returned instead. | ||
* @returns {Promise.<Object>} Only when the callback is not provided. | ||
*/ | ||
function pidusage (pids, callback) { | ||
function pidusage (pids, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options | ||
options = {} | ||
} | ||
|
||
if (typeof callback === 'function') { | ||
stats(pids, callback) | ||
stats(pids, options, callback) | ||
return | ||
} | ||
return pify(stats, pids) | ||
|
||
return new Promise(function (resolve, reject) { | ||
stats(pids, options, function (err, data) { | ||
if (err) return reject(err) | ||
resolve(data) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = pidusage |
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
Oops, something went wrong.