devtools-tracing 1.2.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +44 -0
- package/README.md +68 -2
- package/cli.ts +46 -0
- package/{examples → commands}/inp.ts +1 -8
- package/commands/selector-stats.ts +145 -0
- package/commands/sourcemap.ts +114 -0
- package/{examples → commands}/stats.ts +1 -9
- package/dist/cli.js +331 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +76813 -18793
- package/dist/lib/front_end/third_party/codemirror.next/bundle.d.ts +39 -0
- package/dist/src/sourcemap.d.ts +27 -0
- package/package.json +5 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// commands/selector-stats.ts
|
|
26
|
+
var fs = __toESM(require("node:fs"));
|
|
27
|
+
var zlib = __toESM(require("node:zlib"));
|
|
28
|
+
var import__ = require("../");
|
|
29
|
+
var SelectorTimingsKey = import__.Trace.Types.Events.SelectorTimingsKey;
|
|
30
|
+
async function run(tracePath) {
|
|
31
|
+
(0, import__.initDevToolsTracing)();
|
|
32
|
+
const fileData = fs.readFileSync(tracePath);
|
|
33
|
+
const decompressedData = tracePath.endsWith(".gz") ? zlib.gunzipSync(fileData) : fileData;
|
|
34
|
+
const traceData = JSON.parse(
|
|
35
|
+
decompressedData.toString()
|
|
36
|
+
);
|
|
37
|
+
const traceModel = import__.Trace.TraceModel.Model.createWithAllHandlers({
|
|
38
|
+
debugMode: true,
|
|
39
|
+
enableAnimationsFrameHandler: false,
|
|
40
|
+
maxInvalidationEventsPerEvent: 20,
|
|
41
|
+
showAllEvents: false
|
|
42
|
+
});
|
|
43
|
+
await traceModel.parse(traceData.traceEvents, {
|
|
44
|
+
isCPUProfile: false,
|
|
45
|
+
isFreshRecording: false,
|
|
46
|
+
metadata: traceData.metadata,
|
|
47
|
+
showAllEvents: false
|
|
48
|
+
});
|
|
49
|
+
const parsedTrace = traceModel.parsedTrace(0);
|
|
50
|
+
const parsedTraceData = parsedTrace.data;
|
|
51
|
+
const selectorStatsData = parsedTraceData.SelectorStats;
|
|
52
|
+
const selectorMap = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const [, value] of selectorStatsData.dataForRecalcStyleEvent) {
|
|
54
|
+
for (const timing of value.timings) {
|
|
55
|
+
const key = timing[SelectorTimingsKey.Selector] + "_" + timing[SelectorTimingsKey.StyleSheetId];
|
|
56
|
+
const existing = selectorMap.get(key);
|
|
57
|
+
if (existing) {
|
|
58
|
+
existing[SelectorTimingsKey.Elapsed] += timing[SelectorTimingsKey.Elapsed];
|
|
59
|
+
existing[SelectorTimingsKey.MatchAttempts] += timing[SelectorTimingsKey.MatchAttempts];
|
|
60
|
+
existing[SelectorTimingsKey.MatchCount] += timing[SelectorTimingsKey.MatchCount];
|
|
61
|
+
existing[SelectorTimingsKey.FastRejectCount] += timing[SelectorTimingsKey.FastRejectCount];
|
|
62
|
+
} else {
|
|
63
|
+
selectorMap.set(key, { ...timing });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const allTimings = [...selectorMap.values()];
|
|
68
|
+
const TOP_N = 15;
|
|
69
|
+
const byElapsed = allTimings.sort(
|
|
70
|
+
(a, b) => b[SelectorTimingsKey.Elapsed] - a[SelectorTimingsKey.Elapsed]
|
|
71
|
+
).slice(0, TOP_N);
|
|
72
|
+
console.log(`
|
|
73
|
+
=== Top ${TOP_N} CSS Selectors by Elapsed Time ===
|
|
74
|
+
`);
|
|
75
|
+
for (const t of byElapsed) {
|
|
76
|
+
const elapsedMs = (t[SelectorTimingsKey.Elapsed] / 1e3).toFixed(2);
|
|
77
|
+
console.log(
|
|
78
|
+
` ${elapsedMs}ms | attempts: ${t[SelectorTimingsKey.MatchAttempts]} | matches: ${t[SelectorTimingsKey.MatchCount]} | ${t[SelectorTimingsKey.Selector]}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const byAttempts = [...selectorMap.values()].sort(
|
|
82
|
+
(a, b) => b[SelectorTimingsKey.MatchAttempts] - a[SelectorTimingsKey.MatchAttempts]
|
|
83
|
+
).slice(0, TOP_N);
|
|
84
|
+
console.log(`
|
|
85
|
+
=== Top ${TOP_N} CSS Selectors by Match Attempts ===
|
|
86
|
+
`);
|
|
87
|
+
for (const t of byAttempts) {
|
|
88
|
+
const elapsedMs = (t[SelectorTimingsKey.Elapsed] / 1e3).toFixed(2);
|
|
89
|
+
console.log(
|
|
90
|
+
` ${t[SelectorTimingsKey.MatchAttempts]} attempts | ${elapsedMs}ms | matches: ${t[SelectorTimingsKey.MatchCount]} | ${t[SelectorTimingsKey.Selector]}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const invalidatedNodes = selectorStatsData.invalidatedNodeList;
|
|
94
|
+
console.log(
|
|
95
|
+
`
|
|
96
|
+
=== Invalidation Tracking (${invalidatedNodes.length} invalidated nodes) ===
|
|
97
|
+
`
|
|
98
|
+
);
|
|
99
|
+
const invalidationSelectorCounts = /* @__PURE__ */ new Map();
|
|
100
|
+
for (const node of invalidatedNodes) {
|
|
101
|
+
for (const sel of node.selectorList) {
|
|
102
|
+
const count = invalidationSelectorCounts.get(sel.selector) ?? 0;
|
|
103
|
+
invalidationSelectorCounts.set(sel.selector, count + 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const topInvalidationSelectors = [...invalidationSelectorCounts.entries()].sort((a, b) => b[1] - a[1]).slice(0, TOP_N);
|
|
107
|
+
console.log(
|
|
108
|
+
` Top ${TOP_N} selectors causing invalidations:
|
|
109
|
+
`
|
|
110
|
+
);
|
|
111
|
+
for (const [selector, count] of topInvalidationSelectors) {
|
|
112
|
+
console.log(` ${count}x | ${selector}`);
|
|
113
|
+
}
|
|
114
|
+
const subtreeCount = invalidatedNodes.filter((n) => n.subtree).length;
|
|
115
|
+
console.log(
|
|
116
|
+
`
|
|
117
|
+
Subtree invalidations: ${subtreeCount} / ${invalidatedNodes.length} total`
|
|
118
|
+
);
|
|
119
|
+
let totalElapsedUs = 0;
|
|
120
|
+
let totalMatchAttempts = 0;
|
|
121
|
+
let totalMatchCount = 0;
|
|
122
|
+
for (const t of allTimings) {
|
|
123
|
+
totalElapsedUs += t[SelectorTimingsKey.Elapsed];
|
|
124
|
+
totalMatchAttempts += t[SelectorTimingsKey.MatchAttempts];
|
|
125
|
+
totalMatchCount += t[SelectorTimingsKey.MatchCount];
|
|
126
|
+
}
|
|
127
|
+
console.log(`
|
|
128
|
+
=== Totals ===
|
|
129
|
+
`);
|
|
130
|
+
console.log(` Unique selectors: ${allTimings.length}`);
|
|
131
|
+
console.log(` Total elapsed: ${(totalElapsedUs / 1e3).toFixed(2)}ms`);
|
|
132
|
+
console.log(` Total match attempts: ${totalMatchAttempts}`);
|
|
133
|
+
console.log(` Total match count: ${totalMatchCount}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// commands/inp.ts
|
|
137
|
+
var fs2 = __toESM(require("node:fs"));
|
|
138
|
+
var zlib2 = __toESM(require("node:zlib"));
|
|
139
|
+
var import__2 = require("../");
|
|
140
|
+
async function run2(tracePath) {
|
|
141
|
+
(0, import__2.initDevToolsTracing)();
|
|
142
|
+
const fileData = fs2.readFileSync(tracePath);
|
|
143
|
+
const decompressedData = tracePath.endsWith(".gz") ? zlib2.gunzipSync(fileData) : fileData;
|
|
144
|
+
const traceData = JSON.parse(
|
|
145
|
+
decompressedData.toString()
|
|
146
|
+
);
|
|
147
|
+
const processor = import__2.Trace.Processor.TraceProcessor.createWithAllHandlers();
|
|
148
|
+
await processor.parse(traceData.traceEvents, {});
|
|
149
|
+
const insights = processor.insights.get("NO_NAVIGATION");
|
|
150
|
+
const longestInteractionEvent = insights.model.INPBreakdown.longestInteractionEvent;
|
|
151
|
+
const inp = longestInteractionEvent.dur / 1e3;
|
|
152
|
+
console.log({
|
|
153
|
+
insights: insights?.model.INPBreakdown,
|
|
154
|
+
inp
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// commands/sourcemap.ts
|
|
159
|
+
var fs3 = __toESM(require("node:fs"));
|
|
160
|
+
var zlib3 = __toESM(require("node:zlib"));
|
|
161
|
+
var import__3 = require("../");
|
|
162
|
+
async function run3(tracePath) {
|
|
163
|
+
(0, import__3.initDevToolsTracing)();
|
|
164
|
+
const fileData = fs3.readFileSync(tracePath);
|
|
165
|
+
const decompressedData = tracePath.endsWith(".gz") ? zlib3.gunzipSync(fileData) : fileData;
|
|
166
|
+
const traceData = JSON.parse(
|
|
167
|
+
decompressedData.toString()
|
|
168
|
+
);
|
|
169
|
+
const traceModel = import__3.Trace.TraceModel.Model.createWithAllHandlers();
|
|
170
|
+
const resolveSourceMap = (0, import__3.createSourceMapResolver)({
|
|
171
|
+
fetch: verboseFetch
|
|
172
|
+
});
|
|
173
|
+
await traceModel.parse(traceData.traceEvents, {
|
|
174
|
+
isCPUProfile: false,
|
|
175
|
+
isFreshRecording: false,
|
|
176
|
+
metadata: traceData.metadata,
|
|
177
|
+
showAllEvents: false,
|
|
178
|
+
resolveSourceMap
|
|
179
|
+
});
|
|
180
|
+
const parsedTrace = traceModel.parsedTrace(0);
|
|
181
|
+
const parsedTraceData = parsedTrace.data;
|
|
182
|
+
const scripts = parsedTraceData.Scripts.scripts;
|
|
183
|
+
const metadataSourceMaps = traceData.metadata?.sourceMaps?.length ?? 0;
|
|
184
|
+
console.log(`Found ${scripts.length} scripts in trace`);
|
|
185
|
+
console.log(`Source maps in trace metadata: ${metadataSourceMaps}
|
|
186
|
+
`);
|
|
187
|
+
let withUrl = 0;
|
|
188
|
+
let withFrame = 0;
|
|
189
|
+
let withSourceMapUrl = 0;
|
|
190
|
+
let withElided = 0;
|
|
191
|
+
for (const script of scripts) {
|
|
192
|
+
if (script.url) withUrl++;
|
|
193
|
+
if (script.frame) withFrame++;
|
|
194
|
+
if (script.sourceMapUrl) withSourceMapUrl++;
|
|
195
|
+
if (script.sourceMapUrlElided) withElided++;
|
|
196
|
+
}
|
|
197
|
+
console.log("Script breakdown:");
|
|
198
|
+
console.log(` with url: ${withUrl}`);
|
|
199
|
+
console.log(` with frame: ${withFrame}`);
|
|
200
|
+
console.log(` with sourceMapUrl: ${withSourceMapUrl}`);
|
|
201
|
+
console.log(` with sourceMapUrlElided: ${withElided}`);
|
|
202
|
+
console.log(` (resolution requires url + frame + sourceMapUrl/elided)
|
|
203
|
+
`);
|
|
204
|
+
let resolvedCount = 0;
|
|
205
|
+
for (const script of scripts) {
|
|
206
|
+
if (!script.sourceMap) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
resolvedCount++;
|
|
210
|
+
const sourceMap = script.sourceMap;
|
|
211
|
+
const sourceURLs = sourceMap.sourceURLs();
|
|
212
|
+
console.log(
|
|
213
|
+
` ${script.url || script.scriptId} -> ${sourceURLs.length} sources, ${sourceMap.mappings().length} mappings`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
console.log(
|
|
217
|
+
`Resolved source maps for ${resolvedCount} of ${scripts.length} scripts
|
|
218
|
+
`
|
|
219
|
+
);
|
|
220
|
+
const result = (0, import__3.symbolicateTrace)(traceData.traceEvents, scripts);
|
|
221
|
+
console.log(
|
|
222
|
+
`Symbolicated ${result.symbolicatedFrames} frames across ${result.symbolicatedEvents} events`
|
|
223
|
+
);
|
|
224
|
+
const outPath = tracePath.replace(/(\.(json|json\.gz))$/i, ".symbolicated$1");
|
|
225
|
+
if (outPath === tracePath) {
|
|
226
|
+
console.error(
|
|
227
|
+
"Could not determine output path (expected .json or .json.gz extension)"
|
|
228
|
+
);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
const outputJson = JSON.stringify(traceData);
|
|
232
|
+
if (outPath.endsWith(".gz")) {
|
|
233
|
+
fs3.writeFileSync(outPath, zlib3.gzipSync(outputJson));
|
|
234
|
+
} else {
|
|
235
|
+
fs3.writeFileSync(outPath, outputJson);
|
|
236
|
+
}
|
|
237
|
+
console.log(`Wrote symbolicated trace to ${outPath}`);
|
|
238
|
+
}
|
|
239
|
+
async function verboseFetch(url) {
|
|
240
|
+
console.log(`[sourcemap] fetching ${url}`);
|
|
241
|
+
const response = await fetch(url);
|
|
242
|
+
if (!response.ok) {
|
|
243
|
+
console.warn(
|
|
244
|
+
`[sourcemap] ${url} -> ${response.status} ${response.statusText}`
|
|
245
|
+
);
|
|
246
|
+
} else {
|
|
247
|
+
console.log(`[sourcemap] ${url} -> ok`);
|
|
248
|
+
}
|
|
249
|
+
return response;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// commands/stats.ts
|
|
253
|
+
var fs4 = __toESM(require("node:fs"));
|
|
254
|
+
var zlib4 = __toESM(require("node:zlib"));
|
|
255
|
+
var import__4 = require("../");
|
|
256
|
+
async function run4(tracePath) {
|
|
257
|
+
(0, import__4.initDevToolsTracing)();
|
|
258
|
+
const fileData = fs4.readFileSync(tracePath);
|
|
259
|
+
const decompressedData = tracePath.endsWith(".gz") ? zlib4.gunzipSync(fileData) : fileData;
|
|
260
|
+
const traceData = JSON.parse(
|
|
261
|
+
decompressedData.toString()
|
|
262
|
+
);
|
|
263
|
+
const traceModel = import__4.Trace.TraceModel.Model.createWithAllHandlers({
|
|
264
|
+
debugMode: true,
|
|
265
|
+
enableAnimationsFrameHandler: false,
|
|
266
|
+
maxInvalidationEventsPerEvent: 20,
|
|
267
|
+
showAllEvents: false
|
|
268
|
+
});
|
|
269
|
+
await traceModel.parse(traceData.traceEvents, {
|
|
270
|
+
isCPUProfile: false,
|
|
271
|
+
isFreshRecording: false,
|
|
272
|
+
metadata: traceData.metadata,
|
|
273
|
+
showAllEvents: false
|
|
274
|
+
});
|
|
275
|
+
const parsedTrace = traceModel.parsedTrace(0);
|
|
276
|
+
const parsedTraceData = parsedTrace.data;
|
|
277
|
+
const startTime = import__4.Trace.Helpers.Timing.microToMilli(
|
|
278
|
+
parsedTraceData.Meta.traceBounds.min
|
|
279
|
+
);
|
|
280
|
+
const endTime = import__4.Trace.Helpers.Timing.microToMilli(
|
|
281
|
+
parsedTraceData.Meta.traceBounds.max
|
|
282
|
+
);
|
|
283
|
+
const threads = import__4.Trace.Handlers.Threads.threadsInTrace(parsedTrace.data);
|
|
284
|
+
const mainThread = threads.find(
|
|
285
|
+
(t) => t.type === import__4.Trace.Handlers.Threads.ThreadType.MAIN_THREAD
|
|
286
|
+
);
|
|
287
|
+
if (!mainThread) {
|
|
288
|
+
throw new Error("No renderer main thread found in trace file");
|
|
289
|
+
}
|
|
290
|
+
const rendererEvents = [...mainThread.entries].filter(
|
|
291
|
+
(e) => (0, import__4.entryIsVisibleInTimeline)(e, parsedTrace)
|
|
292
|
+
);
|
|
293
|
+
const stats = (0, import__4.statsForTimeRange)(rendererEvents, startTime, endTime);
|
|
294
|
+
console.log(stats);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// cli.ts
|
|
298
|
+
var commands = {
|
|
299
|
+
"selector-stats": run,
|
|
300
|
+
inp: run2,
|
|
301
|
+
sourcemap: run3,
|
|
302
|
+
stats: run4
|
|
303
|
+
};
|
|
304
|
+
function printUsage() {
|
|
305
|
+
console.log("Usage: devtools-tracing <command> <trace-file>");
|
|
306
|
+
console.log("\nCommands:");
|
|
307
|
+
console.log(" selector-stats Top CSS selectors from selector stats and invalidation tracking");
|
|
308
|
+
console.log(" inp Extract INP (Interaction to Next Paint) breakdown");
|
|
309
|
+
console.log(" sourcemap Symbolicate a trace using source maps");
|
|
310
|
+
console.log(" stats Generate timeline category statistics");
|
|
311
|
+
}
|
|
312
|
+
async function main() {
|
|
313
|
+
const [command, tracePath] = process.argv.slice(2);
|
|
314
|
+
if (!command || command === "--help" || command === "-h") {
|
|
315
|
+
printUsage();
|
|
316
|
+
process.exit(0);
|
|
317
|
+
}
|
|
318
|
+
const run5 = commands[command];
|
|
319
|
+
if (!run5) {
|
|
320
|
+
console.error(`Unknown command: ${command}`);
|
|
321
|
+
printUsage();
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
if (!tracePath) {
|
|
325
|
+
console.error(`Missing trace file path.`);
|
|
326
|
+
console.error(`Usage: devtools-tracing ${command} <trace-file>`);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
await run5(tracePath);
|
|
330
|
+
}
|
|
331
|
+
main();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { initDevToolsTracing } from './src/init.js';
|
|
2
2
|
export { statsForTimeRange, entryIsVisibleInTimeline } from './src/timeline.js';
|
|
3
|
+
export { createSourceMapResolver, symbolicateTrace } from './src/sourcemap.js';
|
|
4
|
+
export type { SymbolicateOptions, SymbolicateResult } from './src/sourcemap.js';
|
|
3
5
|
import * as Trace from './lib/front_end/models/trace/trace.js';
|
|
4
|
-
|
|
6
|
+
import * as SDK from './lib/front_end/core/sdk/sdk.js';
|
|
7
|
+
export { Trace, SDK };
|