{"bugs":{"url":"https://github.com/hyj1991/v8-profiler-next/issues"},"dist":{"shasum":"10b6ad886e7d0e02d61060b2fcb8c95ced50b951","tarball":"https://registry.npmjs.org/v8-profiler-next/-/v8-profiler-next-1.8.0.tgz","fileCount":45,"integrity":"sha512-IHuu+PbrGubYiwRTJ25tQ3NQg88VzVjt8yuMQtUG4K/OBqdIoQHwyQfxR19i3nlUWng3QXhmtGcKFL0URv69vw==","signatures":[{"sig":"MEUCIDpMaQm7YIbz+h9e0BFcaZfa2Wo657QqvNgo2nP52hTUAiEAjcO5Cf6Lw9TU9AHKW9XZI493+Pc+zw+q5fP21euAamQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":91104,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJimsmFACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqK6g/7B21Fy0zq8cDPJKKORf6WQADpV+SOJOBj0xDwF/G5nC9Wnqur\r\nupDarox7zwJArYJ/tDIX6dL4poAQta12VRbB5+8+oGAlsyaZdsemHWeGzMH0\r\nxGhRHTIWaYHSCAEisRLx5YiGcyHHnuljY+VNzW+6x3luwfzJWBKMmX+asP4l\r\n9EUk5QKWbjPWRLmbBTFMX2zMIHxaFx1nPe6y7NjuMCG/KNMBTfxe53ZKLFbm\r\nZbF/6CSBzrZKQpLto6wZJvpzmvkLOQnuKfLt8Z/we6s9VzeVpCHo7DLFAgF+\r\neoK1SYzggAb1UGX5O2Q/t28Rvnm2SMrKW/FP4NZMKET/tsGvR9XZAqOcQj8D\r\nsfY2VVSdA9P9cEbXvCHYbkLnLYBcHCVr2Q9uvozHbRs8mbDyMEKSb+pr3aYO\r\n9gb8T0QE4nkAz9EJdpTH40eiG+jfliZfgZWJe530Q6vqim1JQVrirDI/KfXD\r\n0BKCR7AEhpQFvCULS3SZfa/yPD5tDBahj097HOghn/S0jOmT5Q7ReSvTltF7\r\nPzSd1W9LC0uWetsPw5NmR2WEENZrMcCfDK9gnpOjsJTdeRiFGnGoTPjzsLs3\r\n2NDw+yPk9x6JkaZgs9CJm+MbKD142S1JddhUcaYdDOp3XXCXzExz6GWVOMRh\r\nykCm/GfVuVshc7NNny958hQU6XTjv7XxOpQ=\r\n=W85J\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dispatch.js","name":"v8-profiler-next","author":{"name":"https://github.com/hyj1991"},"binary":{"host":"https://github.com/hyj1991/v8-profiler-next/releases/download","module_name":"profiler","module_path":"./build/binding/{configuration}/{node_abi}-{platform}-{arch}/","remote_path":"./v{version}/","package_name":"{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz"},"readme":"# v8-profiler-next\n\n[![npm version](https://img.shields.io/npm/v/v8-profiler-next/latest.svg)](https://www.npmjs.com/package/v8-profiler-next)\n[![Package Quality](http://npm.packagequality.com/shield/v8-profiler-next.svg)](http://packagequality.com/#?package=v8-profiler-next)\n[![Linux/osx build status](https://github.com/hyj1991/v8-profiler-next/workflows/Continuous%20integration/badge.svg?branch=master)](https://github.com/hyj1991/v8-profiler-next/actions?query=branch%3Amaster)\n[![windows build status](https://ci.appveyor.com/api/projects/status/vp54r2t137iirntf?svg=true)](https://ci.appveyor.com/project/hyj1991/v8-profiler-next)\n[![downloads info](https://img.shields.io/npm/dm/v8-profiler-next.svg)](https://www.npmjs.com/package/v8-profiler-next)\n[![license](https://img.shields.io/npm/l/v8-profiler-next.svg)](LICENSE)\n\n## Description\n\nv8-profiler-next provides [node](http://github.com/nodejs/node) bindings for the v8 profiler.\n\n## I. Quick Start\n\n* **Compatibility**\n  * **node version:** v4.x ~ v18.x\n  * **platform:** mac, linux, windows\n\nThis module can also be used in `worker_threads`.\n\n### take cpu profile\n\n```js\n'use strict';\nconst fs = require('fs');\nconst v8Profiler = require('v8-profiler-next');\nconst title = 'good-name';\n\n// set generateType 1 to generate new format for cpuprofile\n// to be compatible with cpuprofile parsing in vscode.\nv8Profiler.setGenerateType(1);\n\n// ex. 5 mins cpu profile\nv8Profiler.startProfiling(title, true);\nsetTimeout(() => {\n  const profile = v8Profiler.stopProfiling(title);\n  profile.export(function (error, result) {\n    // if it doesn't have the extension .cpuprofile then\n    // chrome's profiler tool won't like it.\n    // examine the profile:\n    //   Navigate to chrome://inspect\n    //   Click Open dedicated DevTools for Node\n    //   Select the profiler tab\n    //   Load your file\n    fs.writeFileSync(`${title}.cpuprofile`, result);\n    profile.delete();\n  });\n}, 5 * 60 * 1000);\n```\n\nGet `.cpuprofile` in `worker_threads`:\n\n```js\n'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\nconst v8Profiler = require('v8-profiler-next');\nconst workerThreads = require('worker_threads');\n\nv8Profiler.setGenerateType(1);\n\nif (workerThreads.isMainThread) {\n  const w = new workerThreads.Worker(__filename, {\n    env: process.env,\n  });\n  v8Profiler.startProfiling('main', true);\n  w.once('exit', code => {\n    // create cpu profile in main thread\n    const profile = v8Profiler.stopProfiling('main');\n    const mainProfile = path.join(__dirname, 'main.cpuprofile');\n    fs.existsSync(mainProfile) && fs.unlinkSync(mainProfile);\n    fs.writeFileSync(mainProfile, JSON.stringify(profile));\n  });\n} else {\n  v8Profiler.startProfiling('worker_threads', true);\n  // create cpu profile in worker_threads\n  const start = Date.now();\n  while (Date.now() - start < 2000) { }\n  const profile = v8Profiler.stopProfiling('worker_threads');\n  const workerProfile = path.join(__dirname, 'worker_threads.cpuprofile');\n  fs.existsSync(workerProfile) && fs.unlinkSync(workerProfile);\n  fs.writeFileSync(workerProfile, JSON.stringify(profile));\n}\n```\n\n### take heapsnapshot\n\n```js\n'use strict';\nconst v8Profiler = require('v8-profiler-next');\nconst snapshot = v8Profiler.takeSnapshot();\n// 1. not as stream\nsnapshot.export(function (error, result) {\n\tif (error){\n\t\tconsole.error(error);\n\t\treturn;\n\t}\n\tconsole.log(result);\n\tsnapshot.delete();\n});\n// 2. as stream\nconst transform = snapshot.export();\ntransform.pipe(process.stdout);\ntransform.on('finish', snapshot.delete.bind(snapshot));\n```\n\nGet `.heapsnapshot` in `worker_threads`:\n\n```js\n'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\nconst v8Profiler = require('v8-profiler-next');\nconst workerThreads = require('worker_threads');\n\nfunction createSnapshot(filename) {\n  const snapshot = v8Profiler.takeSnapshot();\n  const file = path.join(__dirname, filename);\n  const transform = snapshot.export();\n  transform.pipe(fs.createWriteStream(file));\n  transform.on('finish', snapshot.delete.bind(snapshot));\n}\n\nif (workerThreads.isMainThread) {\n  const w = new workerThreads.Worker(__filename, {\n    env: process.env,\n  });\n\n  // create heapsnapshot in main thread\n  createSnapshot('main.heapsnapshot');\n\n} else {\n  const start = Date.now();\n  const array = [];\n  while (Date.now() - start < 2000) { array.push(new Array(1e3).fill('*')); }\n\n  // create heapsnapshot in worker_threads\n  createSnapshot('worker_threads.heapsnapshot');\n}\n```\n\n### take allocation profile\n\n**Attention:** If node version < v12.x, please use sampling heap profiling alone without cpu profiling or taking snapshot.\n\n```js\n'use strict';\nconst v8Profiler = require('v8-profiler-next');\n// set a leak array\nconst arraytest = [];\nsetInterval(() => {\n  arraytest.push(new Array(1e2).fill('*').join());\n}, 20);\n// start 1min sampling profile\nv8Profiler.startSamplingHeapProfiling();\nsetTimeout(() => {\n\t// stop and get allocation profile\n\tconst profile = v8Profiler.stopSamplingHeapProfiling();\n\t// upload shf.heapprofile into chrome dev tools -> Memory -> ALLOCATION PRODILES\n  require('fs').writeFileSync('./shf.heapprofile', JSON.stringify(profile));\n\tconsole.log(profile);\n}, 60 * 1000);\n```\n\nGet `.heapprofile` in `worker_threads`:\n\n```js\n'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\nconst v8Profiler = require('v8-profiler-next');\nconst workerThreads = require('worker_threads');\n\nif (workerThreads.isMainThread) {\n  const w = new workerThreads.Worker(__filename, {\n    env: process.env,\n  });\n  v8Profiler.startSamplingHeapProfiling();\n  w.once('exit', code => {\n    // create heap profile in main thread\n    const profile = v8Profiler.stopSamplingHeapProfiling();\n    const mainProfile = path.join(__dirname, 'main.heapprofile');\n    fs.existsSync(mainProfile) && fs.unlinkSync(mainProfile);\n    fs.writeFileSync(mainProfile, JSON.stringify(profile));\n  });\n} else {\n  v8Profiler.startSamplingHeapProfiling();\n  // create heap profile in worker_threads\n  const start = Date.now();\n  const array = [];\n  while (Date.now() - start < 2000) { array.push(new Array(1e3).fill('*')); }\n  const profile = v8Profiler.stopSamplingHeapProfiling();\n  const workerProfile = path.join(__dirname, 'worker_threads.heapprofile');\n  fs.existsSync(workerProfile) && fs.unlinkSync(workerProfile);\n  fs.writeFileSync(workerProfile, JSON.stringify(profile));\n}\n```\n\n## II. License\n\n[MIT License](LICENSE)\n\nCopyright (c) 2018 team of [v8-profiler](github.com/node-inspector/v8-profiler), hyj1991\n","gitHead":"c341e5f53a088a959476fedae53c70ec6d2d6151","license":"MIT","scripts":{"dep":"npm run build && npm run test","copy":"node scripts/copy.js","lint":"npm run format && eslint . --fix","pack":"node scripts/clean.js && node-pre-gyp package && node-pre-gyp testpackage && npm run copy","test":"node scripts/test.js","autod":"autod","build":"node scripts/rebuild.js","format":"clang-format -i --glob=\"src/**/*[.h|.cc]\"","install":"node scripts/install.js","pack-7u":"node scripts/7u.js","pack-8u":"node scripts/8u.js","test-new":"mocha test/*.test.js --timeout 10000","test-old":"mocha test/*.test.js --exclude test/worker.test.js --timeout 10000","stability":"node scripts/stability.js","debug-test":"V8_PROFILER_DEBUG=* node scripts/test.js","pack-common":"node scripts/common.js","test-single":"mocha --timeout 10000"},"_npmUser":{"name":"hyj1991","email":"yeekwanvong@gmail.com"},"homepage":"https://github.com/hyj1991/v8-profiler-next#readme","keywords":["node","v8-profiler"],"repository":{"url":"git+https://github.com/hyj1991/v8-profiler-next.git","type":"git"},"_npmVersion":"8.5.5","description":"node bindings for the v8 profiler","directories":{},"maintainers":[{"name":"hyj1991","email":"yeekwanvong@gmail.com"}],"_nodeVersion":"16.15.0","dependencies":{"nan":"^2.16.0","@xprofiler/node-pre-gyp":"^1.0.9"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"chai":"^4.3.6","mocha":"^5.2.0","eslint":"^8.16.0","clang-format":"^1.8.0"},"_npmOperationalInternal":{"tmp":"tmp/v8-profiler-next_1.8.0_1654311301129_0.37407506031809223","host":"s3://npm-registry-packages"},"_id":"v8-profiler-next@1.8.0","version":"1.8.0"}