Skip to content

Commit 4bb7a7b

Browse files
Jayson ChenDevtools-frontend LUCI CQ
authored andcommitted
Catching up on target and execution context
Explainer: https://docs.google.com/document/d/1TcNWJazctw4jwW5unidwbXCPNUyUeTEbyM3tmsivipw/edit?tab=t.0 With script catch up, we can assume we have all the information about a script, but we still need to catch up on execution contexts and targets. With this change we can reliably operate enhanced traces recorded at any time of a page life cycle in rehydrated session. Bug: 337909145 Change-Id: Ie55f85c3cd87e8793277ea31fa0220939a657144 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6310360 Commit-Queue: Jayson Chen <[email protected]> Commit-Queue: Paul Irish <[email protected]> Reviewed-by: Robert Paveza <[email protected]> Reviewed-by: Paul Irish <[email protected]> Feels: Paul Irish <[email protected]>
1 parent 8b21fd8 commit 4bb7a7b

File tree

7 files changed

+364
-89
lines changed

7 files changed

+364
-89
lines changed

front_end/core/sdk/EnhancedTracesParser.test.ts

Lines changed: 138 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ import type {RehydratingExecutionContext, RehydratingScript, RehydratingTarget}
1111
describe('EnhancedTracesParser', () => {
1212
let enhancedTracesParser: EnhancedTraces.EnhancedTracesParser;
1313
const target1: RehydratingTarget = {
14-
targetId: '21D58E83A5C17916277166140F6A464B' as Protocol.Page.FrameId,
14+
targetId: '21D58E83A5C17916277166140F6A464B' as Protocol.Target.TargetID,
1515
type: 'page',
16-
isolate: '12345',
1716
pid: 8050,
1817
url: 'http://localhost:8080/index.html',
1918
};
2019
const target2: RehydratingTarget = {
21-
targetId: '3E1717BE677B75D0536E292E00D6A34A' as Protocol.Page.FrameId,
22-
type: 'page',
23-
isolate: '6789',
20+
targetId: '3E1717BE677B75D0536E292E00D6A34A' as Protocol.Target.TargetID,
21+
type: 'iframe',
2422
pid: 8051,
25-
url: 'http://localhost:8080/index.html',
23+
url: 'http://localhost:8080/test.html',
24+
};
25+
const target3: RehydratingTarget = {
26+
targetId: '6A7611591E1EBABAACBAB2B23F0AEC93' as Protocol.Target.TargetID,
27+
type: 'iframe',
28+
pid: 8052,
29+
url: 'test1',
2630
};
2731

2832
const executionContext1: RehydratingExecutionContext = {
@@ -61,6 +65,18 @@ describe('EnhancedTracesParser', () => {
6165
isolate: '6789',
6266
};
6367

68+
const executionContext4: RehydratingExecutionContext = {
69+
id: 1 as Protocol.Runtime.ExecutionContextId,
70+
origin: '',
71+
v8Context: '',
72+
auxData: {
73+
frameId: '6A7611591E1EBABAACBAB2B23F0AEC93' as Protocol.Page.FrameId,
74+
isDefault: false,
75+
type: 'type',
76+
},
77+
isolate: '1357',
78+
};
79+
6480
const script1: RehydratingScript = {
6581
scriptId: '1' as Protocol.Runtime.ScriptId,
6682
isolate: '12345',
@@ -76,6 +92,7 @@ describe('EnhancedTracesParser', () => {
7692
sourceURL: undefined,
7793
sourceMapURL: 'http://localhost:8080/source.map.json',
7894
length: 13,
95+
pid: 8050,
7996
sourceText: 'source text 1',
8097
auxData: {
8198
frameId: '21D58E83A5C17916277166140F6A464B' as Protocol.Page.FrameId,
@@ -99,6 +116,7 @@ describe('EnhancedTracesParser', () => {
99116
sourceURL: undefined,
100117
sourceMapURL: undefined,
101118
length: 13,
119+
pid: 8050,
102120
sourceText: 'source text 2',
103121
auxData: {
104122
frameId: '21D58E83A5C17916277166140F6A464B' as Protocol.Page.FrameId,
@@ -122,6 +140,7 @@ describe('EnhancedTracesParser', () => {
122140
sourceURL: undefined,
123141
sourceMapURL: undefined,
124142
length: 13,
143+
pid: 8051,
125144
sourceText: 'source text 3',
126145
auxData: {
127146
frameId: '3E1717BE677B75D0536E292E00D6A34A' as Protocol.Page.FrameId,
@@ -130,37 +149,96 @@ describe('EnhancedTracesParser', () => {
130149
},
131150
};
132151

152+
const script4: RehydratingScript = {
153+
scriptId: '3' as Protocol.Runtime.ScriptId,
154+
isolate: '12345',
155+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
156+
startLine: 0,
157+
startColumn: 0,
158+
endLine: 1,
159+
endColumn: 10,
160+
hash: '',
161+
isModule: false,
162+
url: 'http://localhost:8080/index.html',
163+
hasSourceURL: false,
164+
sourceURL: undefined,
165+
sourceMapURL: undefined,
166+
pid: 8050,
167+
auxData: {
168+
frameId: '21D58E83A5C17916277166140F6A464B' as Protocol.Page.FrameId,
169+
isDefault: true,
170+
type: 'type',
171+
},
172+
};
173+
174+
const script5: RehydratingScript = {
175+
scriptId: '4' as Protocol.Runtime.ScriptId,
176+
isolate: '12345',
177+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
178+
startLine: 0,
179+
startColumn: 0,
180+
endLine: 1,
181+
endColumn: 10,
182+
hash: '',
183+
isModule: false,
184+
url: 'http://localhost:8080/index.html',
185+
hasSourceURL: false,
186+
sourceURL: undefined,
187+
sourceMapURL: undefined,
188+
pid: 8050,
189+
auxData: {
190+
frameId: '21D58E83A5C17916277166140F6A464B' as Protocol.Page.FrameId,
191+
isDefault: true,
192+
type: 'type',
193+
},
194+
};
195+
196+
const script6: RehydratingScript = {
197+
scriptId: '1' as Protocol.Runtime.ScriptId,
198+
isolate: '1357',
199+
executionContextId: 1 as Protocol.Runtime.ExecutionContextId,
200+
startLine: 0,
201+
startColumn: 0,
202+
endLine: 1,
203+
endColumn: 10,
204+
hash: '',
205+
isModule: false,
206+
url: 'http://localhost:8080/index.html',
207+
hasSourceURL: false,
208+
sourceURL: undefined,
209+
sourceMapURL: undefined,
210+
pid: 8052,
211+
};
212+
133213
beforeEach(async function() {
134214
const events = await TraceLoader.rawEvents(this, 'enhanced-traces.json.gz');
135215
enhancedTracesParser = new EnhancedTraces.EnhancedTracesParser({traceEvents: events as object[], metadata: {}});
136216
});
137217

138-
it('captures targets from target rundown events', async function() {
218+
it('captures correct targets', async function() {
139219
const data = enhancedTracesParser.data();
140220
const targets: RehydratingTarget[] = [];
141-
for (const target of data.keys()) {
221+
for (const hydrationData of data) {
222+
const target = hydrationData.target;
142223
targets.push(target);
143224
if (target.pid === 8050) {
144225
assert.deepEqual(target, target1);
145226
} else if (target.pid === 8051) {
146227
assert.deepEqual(target, target2);
228+
} else if (target.pid === 8052) {
229+
assert.deepEqual(target, target3);
147230
}
148231
}
149-
assert.lengthOf(targets, 2);
232+
assert.lengthOf(targets, 3);
150233
});
151234

152235
it('captures execution context info', async function() {
153236
const data = enhancedTracesParser.data();
154237
let executionContexts: RehydratingExecutionContext[] = [];
155-
for (const target of data.keys()) {
156-
const contextsAndScripts = data.get(target);
157-
if (contextsAndScripts) {
158-
executionContexts = [...executionContexts, ...contextsAndScripts[0]];
159-
} else {
160-
assert.fail('Contexts and Scripts should not be null or undefined');
161-
}
238+
for (const hydrationData of data) {
239+
executionContexts = [...executionContexts, ...hydrationData.executionContexts];
162240
}
163-
assert.lengthOf(executionContexts, 3);
241+
assert.lengthOf(executionContexts, 4);
164242
for (const executionContext of executionContexts) {
165243
if (executionContext.id === 1 && executionContext.isolate === '12345') {
166244
assert.deepEqual(executionContext, executionContext1);
@@ -175,15 +253,10 @@ describe('EnhancedTracesParser', () => {
175253
it('captures script info and source text', async function() {
176254
const data = enhancedTracesParser.data();
177255
let scripts: RehydratingScript[] = [];
178-
for (const target of data.keys()) {
179-
const contextsAndScripts = data.get(target);
180-
if (contextsAndScripts) {
181-
scripts = [...scripts, ...contextsAndScripts[1]];
182-
} else {
183-
assert.fail('Contexts and Scripts should not be null or undefined');
184-
}
256+
for (const hydrationData of data) {
257+
scripts = [...scripts, ...hydrationData.scripts];
185258
}
186-
assert.lengthOf(scripts, 3);
259+
assert.lengthOf(scripts, 6);
187260
for (const script of scripts) {
188261
if (script.scriptId === '1' && script.isolate === '12345') {
189262
assert.deepEqual(script, {...script1, sourceMapURL: undefined});
@@ -195,40 +268,50 @@ describe('EnhancedTracesParser', () => {
195268
}
196269
});
197270

198-
it('grouped contexts and scripts under the right target', async function() {
271+
it('groups contexts and scripts under the right target', async function() {
199272
const data = enhancedTracesParser.data();
200-
for (const target of data.keys()) {
201-
const contextsAndScripts = data.get(target);
202-
if (contextsAndScripts) {
203-
const executionContexts = contextsAndScripts[0];
204-
const scripts = contextsAndScripts[1];
205-
if (target.pid === 8050) {
206-
assert.lengthOf(executionContexts, 2);
207-
for (const executionContext of executionContexts) {
208-
// We should be able to get the correct execution context without specifying isolate
209-
// as the contexts and scripts are grouped under its repsective target already.
210-
if (executionContext.id === 1) {
211-
assert.deepEqual(executionContext, executionContext1);
212-
} else if (executionContext.id === 2) {
213-
assert.deepEqual(executionContext, executionContext2);
214-
}
273+
for (const hydrationData of data) {
274+
const target = hydrationData.target;
275+
const executionContexts = hydrationData.executionContexts;
276+
const scripts = hydrationData.scripts;
277+
if (target.pid === 8050) {
278+
assert.lengthOf(executionContexts, 2);
279+
for (const executionContext of executionContexts) {
280+
// We should be able to get the correct execution context without specifying isolate
281+
// as the contexts and scripts are grouped under its respective target already.
282+
if (executionContext.id === 1) {
283+
assert.deepEqual(executionContext, executionContext1);
284+
} else if (executionContext.id === 2) {
285+
assert.deepEqual(executionContext, executionContext2);
215286
}
216-
assert.lengthOf(scripts, 2);
217-
for (const script of scripts) {
218-
if (script.scriptId === '1') {
219-
assert.deepEqual(script, {...script1, sourceMapURL: undefined});
220-
} else if (script.scriptId === '2') {
221-
assert.deepEqual(script, script2);
222-
}
287+
}
288+
assert.lengthOf(scripts, 4);
289+
for (const script of scripts) {
290+
if (script.scriptId === '1') {
291+
assert.deepEqual(script, {...script1, sourceMapURL: undefined});
292+
} else if (script.scriptId === '2') {
293+
assert.deepEqual(script, script2);
294+
} else if (script.scriptId === '3') {
295+
// This script should be grouped under this target given the clue from FunctionCall
296+
// trace event.
297+
assert.deepEqual(script, script4);
298+
} else if (script.scriptId === '4') {
299+
// This script should be grouped under this target given the execution context @
300+
// isoalte info.
301+
assert.deepEqual(script, script5);
223302
}
224-
} else if (target.pid === 8051) {
225-
assert.lengthOf(executionContexts, 1);
226-
assert.lengthOf(scripts, 1);
227-
assert.deepEqual(executionContexts[0], executionContext3);
228-
assert.deepEqual(scripts[0], script3);
229303
}
230-
} else {
231-
assert.fail('Contexts and Scripts should not be null or undefined');
304+
} else if (target.pid === 8051) {
305+
assert.lengthOf(executionContexts, 1);
306+
assert.lengthOf(scripts, 1);
307+
assert.deepEqual(executionContexts[0], executionContext3);
308+
assert.deepEqual(scripts[0], script3);
309+
} else if (target.pid === 8052) {
310+
assert.lengthOf(executionContexts, 1);
311+
assert.lengthOf(scripts, 1);
312+
assert.deepEqual(executionContexts[0], executionContext4);
313+
// This script should be grouped under this target given the PID info.
314+
assert.deepEqual(scripts[0], script6);
232315
}
233316
}
234317
});

0 commit comments

Comments
 (0)