-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
36 lines (29 loc) · 815 Bytes
/
Copy pathstart.js
File metadata and controls
36 lines (29 loc) · 815 Bytes
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
34
35
36
'use strict'
const doc = require('..')
// Keep the event loop alive
const noop = () => {}
const interval = setInterval(noop, 1000)
// Initialize a sampler with the default options
const sampler = doc({
autoStart: false
})
// On sample callback
const onSample = () => {
console.table({
cpu: sampler.cpu.usage,
...sampler.memory,
eventLoopDelay: sampler.eventLoopDelay.computed,
eventLoopUtilization: doc.eventLoopUtilizationSupported ? sampler.eventLoopUtilization.utilization : 'Not Supported'
})
}
sampler.on('sample', onSample)
let counter = 0
// In this example, you need t send a SIGINT signal to start the sampler, then another SIGINT signal to exit.
process.on('SIGINT', () => {
if (counter === 0) {
sampler.start()
counter++
return
}
clearInterval(interval)
})