-
Notifications
You must be signed in to change notification settings - Fork 481
Expand file tree
/
Copy pathinsert-stack-labels.test.ts
More file actions
158 lines (136 loc) · 5.47 KB
/
Copy pathinsert-stack-labels.test.ts
File metadata and controls
158 lines (136 loc) · 5.47 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { getProfileFromTextSamples } from '../fixtures/profiles/processed-profile';
import { insertStackLabels } from '../../profile-logic/insert-stack-labels';
import { callTreeFromProfile, formatTree } from '../fixtures/utils';
describe('insertStackLabels', function () {
it('inserts a label before the first frame matching a label', function () {
const { profile } = getProfileFromTextSamples(`
A
B
mozilla::layout::Reflow
mozilla::layout::FrameReflow
`);
const labeled = insertStackLabels(profile, [
{ name: 'Layout', funcPrefixes: ['mozilla::layout::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Root (unaccounted / catch-all) (total: 1, self: —)',
' - A (total: 1, self: —)',
' - B (total: 1, self: —)',
' - Layout (total: 1, self: —)',
' - mozilla::layout::Reflow (total: 1, self: —)',
' - mozilla::layout::FrameReflow (total: 1, self: 1)',
]);
});
it('does not repeat the label for consecutive frames in the same label', function () {
const { profile } = getProfileFromTextSamples(`
A
gfx::Composite
gfx::LayerManager::Render
gfx::DrawQuad
`);
const labeled = insertStackLabels(profile, [
{ name: 'Graphics', funcPrefixes: ['gfx::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Root (unaccounted / catch-all) (total: 1, self: —)',
' - A (total: 1, self: —)',
' - Graphics (total: 1, self: —)',
' - gfx::Composite (total: 1, self: —)',
' - gfx::LayerManager::Render (total: 1, self: —)',
' - gfx::DrawQuad (total: 1, self: 1)',
]);
});
it('does not re-insert the label when re-entering a label after an unmatched frame', function () {
// A non-JS, non-label frame (helper) propagates the inherited label context,
// so gfx::DrawQuad is still considered inside the Graphics label and no new
// label is inserted.
const { profile } = getProfileFromTextSamples(`
gfx::Composite
helper
gfx::DrawQuad
`);
const labeled = insertStackLabels(profile, [
{ name: 'Graphics', funcPrefixes: ['gfx::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Graphics (total: 1, self: —)',
' - gfx::Composite (total: 1, self: —)',
' - helper (total: 1, self: —)',
' - gfx::DrawQuad (total: 1, self: 1)',
]);
});
it('inserts the right label when multiple labels are configured', function () {
const { profile } = getProfileFromTextSamples(`
A A
layout::Reflow gfx::Composite
`);
const labeled = insertStackLabels(profile, [
{ name: 'Layout', funcPrefixes: ['layout::'] },
{ name: 'Graphics', funcPrefixes: ['gfx::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Root (unaccounted / catch-all) (total: 2, self: —)',
' - A (total: 2, self: —)',
' - Layout (total: 1, self: —)',
' - layout::Reflow (total: 1, self: 1)',
' - Graphics (total: 1, self: —)',
' - gfx::Composite (total: 1, self: 1)',
]);
});
it('inserts a new label when switching from one label to another', function () {
const { profile } = getProfileFromTextSamples(`
layout::Reflow
gfx::Composite
`);
const labeled = insertStackLabels(profile, [
{ name: 'Layout', funcPrefixes: ['layout::'] },
{ name: 'Graphics', funcPrefixes: ['gfx::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Layout (total: 1, self: —)',
' - layout::Reflow (total: 1, self: —)',
' - Graphics (total: 1, self: —)',
' - gfx::Composite (total: 1, self: 1)',
]);
});
it('wraps unmatched root frames in a root label', function () {
const { profile } = getProfileFromTextSamples(`
A
B
C
`);
const labeled = insertStackLabels(profile, [
{ name: 'Layout', funcPrefixes: ['layout::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Root (unaccounted / catch-all) (total: 1, self: —)',
' - A (total: 1, self: —)',
' - B (total: 1, self: —)',
' - C (total: 1, self: 1)',
]);
});
it('handles multiple samples sharing common prefixes correctly', function () {
const { profile } = getProfileFromTextSamples(`
A A A
B B B
gfx::Composite gfx::Composite C
gfx::DrawQuad gfx::LayerManager::Render
`);
const labeled = insertStackLabels(profile, [
{ name: 'Graphics', funcPrefixes: ['gfx::'] },
]);
expect(formatTree(callTreeFromProfile(labeled))).toEqual([
'- Root (unaccounted / catch-all) (total: 3, self: —)',
' - A (total: 3, self: —)',
' - B (total: 3, self: —)',
' - Graphics (total: 2, self: —)',
' - gfx::Composite (total: 2, self: —)',
' - gfx::DrawQuad (total: 1, self: 1)',
' - gfx::LayerManager::Render (total: 1, self: 1)',
' - C (total: 1, self: 1)',
]);
});
});