Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
17 changes: 17 additions & 0 deletions .codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
192 changes: 5 additions & 187 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <subcommand> --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**

<details>
<summary><strong>Click to view full <code>SKILL.md</code> template</strong></summary>

````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 <subcommand> --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 <file>` / `trace-engine-cli overview <file>`
High-level trace metadata, duration, Core Web Vitals (LCP, INP, CLS), and a breakdown of main-thread time by category. Calling `trace-engine-cli <file>` without `overview` also prints the `# Drill-down commands:` reference footer.
```bash
trace-engine-cli trace.json.gz
```

### `trace-engine-cli report <file>`
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 <file>`
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 <file>`
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 <file>`
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 <file>` (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 <file>`
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 <file>`
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 <file>`
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 <file>`
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 <file>`
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 <file>`
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 <file>`
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 <target>`
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 <file> --time-range "<start>,<end>"`
2. **Bucket CPU activity**: `trace-engine-cli profile <file> --time-range "<start>,<end>"`
3. **Check for starved functions**: `trace-engine-cli find <file> --function "<name>" --time-range "<start>,<end>"`
4. **Diff against unblocked interval**: `trace-engine-cli diff <file> --window-a "<stallWindow>" --window-b "<unblockedWindow>"`

### Recipe B: Diagnosing Core Web Vitals (INP / LCP / CLS)
1. Run `trace-engine-cli <file>` to inspect CWV scores.
2. If INP is poor, run `trace-engine-cli interactions <file>`.
3. If CLS is high, run `trace-engine-cli shifts <file> --events` and `trace-engine-cli insights <file> --category cls`.
4. Run `trace-engine-cli insights <file>` for all diagnostic insight cards.

### Recipe C: Inspecting Test Fixtures (e.g. `fixtures/traces/`)
1. Check high-level trace contents: `trace-engine-cli <fixture>`
2. Inspect navigations and insight set IDs: `trace-engine-cli navigations <fixture>`
3. Inspect relevant subsystem: `trace-engine-cli shifts <fixture> --events`, `trace-engine-cli network <fixture>`, or `trace-engine-cli insights <fixture> --category <category>`
4. Inspect raw event payloads: `trace-engine-cli events <fixture> --name <EventName> --fields <fieldPaths>`

### Recipe D: Analyzing CPU Activity in a Subframe
1. Run `trace-engine-cli threads <file>` 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 <file> --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 <file>` 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.
````

</details>
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.

---

Expand Down
Loading