-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcFlags.js
More file actions
41 lines (35 loc) · 1.01 KB
/
Copy pathgcFlags.js
File metadata and controls
41 lines (35 loc) · 1.01 KB
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
37
38
39
40
41
'use strict'
const doc = require('..')
if (!doc.gcFlagsSupported) {
console.error('GC Flags are not supported on your Node.js version')
process.exit(1)
}
// Keep the event loop alive
const noop = () => {}
setInterval(noop, 1000)
// Initialize a sampler with the default options
const sampler = doc({
gcOptions: {
aggregate: true,
flags: true
},
collect: {
gc: true
}
})
// 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',
gc: sampler.gc.pause.mean,
'gc(99)': sampler.gc.pause.getPercentile(99),
'gc.minor': sampler.gc.minor.mean,
'gc.minor(99)': sampler.gc.minor.getPercentile(99),
'gc.minor.flags.no': sampler.gc.minor.flags.no.mean,
'gc.minor.flags.no(99)': sampler.gc.minor.flags.no.getPercentile(99)
})
}
sampler.on('sample', onSample)