@paulirish/trace_engine 0.0.4 → 0.0.6

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/PAUL.readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # see readme for cmds
2
+
3
+ # some types thing that might work
4
+
5
+ node out/Typed/../../third_party/typescript/../../node_modules/typescript/bin/tsc -p out/Typed/gen/front_end/models/trace/trace-tsconfig.json # this then has js/map/d.ts. should be able to use for typs
package/README.md CHANGED
@@ -18,18 +18,41 @@ console.log(processor.data)
18
18
 
19
19
  See the included `analyze-trace.mjs` a runnable invocation.
20
20
 
21
- ## Building standalone
21
+ ## Maintainer cheatsheet
22
22
 
23
- ```sh
24
- # parent doc: go/btlax
23
+ See also http://go/btlax
25
24
 
26
- # these in no particular order..
25
+ #### Build, run, extract
27
26
 
27
+ ```sh
28
+ # build bundle with esbuild
28
29
  front_end/models/trace/build-trace-engine-lib.sh
29
30
 
31
+ # run
32
+ node scripts/analyze-trace.mjs test/unittests/fixtures/traces/web-dev.json.gz
33
+
34
+ # test
35
+ node scripts/test/test-trace-engine.mjs
36
+
37
+ # copy built files to $HOME/code/trace_engine
30
38
  front_end/models/trace/copy-build-trace-engine-for-publish.sh
31
39
  ```
32
40
 
41
+ #### Test and publish
42
+
43
+ ```sh
44
+ # switch to standalone
45
+ cd $HOME/code/trace_engine
46
+
47
+ # test
48
+ node test/test-trace-engine.mjs
49
+
50
+ # bump and publish
51
+ npm version v0.0.XXX # Manually determine next version
52
+ npm publish --access public --dry-run
53
+ npm publish --access public
54
+ ```
55
+
33
56
  ## High level architecture
34
57
 
35
58
  ```
package/analyze-trace.mjs CHANGED
@@ -5,26 +5,35 @@
5
5
  // Run this first:
6
6
  // front_end/models/trace/build-trace-engine-lib.sh
7
7
 
8
- import fs from 'fs';
9
- import zlib from 'zlib';
8
+ import fs from 'node:fs';
9
+ import zlib from 'node:zlib';
10
10
  // eslint-disable-next-line rulesdir/es_modules_import
11
11
  import * as TraceModel from './trace.mjs';
12
12
 
13
13
  polyfillDOMRect();
14
14
 
15
- // If run as CLI, parse the argv trace (or a fallback)
16
- if (import.meta.url.endsWith(process.argv[1])) {
17
- const filename = process.argv.at(2) ?? './test/invalid-animation-events.json.gz';
15
+
16
+ export async function analyzeTrace(filename) {
18
17
  const traceEvents = loadTraceEventsFromFile(filename);
19
18
 
20
19
  // Primary usage:
21
20
  const processor = TraceModel.Processor.TraceProcessor.createWithAllHandlers(); // aka `fullTraceEngine`
22
21
  await processor.parse(traceEvents);
22
+ return processor.data;
23
+ }
23
24
 
24
- console.log(processor.data);
25
- console.assert(processor.data.Renderer.allRendererEvents.length);
25
+ // If run as CLI, parse the argv trace (or a fallback)
26
+ if (import.meta.url.endsWith(process?.argv[1])) {
27
+ cli();
26
28
  }
27
29
 
30
+ async function cli() {
31
+ const filename = process.argv.at(2);
32
+ const traceModel = await analyzeTrace(filename);
33
+ console.log(traceModel);
34
+ }
35
+
36
+
28
37
  /**
29
38
  * @param {string=} filename
30
39
  * @returns TraceEvent[]
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@paulirish/trace_engine",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "trace.mjs",
6
6
  "scripts": {
7
- "test": "node analyze-trace.mjs"
7
+ "test": "node test/test-trace-engine.mjs",
8
+ "prepublishOnly": "npm test"
8
9
  },
9
10
  "type": "module",
10
11
  "keywords": [],
@@ -0,0 +1,52 @@
1
+ // Copyright 2023 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import test from 'node:test';
6
+ import {strict as assert} from 'assert';
7
+
8
+ import {analyzeTrace} from '../analyze-trace.mjs';
9
+
10
+ const filename = './test/invalid-animation-events.json.gz';
11
+ const data = await analyzeTrace(filename);
12
+
13
+ test('key values are populated', t => {
14
+ assert.equal(data.Renderer.allRendererEvents.length > 90_000, true);
15
+ assert.equal(data.Screenshots.length > 2, true);
16
+ assert.equal(data.Meta.threadsInProcess.size > 2, true);
17
+ assert.equal(data.Meta.mainFrameNavigations.length > 0, true);
18
+ });
19
+
20
+ test('numeric values are set and look legit', t => {
21
+ const shouldBeNumbers = [
22
+ data.Meta.traceBounds.min,
23
+ data.Meta.traceBounds.max,
24
+ data.Meta.traceBounds.range,
25
+ data.Meta.browserProcessId,
26
+ data.Meta.browserThreadId,
27
+ data.Meta.gpuProcessId,
28
+ data.Meta.gpuThreadId,
29
+ Array.from(data.Meta.topLevelRendererIds.values()).at(0),
30
+ Array.from(data.Meta.frameByProcessId.keys()).at(0),
31
+ ];
32
+ for (const datum of shouldBeNumbers) {
33
+ assert.equal(isNaN(datum), false);
34
+ assert.equal(typeof datum, 'number');
35
+ assert.equal(datum > 10, true);
36
+ }
37
+ });
38
+
39
+ test('string values are set and look legit', t => {
40
+ const shouldBeStrings = [
41
+ data.Meta.mainFrameId,
42
+ data.Meta.mainFrameURL,
43
+ Array.from(data.Meta.navigationsByFrameId.keys()).at(0),
44
+ Array.from(data.Meta.navigationsByNavigationId.keys()).at(0),
45
+ data.Meta.mainFrameId,
46
+ ];
47
+
48
+ for (const datum of shouldBeStrings) {
49
+ assert.equal(typeof datum, 'string');
50
+ assert.equal(datum.length > 10, true);
51
+ }
52
+ });