mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 13:47:16 +00:00

- Move Performance and InternalPerformance to a new lib/internal/perf/performance.js - Move now() getMilestoneTimestamp() into lib/internal/perf/utils.js - Rename lib/internal/perf/perf.js to lib/internal/perf/performance_entry.js - Refresh time origin at startup (this means the time origins could differ between snapshot building time and snapshot creation time) PR-URL: https://github.com/nodejs/node/pull/38971 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: James M Snell <jasnell@gmail.com>
34 lines
876 B
JavaScript
34 lines
876 B
JavaScript
'use strict';
|
|
|
|
const nodeTiming = require('internal/perf/nodetiming');
|
|
|
|
const { now } = require('internal/perf/utils');
|
|
|
|
function eventLoopUtilization(util1, util2) {
|
|
const ls = nodeTiming.loopStart;
|
|
|
|
if (ls <= 0) {
|
|
return { idle: 0, active: 0, utilization: 0 };
|
|
}
|
|
|
|
if (util2) {
|
|
const idle = util1.idle - util2.idle;
|
|
const active = util1.active - util2.active;
|
|
return { idle, active, utilization: active / (idle + active) };
|
|
}
|
|
|
|
const idle = nodeTiming.idleTime;
|
|
const active = now() - ls - idle;
|
|
|
|
if (!util1) {
|
|
return { idle, active, utilization: active / (idle + active) };
|
|
}
|
|
|
|
const idle_delta = idle - util1.idle;
|
|
const active_delta = active - util1.active;
|
|
const utilization = active_delta / (idle_delta + active_delta);
|
|
return { idle: idle_delta, active: active_delta, utilization };
|
|
}
|
|
|
|
module.exports = eventLoopUtilization;
|