@paulirish/trace_engine 0.0.8 → 0.0.9

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/README.md CHANGED
@@ -26,16 +26,16 @@ See also http://go/btlax
26
26
 
27
27
  ```sh
28
28
  # build bundle with esbuild
29
- front_end/models/trace/build-trace-engine-lib.sh
29
+ scripts/trace/build-trace-engine-lib.sh
30
30
 
31
31
  # run
32
- node scripts/analyze-trace.mjs test/unittests/fixtures/traces/web-dev.json.gz
32
+ node scripts/trace/analyze-trace.mjs test/unittests/fixtures/traces/web-dev.json.gz
33
33
 
34
34
  # test
35
- node scripts/test/test-trace-engine.mjs
35
+ node scripts/trace/test/test-trace-engine.mjs
36
36
 
37
37
  # copy built files to $HOME/code/trace_engine
38
- front_end/models/trace/copy-build-trace-engine-for-publish.sh
38
+ scripts/trace/copy-build-trace-engine-for-publish.sh
39
39
  ```
40
40
 
41
41
  #### Test and publish
package/analyze-trace.mjs CHANGED
@@ -11,6 +11,10 @@ import zlib from 'node:zlib';
11
11
 
12
12
  /** @typedef {import('../front_end/models/trace/trace.ts')} TraceEngine */
13
13
 
14
+ // For types... see Connor's manual hack here:
15
+ // https://github.com/GoogleChrome/lighthouse/pull/15703/files#diff-ec7e073cf0e6135d4f2af9bc04fe6100ec0df80ad1686bee2da53871be5f1a7b
16
+ // and https://github.com/GoogleChrome/lighthouse/pull/15703/files#diff-6dab4507247217209f5ab0f6c343ca2b00af1300878abba81fb74d51cdfbedf9
17
+
14
18
  /** @type {TraceEngine} */
15
19
  import * as TraceEngine from './trace.mjs';
16
20
 
@@ -22,10 +26,9 @@ polyfillDOMRect();
22
26
  */
23
27
  export async function analyzeTrace(filename) {
24
28
  const traceEvents = loadTraceEventsFromFile(filename);
25
-
26
- const processor = TraceEngine.Processor.TraceProcessor.createWithAllHandlers(TraceEngine.Types.Configuration.DEFAULT); // aka `fullTraceEngine`
27
- await processor.parse(traceEvents);
28
- return processor.data;
29
+ const model = TraceEngine.TraceModel.Model.createWithAllHandlers(TraceEngine.Types.Configuration.DEFAULT); // aka `fullTraceEngine`
30
+ await model.parse(traceEvents);
31
+ return model.traceParsedData();
29
32
  }
30
33
 
31
34
  // If run as CLI, parse the argv trace (or a fallback)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paulirish/trace_engine",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "main": "trace.mjs",
6
6
  "scripts": {
package/trace.mjs CHANGED
@@ -2232,6 +2232,7 @@ var browserThreadId = TraceEvents_exports.ThreadID(-1);
2232
2232
  var gpuProcessId = TraceEvents_exports.ProcessID(-1);
2233
2233
  var gpuThreadId = TraceEvents_exports.ThreadID(-1);
2234
2234
  var viewportRect = null;
2235
+ var processNames = /* @__PURE__ */ new Map();
2235
2236
  var topLevelRendererIds = /* @__PURE__ */ new Set();
2236
2237
  var traceBounds = {
2237
2238
  min: Timing_exports2.MicroSeconds(Number.POSITIVE_INFINITY),
@@ -2259,6 +2260,7 @@ var CHROME_WEB_TRACE_EVENTS = /* @__PURE__ */ new Set([
2259
2260
  function reset3() {
2260
2261
  navigationsByFrameId.clear();
2261
2262
  navigationsByNavigationId.clear();
2263
+ processNames.clear();
2262
2264
  mainFrameNavigations.length = 0;
2263
2265
  browserProcessId = TraceEvents_exports.ProcessID(-1);
2264
2266
  browserThreadId = TraceEvents_exports.ThreadID(-1);
@@ -2309,6 +2311,9 @@ function handleEvent3(event) {
2309
2311
  if (traceIsGeneric && CHROME_WEB_TRACE_EVENTS.has(event.name)) {
2310
2312
  traceIsGeneric = false;
2311
2313
  }
2314
+ if (TraceEvents_exports.isProcessName(event)) {
2315
+ processNames.set(event.pid, event);
2316
+ }
2312
2317
  if (event.ts !== 0 && !event.name.endsWith("::UMA") && eventPhasesOfInterestForTraceBounds.has(event.ph)) {
2313
2318
  traceBounds.min = Timing_exports2.MicroSeconds(Math.min(event.ts, traceBounds.min));
2314
2319
  const eventDuration = event.dur || Timing_exports2.MicroSeconds(0);
@@ -2447,6 +2452,7 @@ function data3() {
2447
2452
  traceBounds: { ...traceBounds },
2448
2453
  browserProcessId,
2449
2454
  browserThreadId,
2455
+ processNames: new Map(processNames),
2450
2456
  gpuProcessId,
2451
2457
  gpuThreadId: gpuThreadId === TraceEvents_exports.ThreadID(-1) ? void 0 : gpuThreadId,
2452
2458
  viewportRect: viewportRect || void 0,
@@ -3360,18 +3366,19 @@ function assignIsMainFrame(processes2, mainFrameId2, rendererProcessesByFrame) {
3360
3366
  }
3361
3367
  }
3362
3368
  function assignThreadName(processes2, rendererProcessesByFrame, threadsInProcess2) {
3363
- for (const [, renderProcessesByPid] of rendererProcessesByFrame) {
3364
- for (const [pid] of renderProcessesByPid) {
3365
- const process = getOrCreateRendererProcess(processes2, pid);
3366
- for (const [tid, threadInfo] of threadsInProcess2.get(pid) ?? []) {
3367
- const thread = getOrCreateRendererThread(process, tid);
3368
- thread.name = threadInfo?.args.name ?? `${tid}`;
3369
- }
3369
+ for (const [pid, process] of processes2) {
3370
+ for (const [tid, threadInfo] of threadsInProcess2.get(pid) ?? []) {
3371
+ const thread = getOrCreateRendererThread(process, tid);
3372
+ thread.name = threadInfo?.args.name ?? `${tid}`;
3370
3373
  }
3371
3374
  }
3372
3375
  }
3373
3376
  function sanitizeProcesses(processes2) {
3374
3377
  const auctionWorklets = data2().worklets;
3378
+ const metaData = data3();
3379
+ if (metaData.traceIsGeneric) {
3380
+ return;
3381
+ }
3375
3382
  for (const [pid, process] of processes2) {
3376
3383
  if (process.url === null) {
3377
3384
  const maybeWorklet = auctionWorklets.get(pid);
@@ -3478,10 +3485,10 @@ function threadsInRenderer(rendererData, auctionWorkletsData) {
3478
3485
  if (rendererData.processes.size) {
3479
3486
  for (const [pid, process] of rendererData.processes) {
3480
3487
  for (const [tid, thread] of process.threads) {
3481
- const threadType = getThreadTypeForRendererThread(auctionWorkletsData, pid, thread);
3482
3488
  if (!thread.tree) {
3483
3489
  continue;
3484
3490
  }
3491
+ const threadType = getThreadTypeForRendererThread(auctionWorkletsData, pid, thread);
3485
3492
  foundThreads.push({
3486
3493
  name: thread.name,
3487
3494
  pid,