v8-profiler-next
I. Quick Start
Need node v6 +
take cpu profile
'use strict';
const v8Profiler = require('v8-profiler-next');
const title = '';
v8Profiler.startProfiling(title, true);
setTimeout(() => {
const profiler = v8Profiler.stopProfiling(title);
profiler.delete();
console.log(profiler);
}, 5 * 60 * 1000);
take heapsnapshot
'use strict';
const v8Profiler = require('v8-profiler-next');
const snapshot = v8Profiler.takeSnapshot();
snapshot.export(function (error, result) {
if (error){
console.error(error);
return;
}
console.log(result);
snapshot.delete();
});
const transform = snapshot.export();
transform.pipe(process.stdout);
transform.on('finish', snapshot.delete.bind(snapshot));
take allocation profile
'use strict';
const v8Profiler = require('v8-profiler-next');
const arraytest = [];
setInterval(() => {
arraytest.push(new Array(1e2).fill('*').join());
}, 20);
v8Profiler.startSamplingHeapProfiling();
setTimeout(() => {
const profile = v8Profiler.stopSamplingHeapProfiling();
require('fs').writeFileSync('./shf.heapprofile', JSON.stringify(profile));
console.log(profile);
}, 60 * 1000);
II. License
MIT License
Copyright (c) 2017 team of v8-profiler, hyj1991