diff options
Diffstat (limited to 'lib/os.js')
-rw-r--r-- | lib/os.js | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -21,7 +21,7 @@ 'use strict'; -const { pushValToArrayMax, safeGetenv } = internalBinding('util'); +const { safeGetenv } = internalBinding('util'); const constants = internalBinding('constants').os; const { deprecate } = require('internal/util'); const isWindows = process.platform === 'win32'; @@ -82,31 +82,29 @@ const getNetworkInterfacesDepMsg = 'os.getNetworkInterfaces is deprecated. Use os.networkInterfaces instead.'; const avgValues = new Float64Array(3); -const cpuValues = new Float64Array(6 * pushValToArrayMax); function loadavg() { getLoadAvg(avgValues); return [avgValues[0], avgValues[1], avgValues[2]]; } -function addCPUInfo() { - for (var i = 0, c = 0; i < arguments.length; ++i, c += 6) { - this[this.length] = { - model: arguments[i], - speed: cpuValues[c], +function cpus() { + const data = getCPUs(); + const result = []; + for (var i = 0; i < data.length; i += 7) { + result.push({ + model: data[i], + speed: data[i + 1], times: { - user: cpuValues[c + 1], - nice: cpuValues[c + 2], - sys: cpuValues[c + 3], - idle: cpuValues[c + 4], - irq: cpuValues[c + 5] + user: data[i + 2], + nice: data[i + 3], + sys: data[i + 4], + idle: data[i + 5], + irq: data[i + 6] } - }; + }); } -} - -function cpus() { - return getCPUs(addCPUInfo, cpuValues, []); + return result; } function arch() { |