-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.js
36 lines (30 loc) · 839 Bytes
/
main.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
36
"use strict";
var EventEmitter = require('events').EventEmitter;
var GcProfiler = require('./build/Release/GcProfiler');
var main = new EventEmitter();
module.exports = main;
// https://github.com/v8/v8/blob/ca9ec36eb5881f73c1ac1b5a5df710227ad96fae/include/v8.h#L5228
var GC_TYPES = {
1: 'Scavenge',
2: 'MarkSweepCompact',
4: 'IncrementalMarking',
8: 'ProcessWeakCallbacks',
15: 'All'
};
main.GCCallbackFlags = {
kNoGCCallbackFlags: 0,
kGCCallbackFlagCompacted: 1 << 0,
kGCCallbackFlagConstructRetainedObjectInfos: 1 << 1,
kGCCallbackFlagForced: 1 << 2
};
GcProfiler.loadProfiler(function (startTime, ms, type, flags)
{
var info = {
date: new Date(startTime * 1000),
duration: ms,
type: GC_TYPES[type],
forced: !!(flags && main.GCCallbackFlags.kGCCallbackFlagForced),
flags: flags
};
main.emit('gc', info);
});