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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test diffing census reports of a "complex" and "realistic" breakdown.
const BREAKDOWN = {
by: "coarseType",
objects: {
by: "allocationStack",
then: {
by: "objectClass",
then: { by: "count", count: false, bytes: true },
other: { by: "count", count: false, bytes: true }
},
noStack: {
by: "objectClass",
then: { by: "count", count: false, bytes: true },
other: { by: "count", count: false, bytes: true }
}
},
strings: {
by: "internalType",
then: { by: "count", count: false, bytes: true }
},
scripts: {
by: "internalType",
then: { by: "count", count: false, bytes: true }
},
other: {
by: "internalType",
then: { by: "count", count: false, bytes: true }
},
};
const stack1 = saveStack();
const stack2 = saveStack();
const stack3 = saveStack();
const REPORT1 = {
objects: new Map([
[stack1, { Function: { bytes: 1 },
Object: { bytes: 2 },
other: { bytes: 0 },
}],
[stack2, { Array: { bytes: 3 },
Date: { bytes: 4 },
other: { bytes: 0 },
}],
["noStack", { Object: { bytes: 3 }}],
]),
strings: {
JSAtom: { bytes: 10 },
JSLinearString: { bytes: 5 },
},
scripts: {
JSScript: { bytes: 1 },
"js::jit::JitCode": { bytes: 2 },
},
other: {
"mozilla::dom::Thing": { bytes: 1 },
}
};
const REPORT2 = {
objects: new Map([
[stack2, { Array: { bytes: 1 },
Date: { bytes: 2 },
other: { bytes: 3 },
}],
[stack3, { Function: { bytes: 1 },
Object: { bytes: 2 },
other: { bytes: 0 },
}],
["noStack", { Object: { bytes: 3 }}],
]),
strings: {
JSAtom: { bytes: 5 },
JSLinearString: { bytes: 10 },
},
scripts: {
JSScript: { bytes: 2 },
"js::LazyScript": { bytes: 42 },
"js::jit::JitCode": { bytes: 1 },
},
other: {
"mozilla::dom::OtherThing": { bytes: 1 },
}
};
const EXPECTED = {
"objects": new Map([
[stack1, { Function: { bytes: -1 },
Object: { bytes: -2 },
other: { bytes: 0 },
}],
[stack2, { Array: { bytes: -2 },
Date: { bytes: -2 },
other: { bytes: 3 },
}],
[stack3, { Function: { bytes: 1 },
Object: { bytes: 2 },
other: { bytes: 0 },
}],
["noStack", { Object: { bytes: 0 }}],
]),
"scripts": {
"JSScript": {
"bytes": 1
},
"js::jit::JitCode": {
"bytes": -1
},
"js::LazyScript": {
"bytes": 42
}
},
"strings": {
"JSAtom": {
"bytes": -5
},
"JSLinearString": {
"bytes": 5
}
},
"other": {
"mozilla::dom::Thing": {
"bytes": -1
},
"mozilla::dom::OtherThing": {
"bytes": 1
}
}
};
function run_test() {
assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED);
}
|