All files / lib/internal/perf event_loop_utilization.js

100% Statements 33/33
100% Branches 9/9
100% Functions 1/1
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34104x 104x 104x 104x 104x 104x 31x 31x 31x 31x 6x 6x 25x 30x 4x 4x 4x 4x 21x 21x 21x 21x 30x 16x 16x 5x 5x 5x 5x 5x 31x 104x 104x  
'use strict';
 
const nodeTiming = require('internal/perf/nodetiming');
 
const { now } = require('internal/perf/perf');
 
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;