4

memlab

 1 year ago
source link: https://facebookincubator.github.io/memlab/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

memlab

Analyzes JavaScript heap and finds memory leaks in browser and node.js

Define Your Test

Define E2E test scenarios on browser interaction:

// test.js
function url() {
return 'https://www.google.com/maps/';
async function action(page) {
await page.click('button[aria-label="Hotels"]');
async function back(page) {
await page.click('[aria-label="Clear search"]');
module.exports = {action, back, url};

Run memlab in CLI

Find memory leaks with the custom E2E test scenario:

$ memlab run --scenario test.js
Support memory analyses for the previous browser test:
# Analyze duplicated string in heap
$ memlab analyze string
# Check unbound object growth
$ memlab analyze unbound-object
# Get shapes with unbound growth
$ memlab analyze unbound-shape
# discover more memory analyses
$ memlab analyze -h

Programming API

Memory analysis for JavaScript heap snapshots:

const {findLeaks, takeSnapshots} = require('@memlab/api');
async function test() {
const scenario = {
url: () => 'https://www.facebook.com',
const result = await takeSnapshots({scenario});
const leaks = findLeaks(result);
// ...

Who's using memlab?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK