diff --git a/benchmark/process/resourceUsage.js b/benchmark/process/resourceUsage.js new file mode 100644 index 00000000000..22e61b095c7 --- /dev/null +++ b/benchmark/process/resourceUsage.js @@ -0,0 +1,16 @@ +'use strict'; + +var common = require('../common.js'); +var bench = common.createBenchmark(main, { + n: [1e6] +}); + +function main(conf) { + var n = +conf.n; + + bench.start(); + for (var i = 0; i < n; i++) { + process.resourceUsage(); + } + bench.end(n); +} diff --git a/doc/api/process.md b/doc/api/process.md index 76e959136b7..98e7f9aad50 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1356,6 +1356,50 @@ In custom builds from non-release versions of the source tree, only the `name` property may be present. The additional properties should not be relied upon to exist. +## process.resourceUsage() + + +* Returns: {Object} containing resource usage measures for the current process + +Note: Windows only provides the following resource usage measures: + +- `userCpuTimeUsedSec` +- `userCpuTimeUsedMs` +- `systemCpuTimeUsedSec` +- `systemCpuTimeUsedMs` +- `blockInputOperations` +- `blockOutputOperations` + +On Windows, all other values are `0`. + +On Linux, some fields may or may not be used/set to non-zero values depending on +the kernel version. See the getrusage(2) man page for more information. + +Example return value: + +```js + { userCpuTimeUsedSec: 0, + userCpuTimeUsedMs: 159729, + systemCpuTimeUsedSec: 0, + systemCpuTimeUsedMs: 30597, + maxResidentSetSize: 20426752, + integralSharedMemorySize: 0, + integralUnsharedDataSize: 0, + integralUnsharedStackSize: 0, + pageReclaims: 3002, + pageFaults: 2250, + swaps: 0, + blockInputOperations: 0, + blockOutputOperations: 0, + ipcMessagesSent: 55, + ipcMessagesReceived: 54, + signalsReceived: 0, + voluntaryContextSwitches: 92, + involuntaryContextSwitches: 374 } +``` + ## process.send(message[, sendHandle[, options]][, callback])