Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

inspector-api

wallet77281.3kMIT1.4.11TypeScript support: included

A simple node module to access V8 inspector + some tools to export and read the data.

v8, inspector, profiler, profiling, cpu, memory, coverage, heap, HeapSnapshot, performance, sampling

readme

GitHub release GitHub license

CI pipeline Code coverage Opened issues Opened PR DeepScan grade Node version

Purpose

Simple wrapper around "inspector" module. Basically it adds :

  • promises & async/await syntax
  • S3 exporter

Compatibility

Version Supported Tested
20.x yes yes
18.x yes yes
16.x yes yes

In order to have all features we recommend to use at least Node.js version 10 or higher.

Installation

$ npm install inspector-api --save

Usage

CPU profiling

const Inspector = require('inspector-api')
const inspector = new Inspector()

await inspector.profiler.enable()
await inspector.profiler.start()
// Invoke business logic under measurement here...

// some time later...
await inspector.profiler.stop()

Memory sampling

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

const Inspector = require('inspector-api')
const inspector = new Inspector()

await inspector.heap.takeSnapshot()

Code coverage

const Inspector = require('inspector-api')
const 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()

Use S3 exporter

const Inspector = require('inspector-api')
const inspector = new Inspector({
    storage: {
        type: 's3',
        bucket: 'testBucket',
        dir: 'inspector'
    }
})

await inspector.profiler.enable()
await inspector.profiler.start()
// Invoke business logic under measurement here...

// some time later...
await inspector.profiler.stop()

Warning: it seems that the new AWS SDK leads to unexpected error if you use the takeSnapshot method (you should use memory sampling)

Constructor's config

new inspector([config])

config.storage

Option description Default value
type Storage type (raw, s3 or fs) raw
bucket S3 bucket's name none
dir Directory where to store the file none

If you use fs, the generated data will be store on the disk in your default tmp directory. You can display it in Node.js with the command require('os').tmpdir()

Test

$ npm test

Coverage report can be found in coverage/.

changelog

Version 1.4.6 released on 2022-12-22

Features

Upgrade dependencies

Upgrades dependencies version.

440bf4a - Version 1.4.6

Version 1.4.1 released on 2021-06-10

Features

Add TS config and types

This feature will facilitate the work of the devs when they use this module.

6f932d3 - Version 1.4.1

Version 1.4.0 released on 2021-06-01

Features

Switch to the new AWS SDK

This feature will reduce package size and improve performances.

9be9b5d - Version 1.4.0

Version 1.x released on 2019-10-03

Features

CPU profiling

This feature will trigger a CPU profiling and save data (file, export to S3, return raw data)

7f7265f - Version 1.0.0

Memory Snapshot

This feature can trigger memory snapshot (or memory sampling).

7f7265f - Version 1.0.0

Code coverage

This feature retrieve code coverage data during runtime.

7ab4df1 - Add coverage feature.

Export to S3

This feature allow you to export every generated data to S3.

7f7265f - Version 1.0.0