forked from aalexand/nodejs-profilers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.24 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
const heapProfiler = require('bindings')('sampling_heap_profiler');
const timeProfiler = require('bindings')('time_profiler');
const delay = require('delay');
// heap profiler
function startSamplingHeapProfiler(intervalBytes, stackDepth) {
heapProfiler.startSamplingHeapProfiler(intervalBytes, stackDepth);
}
function stopSamplingHeapProfiler() {
heapProfiler.stopSamplingHeapProfiler();
}
function getAllocationProfile() {
heapProfiler.getAllocationProfile();
}
// time profiler
function setTimeSamplingInterval(intervalMicros) {
timeProfiler.setSamplingInterval(intervalMicros);
}
function startTimeProfiling(runName) {
timeProfiler.startProfiling(runName);
}
function stopTimeProfiling(runName) {
timeProfiler.stopProfiling(runName);
}
async function collectTimeProfile(runName, durationMillis) {
startTimeProfiling(runName);
await delay(durationMillis);
stopTimeProfiling(runName);
}
module.exports = {
startSamplingHeapProfiler: startSamplingHeapProfiler,
stopSamplingHeapProfiler: stopSamplingHeapProfiler,
setTimeSamplingInterval: setTimeSamplingInterval,
startTimeProfiling: startTimeProfiling,
stopTimeProfiling: stopTimeProfiling,
collectTimeProfile: collectTimeProfile,
getAllocationProfile: getAllocationProfile
}