JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 54261
  • Score
    100M100P100Q157264F
  • License MIT

node bindings for the v8 profiler

Package Exports

  • v8-profiler-next

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (v8-profiler-next) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

v8-profiler-next

npm version Package Quality linux build status windows build status downloads info license

Description

v8-profiler-next provides node bindings for the v8 profiler.

I. Quick Start

  • Compatibility
    • node version: v4.x ~ v12.x
    • platform: mac, linux, windows

take cpu profile

'use strict';
const v8Profiler = require('v8-profiler-next');
const title = '';
// ex. 5 mins cpu profile
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();
// 1. not as stream
snapshot.export(function (error, result) {
    if (error){
        console.error(error);
        return;
    }
    console.log(result);
    snapshot.delete();
});
// 2. as stream
const transform = snapshot.export();
transform.pipe(process.stdout);
transform.on('finish', snapshot.delete.bind(snapshot));

take allocation profile

Attention: If node version <= v8.x, please use sampling heap profiling alone without cpu profiling or taking snapshot.

'use strict';
const v8Profiler = require('v8-profiler-next');
// set a leak array
const arraytest = [];
setInterval(() => {
  arraytest.push(new Array(1e2).fill('*').join());
}, 20);
// start 1min sampling profile
v8Profiler.startSamplingHeapProfiling();
setTimeout(() => {
    // stop and get allocation profile
    const profile = v8Profiler.stopSamplingHeapProfiling();
    // upload shf.heapprofile into chrome dev tools -> Memory -> ALLOCATION PRODILES
  require('fs').writeFileSync('./shf.heapprofile', JSON.stringify(profile));
    console.log(profile);
}, 60 * 1000);

II. License

MIT License

Copyright (c) 2018 team of v8-profiler, hyj1991