inspector-api
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "inspector-api", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "index.js", | ||
@@ -27,13 +27,13 @@ "scripts": { | ||
"aws-sdk-mock": "^4.5.0", | ||
"eslint": "^6.0.1", | ||
"eslint-config-standard": "^13.0.1", | ||
"eslint-plugin-import": "^2.18.0", | ||
"eslint-plugin-node": "^9.1.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"jest": "24.8.0" | ||
"eslint-plugin-standard": "^4.0.1", | ||
"jest": "24.9.0" | ||
}, | ||
"dependencies": { | ||
"@voodoo.io/aws-utils": "2.1.0" | ||
"@voodoo.io/aws-utils": "2.2.0" | ||
} | ||
} |
@@ -34,5 +34,5 @@ [![GitHub release](https://badge.fury.io/js/inspector-api.svg)](https://github.com/wallet77/v8-inspector-api/releases/) | ||
## Basic usage | ||
## CPU profiling | ||
```javascript | ||
const Inspector = require('inspector-api'); | ||
const Inspector = require('inspector-api') | ||
const inspector = new Inspector() | ||
@@ -49,6 +49,28 @@ | ||
## Memory sampling | ||
```javascript | ||
const Inspector = require('inspector-api') | ||
const inspector = new Inspector() | ||
await inspector.heap.enable() | ||
await inspector.heap.startSampling() | ||
// Invoke business logic under measurement here... | ||
// some time later... | ||
await inspector.heap.stopSampling() | ||
``` | ||
## Memory snapshot | ||
```javascript | ||
const Inspector = require('inspector-api') | ||
const inspector = new Inspector() | ||
await inspector.heap.takeSnapshot() | ||
``` | ||
## Use S3 exporter | ||
```javascript | ||
const Inspector = require('inspector-api'); | ||
const Inspector = require('inspector-api') | ||
const inspector = new Inspector({ | ||
@@ -82,4 +104,4 @@ storage: { | ||
| `type` | Storage type (raw, s3 or fs) | raw | | ||
| `bucket` | S3 bucket's name | 0 | | ||
| `dir` | Directory where to store the file | empty | | ||
| `bucket` | S3 bucket's name | none | | ||
| `dir` | Directory where to store the file | none | | ||
@@ -86,0 +108,0 @@ If you use fs, the generated data will be store on the disk in your default tmp directory. |
@@ -25,3 +25,3 @@ 'use strict' | ||
async stopSampling () { | ||
return utils.invokeStop('HeapProfiler.stopSampling', this.session, 'heapprofiler', 'heapsnapshot', this.config, this.s3Tools) | ||
return utils.invokeStop('HeapProfiler.stopSampling', this.session, 'heapprofiler', 'heapprofile', this.config, this.s3Tools) | ||
} | ||
@@ -28,0 +28,0 @@ |
@@ -27,4 +27,16 @@ 'use strict' | ||
} | ||
async startPreciseCoverage (args) { | ||
return utils.invokeFunction(this.session, 'Profiler.startPreciseCoverage', args) | ||
} | ||
async stopPreciseCoverage () { | ||
return utils.invokeFunction(this.session, 'Profiler.stopPreciseCoverage') | ||
} | ||
async takePreciseCoverage () { | ||
return utils.invokeStop('Profiler.takePreciseCoverage', this.session, 'coverage', 'json', this.config, this.s3Tools) | ||
} | ||
} | ||
module.exports = Profiler |
@@ -29,5 +29,5 @@ const fs = require('fs') | ||
invokeFunction: (session, fnName) => { | ||
invokeFunction: (session, fnName, args = {}) => { | ||
return new Promise((resolve, reject) => { | ||
session.post(fnName, (err) => { | ||
session.post(fnName, args, (err) => { | ||
if (err) return reject(err) | ||
@@ -44,3 +44,3 @@ resolve() | ||
const profile = res.profile | ||
const data = res.profile || res.result | ||
@@ -50,3 +50,3 @@ const date = new Date() | ||
writeData(profile, fileName, config, s3Tools).then((data) => { | ||
writeData(data, fileName, config, s3Tools).then((data) => { | ||
resolve(data) | ||
@@ -53,0 +53,0 @@ }).catch(err => reject(err)) |
@@ -5,3 +5,3 @@ const Inspector = require('../index') | ||
describe('General methods', () => { | ||
it('collect raw data', async () => { | ||
it('get current Session', async () => { | ||
const inspector = new Inspector() | ||
@@ -24,2 +24,3 @@ await inspector.profiler.enable() | ||
await inspector.destroy() | ||
jest.resetAllMocks() | ||
}) | ||
@@ -92,3 +93,3 @@ | ||
const oldImpl = inspector.profiler.session.post | ||
inspector.profiler.session.post = (name, cb) => { cb(new Error('enable failed')) } | ||
inspector.profiler.session.post = (name, args, cb) => { cb(new Error('enable failed')) } | ||
@@ -112,3 +113,3 @@ try { | ||
await inspector.profiler.enable() | ||
inspector.profiler.session.post = (name, cb) => { cb(new Error('start failed')) } | ||
inspector.profiler.session.post = (name, args, cb) => { cb(new Error('start failed')) } | ||
await inspector.profiler.start() | ||
@@ -139,2 +140,25 @@ await inspector.profiler.stop() | ||
}) | ||
describe('Coverage', () => { | ||
let inspector = null | ||
afterEach(async () => { | ||
await inspector.destroy() | ||
}) | ||
it('collect raw data', async () => { | ||
inspector = new Inspector() | ||
await inspector.profiler.enable() | ||
await inspector.profiler.startPreciseCoverage({ callCount: true, detailed: true }) | ||
const data = await inspector.profiler.takePreciseCoverage() | ||
await inspector.profiler.stopPreciseCoverage() | ||
const detectProfilerFile = data.find((item) => { | ||
return item.url.indexOf('profiler.test.js') > -1 | ||
}) | ||
expect(detectProfilerFile).toBeDefined() | ||
}) | ||
}) | ||
}) |
18908
12
365
115
4
+ Added@voodoo.io/aws-utils@2.2.0(transitive)
+ Addedasync-await-retry@1.0.2(transitive)
+ Addedaws-sdk@2.493.0(transitive)
- Removed@voodoo.io/aws-utils@2.1.0(transitive)
- Removedasync-await-retry@1.0.1(transitive)
- Removedaws-sdk@2.437.0(transitive)
Updated@voodoo.io/aws-utils@2.2.0