UNPKG

2.07 kBJavaScriptView Raw
1'use strict'
2
3const test = require('tap').test
4const analyseMemory = require('../analysis/analyse-memory.js')
5const generateTraceEvent = require('./generate-trace-event.js')
6const generateProcessStat = require('./generate-process-stat.js')
7
8test('analyse memory - delay correlation', function (t) {
9 const goodMemoryStat = generateProcessStat({
10 delay: [1, 1, 1, 30, 1, 1, 1],
11 memory: {
12 heapTotal: [30, 40, 40, 50, 30, 40, 40],
13 heapUsed: [30, 40, 40, 50, 30, 40, 40]
14 }
15 }, 0)
16 const goodMemoryGc = generateTraceEvent([
17 'NONE', 'SCA', 'NONE', 'MSC', 'MSC', 'MSC', 'NONE', 'SCA', 'NONE'
18 ])
19
20 t.strictDeepEquals(analyseMemory(goodMemoryStat, goodMemoryGc), {
21 external: false,
22 heapTotal: false,
23 heapUsed: false,
24 rss: false
25 })
26
27 const badMemoryStat = generateProcessStat({
28 delay: [1, 1, 1, 120, 1, 1, 1],
29 memory: {
30 heapTotal: [1, 50, 50, 150, 1, 50, 50],
31 heapUsed: [1, 50, 50, 150, 1, 50, 50]
32 }
33 }, 0)
34 const badMemoryGc = generateTraceEvent([
35 'NONE', 'SCA', 'NONE',
36 'MSC', 'MSC', 'MSC', 'MSC',
37 'MSC', 'MSC', 'MSC', 'MSC',
38 'MSC', 'MSC', 'MSC',
39 'NONE', 'SCA', 'NONE'
40 ])
41 t.strictDeepEquals(analyseMemory(badMemoryStat, badMemoryGc), {
42 external: false,
43 heapTotal: false,
44 heapUsed: true,
45 rss: false
46 })
47
48 t.end()
49})
50
51test('analyse memory - old space too large', function (t) {
52 for (const noise of [0, 1, 10]) {
53 const goodMemory = generateProcessStat({
54 memory: {
55 heapTotal: [30, 100, 200, 300, 300, 300, 300, 300, 300, 300, 300, 300]
56 }
57 }, noise)
58 t.strictDeepEquals(analyseMemory(goodMemory, []), {
59 external: false,
60 heapTotal: false,
61 heapUsed: false,
62 rss: false
63 })
64
65 const badMemory = generateProcessStat({
66 memory: {
67 heapTotal: [30, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100]
68 }
69 }, noise)
70 t.strictDeepEquals(analyseMemory(badMemory, []), {
71 external: false,
72 heapTotal: true,
73 heapUsed: false,
74 rss: false
75 })
76 }
77
78 t.end()
79})