v8-profiler-next
Advanced tools
Comparing version 1.5.1 to 1.6.0
{ | ||
"name": "v8-profiler-next", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "node bindings for the v8 profiler", | ||
"main": "dispatch.js", | ||
"scripts": { | ||
"test": "mocha test/*.test.js --timeout 10000" | ||
"test-old": "mocha test/*.test.js --exclude test/worker.test.js --timeout 10000", | ||
"test-new": "mocha test/*.test.js --timeout 10000", | ||
"test": "node scripts/test.js", | ||
"test-single": "mocha --timeout 10000", | ||
"build": "node-gyp rebuild", | ||
"format": "clang-format -i --glob=\"src/**/*[.h|.cc]\"" | ||
}, | ||
@@ -25,2 +30,3 @@ "repository": { | ||
"src", | ||
"lib", | ||
"binding.gyp", | ||
@@ -33,8 +39,9 @@ "dispatch.js", | ||
"dependencies": { | ||
"nan": "^2.14.1" | ||
"nan": "^2.15.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"clang-format": "^1.8.0", | ||
"mocha": "^5.2.0" | ||
} | ||
} | ||
} |
111
README.md
@@ -17,5 +17,7 @@ # v8-profiler-next | ||
* **Compatibility** | ||
* **node version:** v4.x ~ v16.x | ||
* **node version:** v4.x ~ v18.x | ||
* **platform:** mac, linux, windows | ||
This module can also be used in `worker_threads`. | ||
### take cpu profile | ||
@@ -51,2 +53,38 @@ | ||
Get `.cpuprofile` in `worker_threads`: | ||
```js | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const v8Profiler = require('./'); | ||
const workerThreads = require('worker_threads'); | ||
v8Profiler.setGenerateType(1); | ||
if (workerThreads.isMainThread) { | ||
const w = new workerThreads.Worker(__filename, { | ||
env: process.env, | ||
}); | ||
v8Profiler.startProfiling('main', true); | ||
w.once('exit', code => { | ||
// create cpu profile in main thread | ||
const profile = v8Profiler.stopProfiling('main'); | ||
const mainProfile = path.join(__dirname, 'main.cpuprofile'); | ||
fs.existsSync(mainProfile) && fs.unlinkSync(mainProfile); | ||
fs.writeFileSync(mainProfile, JSON.stringify(profile)); | ||
}); | ||
} else { | ||
v8Profiler.startProfiling('worker_threads', true); | ||
// create cpu profile in worker_threads | ||
const start = Date.now(); | ||
while (Date.now() - start < 2000) { } | ||
const profile = v8Profiler.stopProfiling('worker_threads'); | ||
const workerProfile = path.join(__dirname, 'worker_threads.cpuprofile'); | ||
fs.existsSync(workerProfile) && fs.unlinkSync(workerProfile); | ||
fs.writeFileSync(workerProfile, JSON.stringify(profile)); | ||
} | ||
``` | ||
### take heapsnapshot | ||
@@ -73,2 +111,38 @@ | ||
Get `.heapsnapshot` in `worker_threads`: | ||
```js | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const v8Profiler = require('./'); | ||
const workerThreads = require('worker_threads'); | ||
function createSnapshot(filename) { | ||
const snapshot = v8Profiler.takeSnapshot(); | ||
const file = path.join(__dirname, filename); | ||
const transform = snapshot.export(); | ||
transform.pipe(fs.createWriteStream(file)); | ||
transform.on('finish', snapshot.delete.bind(snapshot)); | ||
} | ||
if (workerThreads.isMainThread) { | ||
const w = new workerThreads.Worker(__filename, { | ||
env: process.env, | ||
}); | ||
// create heapsnapshot in main thread | ||
createSnapshot('main.heapsnapshot'); | ||
} else { | ||
const start = Date.now(); | ||
const array = []; | ||
while (Date.now() - start < 2000) { array.push(new Array(1e3).fill('*')); } | ||
// create heapsnapshot in worker_threads | ||
createSnapshot('worker_threads.heapsnapshot'); | ||
} | ||
``` | ||
### take allocation profile | ||
@@ -97,2 +171,37 @@ | ||
Get `.heapprofile` in `worker_threads`: | ||
```js | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const v8Profiler = require('./'); | ||
const workerThreads = require('worker_threads'); | ||
if (workerThreads.isMainThread) { | ||
const w = new workerThreads.Worker(__filename, { | ||
env: process.env, | ||
}); | ||
v8Profiler.startSamplingHeapProfiling(); | ||
w.once('exit', code => { | ||
// create heap profile in main thread | ||
const profile = v8Profiler.stopSamplingHeapProfiling(); | ||
const mainProfile = path.join(__dirname, 'main.heapprofile'); | ||
fs.existsSync(mainProfile) && fs.unlinkSync(mainProfile); | ||
fs.writeFileSync(mainProfile, JSON.stringify(profile)); | ||
}); | ||
} else { | ||
v8Profiler.startSamplingHeapProfiling(); | ||
// create heap profile in worker_threads | ||
const start = Date.now(); | ||
const array = []; | ||
while (Date.now() - start < 2000) { array.push(new Array(1e3).fill('*')); } | ||
const profile = v8Profiler.stopSamplingHeapProfiling(); | ||
const workerProfile = path.join(__dirname, 'worker_threads.heapprofile'); | ||
fs.existsSync(workerProfile) && fs.unlinkSync(workerProfile); | ||
fs.writeFileSync(workerProfile, JSON.stringify(profile)); | ||
} | ||
``` | ||
## II. License | ||
@@ -99,0 +208,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78540
30
374
208
3
Updatednan@^2.15.0