trace-query · Chrome Performance CLI

Why does my game stutter?

Drag the blue ball and release. See how it stutters as it flies? Trace Query in CDP Tools lets you investigate Chrome performance traces. Let’s use it to diagnose the performance issue.

Measure the stutter.

At 60 Hz, a smooth shot gets a new frame about every 16.7 ms. In this shot, half the gaps exceeded 50 ms. The longest lasted 117 ms.

cdp trace frames before.json.gz --format text
Frame outcomes: 103 presented, 99 partial, 240 dropped
Presentation gaps: 100 intervals, median 50.07ms, p95 66.80ms, max 116.77ms

First two lines of the frame report.

Find the expensive function.

The game spent 4.08 seconds in overlaps, the function that tests whether two shapes might touch. Its caller checks 8.4 million pairs per physics step. Most are pairs of ground tiles. Neither tile can move.

cdp trace profile before.json.gz --format text --origin /slingshot/ --limit 3
CPU Profile: 11562 total samples, 10931 matching self samples (origin: /slingshot/)
Matched self time: ~5.53s

Function                   Self Time  Self %  Samples  Source
─────────────────────────────────────────────────────────────────────
overlaps                       4.08s   73.8%     7594  physics.js:117
findCollisionPairsNaively      1.39s   25.1%     3075  physics.js:122
measure                      39.91ms    0.7%      212  game.js:115

Skip the stationary pairs.

Check each moving body against the ground. If it reaches the ground, its coordinates tell us which tile to test. The ball and blocks still collide with one another as before.

physics.js · fixed ground check
if (this.terrain && overlaps(body, this.terrain)) {
  const tile = this.terrainTileAt(body.left, body.top);
  if (overlaps(body, tile)) grounded.add(body);
}

Play again with the fix.

Take another shot. With the new collision search, the recorded p95 gap fell from 66.80 ms to 16.72 ms.

Use a plain or gzipped Chrome trace for FILE, or - for stdin. Queries return JSON by default. Add --format text for a terminal report. The standalone alias uses trace-query FILE COMMAND.

Recording and inspection

cdp trace record RECIPE.json [--preset game|standard] [--out FILE]
Record a recipe in Chrome. The game preset captures CPU samples and compositor events.
cdp trace inventory FILE
Identify evidence present in this trace.
cdp trace overview FILE
Trace summary: duration, threads, event counts.
cdp trace threads FILE
List all threads with event counts.
cdp trace categories FILE
List all event categories with counts.
cdp trace names FILE [--cat <cat>] [--thread <name>] [--limit N]
List unique event names with occurrence counts.

Frames and game performance

cdp trace pacing FILE
Presentation gaps and dropped frames by stream.
cdp trace diagnose FILE [frame-id]
Inspect the worst gap or a selected frame.
cdp trace frames FILE
Animation frame timing statistics.
cdp trace frame FILE [INDEX|worst]
Break down a single frame's events.
cdp trace metrics FILE [pattern]
Game marks, measures, custom tracks and GPU timers.
cdp trace long-tasks FILE [--threshold N]
Main-thread tasks exceeding threshold (ms).
cdp trace gc FILE
Garbage collection summary.
cdp trace counters FILE [--name <pattern>]
Counter (C) event values over time.

Events and timing

cdp trace events FILE [pattern]
Query complete intervals with source timestamps.
Search events by name (regex).
cdp trace summarize FILE <name>
Stats for a specific event name.
cdp trace slowest FILE <pattern> [--limit N]
Longest individual occurrences of an event.
cdp trace top FILE [--n N] [--thread <name>] [--cat <cat>]
Top N events by total duration.
cdp trace self FILE [pattern]
Rank exclusive thread time.
cdp trace tree FILE <pattern> [--limit N]
Show call tree for events matching pattern.
cdp trace group FILE <pattern> [--budget N] [--depth N] [--limit N]
Analyze recurring event: distribution, children, budget.
cdp trace slices FILE <pattern> [--limit N]
Show async slices (b/e pairs) matching pattern.

JavaScript and CPU profiles

cdp trace sources FILE
List all JS source URLs from the trace.
cdp trace scripts FILE
List known scriptId → URL mappings.
cdp trace calls FILE [--source <url>] [--limit N]
Function calls, optionally filtered by source URL.
cdp trace functions FILE [--sort total|mean|max|count] [--limit N]
All functions called, with call count and durations.
cdp trace profile FILE [--limit N]
CPU profile: sampled self-time by function.
cdp trace profile-heavy FILE [--limit N]
CPU profile: self+total time (bottom-up).

Comparisons and budgets

cdp trace diff BEFORE.json AFTER.json REPORT [options]
Compare two traces (supports: profile, top, group, health, frames, gc, long-tasks).
cdp trace check FILE <pattern> --budget MS
Enforce p95 duration (exit 2 for a breach).