From 27f76b5274ab48dd97a49dbcd3003455ac939a64 Mon Sep 17 00:00:00 2001 From: GamerDubz <105694977+GamerDubz@users.noreply.github.com> Date: Tue, 1 Dec 2026 08:51:27 +0200 Subject: [PATCH] docs(agents): make the Chrome trace analysis skill installable --- .agents/plugins/marketplace.json | 20 +++ .codex-plugin/plugin.json | 17 +++ README.md | 192 +------------------------- skills/chrome-trace-analysis/SKILL.md | 183 ++++++++++++++++++++++++ 4 files changed, 225 insertions(+), 187 deletions(-) create mode 100644 .agents/plugins/marketplace.json create mode 100644 .codex-plugin/plugin.json create mode 100644 skills/chrome-trace-analysis/SKILL.md diff --git a/.agents/plugins/marketplace.json b/.agents/plugins/marketplace.json new file mode 100644 index 0000000..4ef755e --- /dev/null +++ b/.agents/plugins/marketplace.json @@ -0,0 +1,20 @@ +{ + "name": "trace-engine-cli", + "interface": { + "displayName": "Trace Engine CLI" + }, + "plugins": [ + { + "name": "trace-engine-cli", + "source": { + "source": "local", + "path": "./" + }, + "policy": { + "installation": "AVAILABLE", + "authentication": "ON_INSTALL" + }, + "category": "Coding" + } + ] +} diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json new file mode 100644 index 0000000..d82c101 --- /dev/null +++ b/.codex-plugin/plugin.json @@ -0,0 +1,17 @@ +{ + "name": "trace-engine-cli", + "version": "0.3.0", + "description": "Investigate saved Chrome performance traces with Trace Engine CLI.", + "author": { + "name": "Google LLC" + }, + "homepage": "https://github.com/ChromeDevTools/trace-engine-cli", + "repository": "https://github.com/ChromeDevTools/trace-engine-cli", + "license": "Apache-2.0", + "skills": "./skills/", + "interface": { + "displayName": "Trace Engine CLI", + "shortDescription": "Investigate saved Chrome performance traces with Trace Engine CLI.", + "category": "Coding" + } +} diff --git a/README.md b/README.md index 601c053..392e615 100644 --- a/README.md +++ b/README.md @@ -63,198 +63,16 @@ Add this snippet to your project instruction file (`AGENTS.md`, `CLAUDE.md`, or - Run `trace-engine-cli --help` or `trace-engine-cli --help` to inspect available subcommands and flags. ``` -### Option 2: Agent Skill Template (`SKILL.md`) +### Option 2: Install the Trace Analysis Skill -If your agent environment supports on-demand skills (such as `.gemini/skills/chrome-trace-analysis/SKILL.md` or `.claude/skills/chrome-trace-analysis/SKILL.md`), expand the block below and copy the template: +**Codex** -
-Click to view full SKILL.md template - -````markdown ---- -name: chrome-trace-analysis -description: Inspect and query saved Chrome/DevTools performance trace files and test fixtures (.json, .json.gz) using trace-engine-cli. Use when analyzing trace events, CPU activity, Web Vitals, or diagnostic insights. ---- - -# Chrome & Chromium DevTools Trace Analysis - -Use `trace-engine-cli` to inspect, profile, and diagnose performance recordings captured by the Chrome/Chromium DevTools Performance panel (`.json`, `.json.gz`). - ---- - -## 1. Operational Constraints - -- **Never parse or search traces manually**: Do not write ad-hoc `node -e`, `python`, `jq`, `zcat`, `gzcat`, `zgrep`, `zless`, or shell loops to inspect or search trace files or fixtures. `trace-engine-cli` handles gzip decompression, multi-file scanning, trace engine parsing, model traversal, and formatting. -- **Check command help proactively**: Run `trace-engine-cli --help` or `trace-engine-cli --help` to view available commands, flags (`--time-range`, `--category`, `--function`, `--top`), and output options before attempting custom workarounds. - ---- - -## 2. Core Principles - -- **Relative by default**: Time ranges (`--time-range`, `--window-a`, `--window-b`) default to relative time from trace start (`0ms` origin), matching the DevTools Performance panel UI. -- **Time units**: Range arguments accept milliseconds or explicit unit suffixes (`3500,4200`, `3.5s,4.2s`, `100ms,500ms`). -- **Absolute timestamps**: Pass `--absolute-timestamps` when querying raw epoch timestamps. -- **Output format**: Use `--format toon` (compact YAML-like output, default) for token efficiency, or `--format md` when generating Markdown tables for reports. - ---- - -## 3. Command Reference - -### `trace-engine-cli ` / `trace-engine-cli overview ` -High-level trace metadata, duration, Core Web Vitals (LCP, INP, CLS), and a breakdown of main-thread time by category. Calling `trace-engine-cli ` without `overview` also prints the `# Drill-down commands:` reference footer. -```bash -trace-engine-cli trace.json.gz -``` - -### `trace-engine-cli report ` -When you know which analyses a question needs, select them with `--sections` -so they share one trace parse. Run `trace-engine-cli report --help` to see the -available sections. - -```bash -trace-engine-cli report trace.json.gz --sections overview,shifts,network -trace-engine-cli report trace.json.gz --sections overview,tasks,network \ - --thread PID:TID --tasks-tree bottom-up --tasks-top 1000000 --network-top 1000000 -f json -``` - -### `trace-engine-cli insights ` -Diagnostic insight cards for Core Web Vitals and performance bottlenecks. -Without `--category`, `models` lists the state and estimated savings of every DevTools insight model, failing models first. -```bash -trace-engine-cli insights trace.json.gz - -# Filter by diagnostic category: lcp, inp, cls, render-blocking, third-parties -trace-engine-cli insights trace.json.gz --category cls - -# Target a specific navigation ID or InsightSet ID -trace-engine-cli insights trace.json.gz --navigation NAVIGATION_0 -``` - -### `trace-engine-cli shifts ` -Layout shift clusters, scores, and culprit DOM elements. -```bash -# Cluster summary -trace-engine-cli shifts trace.json.gz - -# Include individual shift events, navigation IDs, and impacted DOM nodes -trace-engine-cli shifts trace.json.gz --events -``` - -### `trace-engine-cli events ` -Inspect and filter raw trace events by name, category, phase, time range, or extract payload fields via dot notation. -```bash -# Match specific event names -trace-engine-cli events trace.json.gz --name LayoutShift,navigationStart - -# Extract nested payload fields via dot notation -trace-engine-cli events trace.json.gz --name LayoutShift --fields args.data.navigationId,args.data.score - -# Filter by category and phase -trace-engine-cli events trace.json.gz --cat devtools.timeline --phase X --top 20 -``` - -### `trace-engine-cli navigations ` (alias: `navs`) -List all navigations in the trace, their primary main frame status, and their mapped Chrome DevTools Trace Engine `InsightSet` IDs. -```bash -trace-engine-cli navigations trace.json.gz -``` - -### `trace-engine-cli profile ` -Time-bucketed CPU profiling progression across discrete intervals. -```bash -trace-engine-cli profile trace.json.gz --time-range "3500,4200" --top 3 -trace-engine-cli profile trace.json.gz --time-range "3s,5s" --bucket 50ms -``` - -### `trace-engine-cli find ` -Search for function execution instances, call frequency, and execution times. ```bash -trace-engine-cli find trace.json.gz --function "drawEventTiles" --time-range "3000,5000" +codex plugin marketplace add ChromeDevTools/trace-engine-cli +codex plugin add trace-engine-cli@trace-engine-cli ``` -### `trace-engine-cli tasks ` -Inspect long tasks (>50ms) with bottom-up and top-down TraceTree call aggregations. -```bash -trace-engine-cli tasks trace.json.gz --time-range "0,5000" -trace-engine-cli tasks trace.json.gz --tree bottom-up --top 20 -``` - -### `trace-engine-cli interactions ` -List user interaction events, duration, processing delays, presentation delays, and target DOM elements. -```bash -trace-engine-cli interactions trace.json.gz -``` - -### `trace-engine-cli scheduling ` -Detect `requestAnimationFrame` and `setTimeout` scheduling, cancellations, and churn loops. -```bash -trace-engine-cli scheduling trace.json.gz --time-range "3500,4200" -``` - -### `trace-engine-cli network ` -Network request waterfall, timings, and initiator chains. -```bash -trace-engine-cli network trace.json.gz --slowest 10 -trace-engine-cli network trace.json.gz --render-blocking -trace-engine-cli network trace.json.gz --initiator-chain "example.com" -``` - -### `trace-engine-cli diff ` -Differential CPU profile comparing two time windows. -```bash -trace-engine-cli diff trace.json.gz --window-a "3500,4000" --window-b "4000,4200" --top 10 -``` - -### `trace-engine-cli scan ` -Scan a directory of trace files, a glob pattern, or multiple fixtures for matching events, categories, phases, or raw text patterns without loading heavyweight engine pipelines. -```bash -# Scan a directory to find which fixture contains an event -trace-engine-cli scan front_end/panels/timeline/fixtures/traces/ --name "LayerTreeHostImpl:snapshot" - -# Fast substring search across compressed traces -trace-engine-cli scan "fixtures/**/*.json.gz" --grep "LayerTreeHostImpl" - -# Filter by category and phase across multiple files -trace-engine-cli scan fixtures/traces/ --cat devtools.timeline --phase X -``` -Check `skippedFiles` in the result. Scan did not search the files in that list, so a match can be missing from them. - ---- - -## 4. Diagnostic Investigation Recipes - -### Recipe A: Investigating UI Jank / Interaction Stalls -1. **Check scheduling churn**: `trace-engine-cli scheduling --time-range ","` -2. **Bucket CPU activity**: `trace-engine-cli profile --time-range ","` -3. **Check for starved functions**: `trace-engine-cli find --function "" --time-range ","` -4. **Diff against unblocked interval**: `trace-engine-cli diff --window-a "" --window-b ""` - -### Recipe B: Diagnosing Core Web Vitals (INP / LCP / CLS) -1. Run `trace-engine-cli ` to inspect CWV scores. -2. If INP is poor, run `trace-engine-cli interactions `. -3. If CLS is high, run `trace-engine-cli shifts --events` and `trace-engine-cli insights --category cls`. -4. Run `trace-engine-cli insights ` for all diagnostic insight cards. - -### Recipe C: Inspecting Test Fixtures (e.g. `fixtures/traces/`) -1. Check high-level trace contents: `trace-engine-cli ` -2. Inspect navigations and insight set IDs: `trace-engine-cli navigations ` -3. Inspect relevant subsystem: `trace-engine-cli shifts --events`, `trace-engine-cli network `, or `trace-engine-cli insights --category ` -4. Inspect raw event payloads: `trace-engine-cli events --name --fields ` - -### Recipe D: Analyzing CPU Activity in a Subframe -1. Run `trace-engine-cli threads ` and find the renderer thread by frame URL. -2. Pass its `PID:TID` as `--thread` to a CPU command, for example `trace-engine-cli tasks --thread 123:1`. Frames that share a renderer thread share its CPU results. - ---- - -## 5. Capture Caveats - -- **Missing page frames**. Browser-target CDP recordings can omit frame metadata. Record and save a trace from the DevTools Performance panel, or send `Tracing.start` on a CDP session attached to the page target. Use `trace-engine-cli scan ` to search raw events in an existing recording. -- **Missing layout-shift data**. Include the `loading` category in CDP recordings for CLS analysis. -- **Missing JavaScript samples**. Leave JavaScript sampling enabled in DevTools or include `disabled-by-default-v8.cpu_profiler` in CDP recordings for sampled call stacks. -```` - -
+The plugin provides the `chrome-trace-analysis` skill. Follow [Installation](#installation) to set up the CLI. For another agent, copy the [skill file](skills/chrome-trace-analysis/SKILL.md) into its skills directory. --- diff --git a/skills/chrome-trace-analysis/SKILL.md b/skills/chrome-trace-analysis/SKILL.md new file mode 100644 index 0000000..fd93ac9 --- /dev/null +++ b/skills/chrome-trace-analysis/SKILL.md @@ -0,0 +1,183 @@ +--- +name: chrome-trace-analysis +description: Inspect and query saved Chrome/DevTools performance trace files and test fixtures (.json, .json.gz) using trace-engine-cli. Use when analyzing trace events, CPU activity, Web Vitals, or diagnostic insights. +--- + +# Chrome & Chromium DevTools Trace Analysis + +Use `trace-engine-cli` to inspect, profile, and diagnose performance recordings captured by the Chrome/Chromium DevTools Performance panel (`.json`, `.json.gz`). + +Use Node.js 22.17 or later. If the command is unavailable, run `npx trace-engine-cli` with the same arguments. + +--- + +## 1. Operational Constraints + +- **Never parse or search traces manually**: Do not write ad-hoc `node -e`, `python`, `jq`, `zcat`, `gzcat`, `zgrep`, `zless`, or shell loops to inspect or search trace files or fixtures. `trace-engine-cli` handles gzip decompression, multi-file scanning, trace engine parsing, model traversal, and formatting. +- **Check command help proactively**: Run `trace-engine-cli --help` or `trace-engine-cli --help` to view available commands, flags (`--time-range`, `--category`, `--function`, `--top`), and output options before attempting custom workarounds. + +--- + +## 2. Core Principles + +- **Relative by default**: Time ranges (`--time-range`, `--window-a`, `--window-b`) default to relative time from trace start (`0ms` origin), matching the DevTools Performance panel UI. +- **Time units**: Range arguments accept milliseconds or explicit unit suffixes (`3500,4200`, `3.5s,4.2s`, `100ms,500ms`). +- **Absolute timestamps**: Pass `--absolute-timestamps` when querying raw epoch timestamps. +- **Output format**: Use `--format toon` (compact YAML-like output, default) for token efficiency, or `--format md` when generating Markdown tables for reports. + +--- + +## 3. Command Reference + +### `trace-engine-cli ` / `trace-engine-cli overview ` +High-level trace metadata, duration, Core Web Vitals (LCP, INP, CLS), and a breakdown of main-thread time by category. Calling `trace-engine-cli ` without `overview` also prints the `# Drill-down commands:` reference footer. +```bash +trace-engine-cli trace.json.gz +``` + +### `trace-engine-cli report ` +When you know which analyses a question needs, select them with `--sections` +so they share one trace parse. Run `trace-engine-cli report --help` to see the +available sections. + +```bash +trace-engine-cli report trace.json.gz --sections overview,shifts,network +trace-engine-cli report trace.json.gz --sections overview,tasks,network \ + --thread PID:TID --tasks-tree bottom-up --tasks-top 1000000 --network-top 1000000 -f json +``` + +### `trace-engine-cli insights ` +Diagnostic insight cards for Core Web Vitals and performance bottlenecks. +Without `--category`, `models` lists the state and estimated savings of every DevTools insight model, failing models first. +```bash +trace-engine-cli insights trace.json.gz + +# Filter by diagnostic category: lcp, inp, cls, render-blocking, third-parties +trace-engine-cli insights trace.json.gz --category cls + +# Target a specific navigation ID or InsightSet ID +trace-engine-cli insights trace.json.gz --navigation NAVIGATION_0 +``` + +### `trace-engine-cli shifts ` +Layout shift clusters, scores, and culprit DOM elements. +```bash +# Cluster summary +trace-engine-cli shifts trace.json.gz + +# Include individual shift events, navigation IDs, and impacted DOM nodes +trace-engine-cli shifts trace.json.gz --events +``` + +### `trace-engine-cli events ` +Inspect and filter raw trace events by name, category, phase, time range, or extract payload fields via dot notation. +```bash +# Match specific event names +trace-engine-cli events trace.json.gz --name LayoutShift,navigationStart + +# Extract nested payload fields via dot notation +trace-engine-cli events trace.json.gz --name LayoutShift --fields args.data.navigationId,args.data.score + +# Filter by category and phase +trace-engine-cli events trace.json.gz --cat devtools.timeline --phase X --top 20 +``` + +### `trace-engine-cli navigations ` (alias: `navs`) +List all navigations in the trace, their primary main frame status, and their mapped Chrome DevTools Trace Engine `InsightSet` IDs. +```bash +trace-engine-cli navigations trace.json.gz +``` + +### `trace-engine-cli profile ` +Time-bucketed CPU profiling progression across discrete intervals. +```bash +trace-engine-cli profile trace.json.gz --time-range "3500,4200" --top 3 +trace-engine-cli profile trace.json.gz --time-range "3s,5s" --bucket 50ms +``` + +### `trace-engine-cli find ` +Search for function execution instances, call frequency, and execution times. +```bash +trace-engine-cli find trace.json.gz --function "drawEventTiles" --time-range "3000,5000" +``` + +### `trace-engine-cli tasks ` +Inspect long tasks (>50ms) with bottom-up and top-down TraceTree call aggregations. +```bash +trace-engine-cli tasks trace.json.gz --time-range "0,5000" +trace-engine-cli tasks trace.json.gz --tree bottom-up --top 20 +``` + +### `trace-engine-cli interactions ` +List user interaction events, duration, processing delays, presentation delays, and target DOM elements. +```bash +trace-engine-cli interactions trace.json.gz +``` + +### `trace-engine-cli scheduling ` +Detect `requestAnimationFrame` and `setTimeout` scheduling, cancellations, and churn loops. +```bash +trace-engine-cli scheduling trace.json.gz --time-range "3500,4200" +``` + +### `trace-engine-cli network ` +Network request waterfall, timings, and initiator chains. +```bash +trace-engine-cli network trace.json.gz --slowest 10 +trace-engine-cli network trace.json.gz --render-blocking +trace-engine-cli network trace.json.gz --initiator-chain "example.com" +``` + +### `trace-engine-cli diff ` +Differential CPU profile comparing two time windows. +```bash +trace-engine-cli diff trace.json.gz --window-a "3500,4000" --window-b "4000,4200" --top 10 +``` + +### `trace-engine-cli scan ` +Scan a directory of trace files, a glob pattern, or multiple fixtures for matching events, categories, phases, or raw text patterns without loading heavyweight engine pipelines. +```bash +# Scan a directory to find which fixture contains an event +trace-engine-cli scan front_end/panels/timeline/fixtures/traces/ --name "LayerTreeHostImpl:snapshot" + +# Fast substring search across compressed traces +trace-engine-cli scan "fixtures/**/*.json.gz" --grep "LayerTreeHostImpl" + +# Filter by category and phase across multiple files +trace-engine-cli scan fixtures/traces/ --cat devtools.timeline --phase X +``` +Check `skippedFiles` in the result. Scan did not search the files in that list, so a match can be missing from them. + +--- + +## 4. Diagnostic Investigation Recipes + +### Recipe A: Investigating UI Jank / Interaction Stalls +1. **Check scheduling churn**: `trace-engine-cli scheduling --time-range ","` +2. **Bucket CPU activity**: `trace-engine-cli profile --time-range ","` +3. **Check for starved functions**: `trace-engine-cli find --function "" --time-range ","` +4. **Diff against unblocked interval**: `trace-engine-cli diff --window-a "" --window-b ""` + +### Recipe B: Diagnosing Core Web Vitals (INP / LCP / CLS) +1. Run `trace-engine-cli ` to inspect CWV scores. +2. If INP is poor, run `trace-engine-cli interactions `. +3. If CLS is high, run `trace-engine-cli shifts --events` and `trace-engine-cli insights --category cls`. +4. Run `trace-engine-cli insights ` for all diagnostic insight cards. + +### Recipe C: Inspecting Test Fixtures (e.g. `fixtures/traces/`) +1. Check high-level trace contents: `trace-engine-cli ` +2. Inspect navigations and insight set IDs: `trace-engine-cli navigations ` +3. Inspect relevant subsystem: `trace-engine-cli shifts --events`, `trace-engine-cli network `, or `trace-engine-cli insights --category ` +4. Inspect raw event payloads: `trace-engine-cli events --name --fields ` + +### Recipe D: Analyzing CPU Activity in a Subframe +1. Run `trace-engine-cli threads ` and find the renderer thread by frame URL. +2. Pass its `PID:TID` as `--thread` to a CPU command, for example `trace-engine-cli tasks --thread 123:1`. Frames that share a renderer thread share its CPU results. + +--- + +## 5. Capture Caveats + +- **Missing page frames**. Browser-target CDP recordings can omit frame metadata. Record and save a trace from the DevTools Performance panel, or send `Tracing.start` on a CDP session attached to the page target. Use `trace-engine-cli scan ` to search raw events in an existing recording. +- **Missing layout-shift data**. Include the `loading` category in CDP recordings for CLS analysis. +- **Missing JavaScript samples**. Leave JavaScript sampling enabled in DevTools or include `disabled-by-default-v8.cpu_profiler` in CDP recordings for sampled call stacks.