-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·57 lines (46 loc) · 1.09 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
require = require('esm')(module, { // eslint-disable-line no-global-assign
cache: false,
cjs: {
cache: true,
namedExports: true
}
})
function randomString(length) {
let i = 0
let str = ''
while (++i < length) {
str += String.fromCharCode(33 + Math.floor(93 * Math.random()))
}
return str
}
async function main() {
const { start, getMemwatch } = require('..')
await start({
graph: true,
useMovingAverage: 5,
leakGrowthCount: 3,
autoHeapDiff: true,
gcMetrics: true
})
const memwatch = await getMemwatch()
let log = { count: 1 }
setInterval(() => {
/* TODO:
* setting a too long string will result in a segfault
* in @airbnb/node-memwatch when creating a heap diff
*
* also, this is a random string because apparently v8 is smart enough
* to not create multiple copies of the same string variable
*/
log[++log.count] = randomString(10000)
if (!(log.count % 10)) {
memwatch.gc()
}
}, 100)
setInterval(() => {
log = { count: 1 }
memwatch.gc()
}, 20000)
}
main()