(loopStart, loopIdleTime, util1, util2)
| 20 | } |
| 21 | |
| 22 | function internalEventLoopUtilization(loopStart, loopIdleTime, util1, util2) { |
| 23 | if (loopStart <= 0) { |
| 24 | return { idle: 0, active: 0, utilization: 0 }; |
| 25 | } |
| 26 | |
| 27 | if (util2) { |
| 28 | const idle = util1.idle - util2.idle; |
| 29 | const active = util1.active - util2.active; |
| 30 | return { idle, active, utilization: active / (idle + active) }; |
| 31 | } |
| 32 | |
| 33 | // Using process.hrtime() to get the time from the beginning of the process, |
| 34 | // and offset it by the loopStart time (which is also calculated from the |
| 35 | // beginning of the process). |
| 36 | const now = process.hrtime(); |
| 37 | const active = now[0] * 1e3 + now[1] / 1e6 - loopStart - loopIdleTime; |
| 38 | |
| 39 | if (!util1) { |
| 40 | return { |
| 41 | idle: loopIdleTime, |
| 42 | active, |
| 43 | utilization: active / (loopIdleTime + active), |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | const idleDelta = loopIdleTime - util1.idle; |
| 48 | const activeDelta = active - util1.active; |
| 49 | const utilization = activeDelta / (idleDelta + activeDelta); |
| 50 | return { |
| 51 | idle: idleDelta, |
| 52 | active: activeDelta, |
| 53 | utilization, |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | module.exports = { |
| 58 | internalEventLoopUtilization, |
no outgoing calls
no test coverage detected
searching dependent graphs…