getrusage.js
Version:
getrusage for node precompiled
32 lines (31 loc) • 1.27 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getrusage = exports.RUSAGE_CHILDREN = exports.RUSAGE_SELF = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = require("fs");
const platformArch = `${process.platform}-${process.arch}`;
if (!(0, fs_1.existsSync)(path_1.default.join(__dirname, '..', 'build', `getrusage-${platformArch}.node`))) {
throw Error(`
getrusage.js not support for platform ${platformArch} now!
`);
}
const binding = require(path_1.default.join('..', 'build', `getrusage-${platformArch}`));
exports.RUSAGE_SELF = binding.RUSAGE_SELF;
exports.RUSAGE_CHILDREN = binding.RUSAGE_CHILDREN;
const getrusage = (who) => {
const usage = binding.getrusage(who);
usage.utime = Number(usage.utime.toFixed(6));
usage.stime = Number(usage.stime.toFixed(6));
/**
* due to macOS use BSD getrusage which unit is bytes,
* while linux use GNU getrusage and the unit is kilobytes
*/
if (process.platform === 'darwin') {
usage.maxrss = Math.round(usage.maxrss / 1024);
}
return usage;
};
exports.getrusage = getrusage;