| 176 | * @returns {Trace} The trace object |
| 177 | */ |
| 178 | const createTrace = (fs, outputPath) => { |
| 179 | const trace = new Tracer(); |
| 180 | const profiler = new Profiler(/** @type {Inspector} */ (inspector)); |
| 181 | if (/\/|\\/.test(outputPath)) { |
| 182 | const dirPath = dirname(fs, outputPath); |
| 183 | mkdirpSync(fs, dirPath); |
| 184 | } |
| 185 | const fsStream = fs.createWriteStream(outputPath); |
| 186 | |
| 187 | let counter = 0; |
| 188 | |
| 189 | trace.pipe(fsStream); |
| 190 | // These are critical events that need to be inserted so that tools like |
| 191 | // chrome dev tools can load the profile. |
| 192 | trace.instantEvent({ |
| 193 | name: "TracingStartedInPage", |
| 194 | id: ++counter, |
| 195 | cat: ["disabled-by-default-devtools.timeline"], |
| 196 | args: { |
| 197 | data: { |
| 198 | sessionId: "-1", |
| 199 | page: "0xfff", |
| 200 | frames: [ |
| 201 | { |
| 202 | frame: "0xfff", |
| 203 | url: "webpack", |
| 204 | name: "" |
| 205 | } |
| 206 | ] |
| 207 | } |
| 208 | } |
| 209 | }); |
| 210 | |
| 211 | // Chrome DevTools treats this as the primary trace-bootstrap event and |
| 212 | // iterates `args.data.frames`; it must be present or the trace fails to load. |
| 213 | trace.instantEvent({ |
| 214 | name: "TracingStartedInBrowser", |
| 215 | id: ++counter, |
| 216 | cat: ["disabled-by-default-devtools.timeline"], |
| 217 | args: { |
| 218 | data: { |
| 219 | sessionId: "-1", |
| 220 | frameTreeNodeId: 1, |
| 221 | persistentIds: true, |
| 222 | frames: [ |
| 223 | { |
| 224 | frame: "0xfff", |
| 225 | url: "webpack", |
| 226 | name: "" |
| 227 | } |
| 228 | ] |
| 229 | } |
| 230 | } |
| 231 | }); |
| 232 | |
| 233 | return { |
| 234 | trace, |
| 235 | counter, |