-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspector.js
35 lines (28 loc) · 996 Bytes
/
inspector.js
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
const inspector = require('inspector');
const fs = require('fs');
const session = new inspector.Session();
inspector.open('localhost', 9229, true);
session.connect();
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
console.log('HeapProfiler.addHeapSnapshotChunk')
fs.appendFileSync('profile.cpuprofile', m.params.chunk + '\n');
});
session.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {
console.log('HeapProfiler.takeHeapSnapshot done:', err, r);
session.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {
console.log('HeapProfiler.takeHeapSnapshot done:', err, r);
// session.disconnect();
});
});
session.post('Profiler.enable', () => {
session.post('Profiler.start', () => {
inspector.console.log('start profiling!');
});
});
setTimeout(() => {
session.post('Profiler.stop', (err, { profile }) => {
if (!err) {
inspector.console.log('end profiling!');
}
});
}, 1000);