-
Notifications
You must be signed in to change notification settings - Fork 9.5k
/
Copy pathcreate-test-trace.js
117 lines (108 loc) · 3.06 KB
/
create-test-trace.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
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
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';
const pid = 1111;
const tid = 222;
const frame = '3EFC2700D7BC3F4734CAF2F726EFB78C';
/** @typedef {{ts: number, duration: number}} TopLevelTaskDef */
/**
* @param {TopLevelTaskDef} options
*/
function getTopLevelTask({ts, duration}) {
return {
name: 'ThreadControllerImpl::RunTask',
ts: ts * 1000,
dur: duration * 1000,
pid,
tid,
ph: 'X',
cat: 'toplevel',
args: {
src_file: '../../third_party/blink/renderer/core/fake_runner.cc',
src_func: 'FakeRunnerFinished',
},
};
}
/**
* Creates a simple trace that fits the desired options. Useful for basic trace
* generation, e.g a trace that will result in particular long-task quiet
* periods. Input times should be in milliseconds.
* @param {{navigationStart?: number, traceEnd?: number, topLevelTasks?: Array<TopLevelTaskDef>}} options
*/
function createTestTrace(options) {
const navStart = (options.navigationStart || 0) * 1000;
const traceEvents = [{
name: 'navigationStart',
ts: navStart,
pid,
tid,
ph: 'R',
cat: 'blink.user_timing',
args: {
frame,
data: {documentLoaderURL: ''},
},
}, {
name: 'TracingStartedInBrowser',
ts: navStart,
pid,
tid,
ph: 'I',
cat: 'disabled-by-default-devtools.timeline',
args: {
data: {
frameTreeNodeId: 6,
persistentIds: true,
frames: [{frame, url: 'about:blank', name: '', processId: pid}],
},
},
s: 't',
}, {
// Needed to identify main thread for TracingStartedInBrowser.
name: 'thread_name',
ts: navStart,
pid,
tid,
ph: 'M',
cat: '__metadata',
args: {name: 'CrRendererMain'},
}, {
name: 'domContentLoadedEventEnd',
ts: navStart + 10,
pid,
tid,
ph: 'R',
cat: 'blink.user_timing,rail',
args: {frame},
}, {
name: 'firstContentfulPaint',
ts: navStart + 10,
pid,
tid,
ph: 'R',
cat: 'loading,rail,devtools.timeline',
args: {frame},
}, {
name: 'firstMeaningfulPaint',
ts: navStart + 15,
pid,
tid,
ph: 'R',
cat: 'loading,rail,devtools.timeline',
args: {frame},
}];
if (options.topLevelTasks) {
for (const task of options.topLevelTasks) {
traceEvents.push(getTopLevelTask(task));
}
}
if (options.traceEnd) {
// Insert a top level short task to extend trace to requested end.
traceEvents.push(getTopLevelTask({ts: options.traceEnd - 1, duration: 1}));
}
return {traceEvents};
}
module.exports = createTestTrace;