memlab 1.1.55 → 1.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -25
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,22 +4,24 @@ memlab is an end-to-end testing and analysis framework for identifying
|
|
|
4
4
|
JavaScript memory leaks and optimization opportunities.
|
|
5
5
|
|
|
6
6
|
Online Resources:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
- [Official Website and Demo](https://facebook.github.io/memlab)
|
|
9
|
+
- [Documentation](https://facebook.github.io/memlab/docs/intro)
|
|
10
|
+
- [Meta Engineering Blog Post](https://engineering.fb.com/2022/09/12/open-source/memlab/)
|
|
10
11
|
|
|
11
12
|
Features:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
|
|
14
|
+
- **Browser memory leak detection** - Write test scenarios with the Puppeteer
|
|
15
|
+
API, and memlab will automatically compare JavaScript heap snapshots, filter
|
|
16
|
+
out memory leaks, and aggregate the results
|
|
17
|
+
- **Object-oriented heap traversing API** - Supports the creation of
|
|
18
|
+
self-defined memory leak detector, and enables programmatic analysis JS heap
|
|
19
|
+
snapshots taken from Chromium-based browsers, Node.js, Electron.js, and Hermes
|
|
20
|
+
- **Memory CLI toolbox** - Built-in toolbox and APIs for finding memory
|
|
21
|
+
optimization opportunities (not necessarily just memory leaks)
|
|
22
|
+
- **Memory assertions in Node.js** - Enables unit tests or running node.js
|
|
23
|
+
programs to take a heap snapshot of their own state, perform self memory
|
|
24
|
+
checking, or write advanced memory assertions
|
|
23
25
|
|
|
24
26
|
## CLI Usage
|
|
25
27
|
|
|
@@ -44,7 +46,7 @@ function url() {
|
|
|
44
46
|
// action where we want to detect memory leaks: click the Hotels button
|
|
45
47
|
async function action(page) {
|
|
46
48
|
// puppeteer page API
|
|
47
|
-
await page.click('
|
|
49
|
+
await page.click('text/Hotels');
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
// action where we want to go back to the step before: click clear search
|
|
@@ -90,6 +92,7 @@ MemLab found 46 leak(s)
|
|
|
90
92
|
--elements (internal)---> [(object elements)] (array) @182929 [8.3MB]
|
|
91
93
|
...
|
|
92
94
|
```
|
|
95
|
+
|
|
93
96
|
To get readable trace, the web site under test needs to serve non-minified code (or at least minified code
|
|
94
97
|
with readable variables, function name, and property names on objects).
|
|
95
98
|
|
|
@@ -101,6 +104,7 @@ in Chrome DevTool and search for the leaked object ID (`@182929`).
|
|
|
101
104
|
View memory issues detected by memlab based on a single JavaScript
|
|
102
105
|
heap snapshot taken from Chromium, Hermes, memlab, or any node.js
|
|
103
106
|
or Electron.js program:
|
|
107
|
+
|
|
104
108
|
```bash
|
|
105
109
|
memlab view-heap --snapshot <PATH TO .heapsnapshot FILE>
|
|
106
110
|
```
|
|
@@ -116,7 +120,7 @@ object (`node`) allocated by the target interaction.
|
|
|
116
120
|
function leakFilter(node, heap) {
|
|
117
121
|
// ... your leak detector logic
|
|
118
122
|
// return true to mark the node as a memory leak
|
|
119
|
-
}
|
|
123
|
+
}
|
|
120
124
|
```
|
|
121
125
|
|
|
122
126
|
`heap` is the graph representation of the final JavaScript heap snapshot.
|
|
@@ -126,6 +130,7 @@ For more details, view the
|
|
|
126
130
|
### Heap Analysis and Investigation
|
|
127
131
|
|
|
128
132
|
View which object keeps growing in size during interaction in the previous run:
|
|
133
|
+
|
|
129
134
|
```bash
|
|
130
135
|
memlab analyze unbound-object
|
|
131
136
|
```
|
|
@@ -140,6 +145,7 @@ Use `memlab analyze` to view all built-in memory analyses.
|
|
|
140
145
|
For extension, view the [doc site](https://facebook.github.io/memlab).
|
|
141
146
|
|
|
142
147
|
View retainer trace of a particular object:
|
|
148
|
+
|
|
143
149
|
```bash
|
|
144
150
|
memlab trace --node-id <HEAP_OBJECT_ID>
|
|
145
151
|
```
|
|
@@ -154,15 +160,15 @@ Use the `memlab` npm package to start a E2E run in browser and detect memory lea
|
|
|
154
160
|
const memlab = require('memlab');
|
|
155
161
|
|
|
156
162
|
const scenario = {
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
// initial page load url
|
|
164
|
+
url: () => 'https://www.google.com/maps/@37.386427,-122.0428214,11z',
|
|
159
165
|
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
// action where we want to detect memory leaks
|
|
167
|
+
action: async page => await page.click('text/Hotels'),
|
|
162
168
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
169
|
+
// action where we want to go back to the step before
|
|
170
|
+
back: async page => await page.click('[aria-label="Close"]'),
|
|
171
|
+
};
|
|
166
172
|
memlab.run({scenario});
|
|
167
173
|
```
|
|
168
174
|
|
|
@@ -189,7 +195,7 @@ test('memory test with heap assertion', async () => {
|
|
|
189
195
|
let heap: IHeapSnapshot = await takeNodeMinimalHeap();
|
|
190
196
|
|
|
191
197
|
// call some function that may add references to obj
|
|
192
|
-
rabbitHole(obj)
|
|
198
|
+
rabbitHole(obj);
|
|
193
199
|
|
|
194
200
|
expect(heap.hasObjectWithClassName('TestObject')).toBe(true);
|
|
195
201
|
obj = null;
|
|
@@ -198,7 +204,6 @@ test('memory test with heap assertion', async () => {
|
|
|
198
204
|
// if rabbitHole does not have any side effect that
|
|
199
205
|
// adds new references to obj, then obj can be GCed
|
|
200
206
|
expect(heap.hasObjectWithClassName('TestObject')).toBe(false);
|
|
201
|
-
|
|
202
207
|
}, 30000);
|
|
203
208
|
```
|
|
204
209
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memlab",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.56",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "memlab is a framework that analyzes memory and finds memory leaks in JavaScript applications.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"snapshot"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@memlab/api": "^1.0.
|
|
30
|
-
"@memlab/cli": "^1.0.
|
|
31
|
-
"@memlab/core": "^1.1.
|
|
32
|
-
"@memlab/e2e": "^1.0.
|
|
33
|
-
"@memlab/heap-analysis": "^1.0.
|
|
29
|
+
"@memlab/api": "^1.0.38",
|
|
30
|
+
"@memlab/cli": "^1.0.41",
|
|
31
|
+
"@memlab/core": "^1.1.39",
|
|
32
|
+
"@memlab/e2e": "^1.0.39",
|
|
33
|
+
"@memlab/heap-analysis": "^1.0.36",
|
|
34
34
|
"ansi": "^0.3.1",
|
|
35
35
|
"babar": "^0.2.0",
|
|
36
36
|
"chalk": "^4.0.0",
|