Skip to content

feat: trace export, HTML dashboards, and WASM profiling#36

Merged
m2papierz merged 21 commits into
masterfrom
feat/trace-export
Jun 20, 2026
Merged

feat: trace export, HTML dashboards, and WASM profiling#36
m2papierz merged 21 commits into
masterfrom
feat/trace-export

Conversation

@m2papierz

Copy link
Copy Markdown
Contributor

What

Add trace visualization export (Perfetto protobuf + Chrome TEF), standalone interactive HTML dashboards for CLI commands, and a WASM crate for in-browser profiling.

Why

Pirx simulations produce rich traces but there was no way to visualize them outside of raw JSON. Users need to load traces into
Perfetto/Chrome DevTools for timeline analysis, generate offline-capable reports for sharing, and run simulations directly in
the browser for demos and lightweight exploration.

How

  • pirx-export — new crate. Pure data transformation from &Trace to Perfetto protobuf or Chrome TEF JSON. Pool-aware track
    hierarchy, buffer counter tracks, factory slice/instant events, stall/decoder/routing visualization. No file I/O, no engine
    dependency. Criterion benchmarks included.
  • CLI export command — wires pirx-export into pirx export. Accepts trace JSON, optional --hw for factory pool names and
    calibrated cycle timing.
  • CLI --html flag — generates self-contained single-file dashboards (Plotly.js vendored inline) for profile, monte-carlo, and
    compare commands. Works fully offline.
  • pirx-wasm — thin wasm-bindgen wrapper over pirx-core/ir/hw. One-shot profiling, Monte Carlo (single-threaded), and
    step-by-step WasmEngine for frame-by-frame animation. Excluded from workspace (separate wasm-pack build). Includes demo page and WASM tests.
  • Engine accessors — last_event() and current_cycle() on Engine for step-by-step consumers.
  • Refactor — deduplicated max_factory_id helper shared across exporters, extracted Chrome TEF convert_event with explicit
    state.

Testing

  • make ci passes locally (fmt + clippy + test + audit)
  • New behavior has tests
  • Hot-path changes have criterion benchmarks

Checklist

  • PR description explains why, not just what
  • No new unwrap()/expect() in production code
  • No new allocations in the simulation hot loop
  • Crate boundaries respected (pirx-core never imports from pirx-adapters)
  • New dependencies justified (not "it's popular" — what does it replace?)

…rters

Trace visualization export for Pirx simulations. Converts `&Trace` into
Perfetto protobuf (for ui.perfetto.dev) and Chrome Trace Event Format
JSON (for chrome://tracing). Pure data transformation — no file I/O,
no engine dependency.

Includes pool-aware track hierarchy, buffer counter tracks, factory
slice/instant events, stall/decoder/routing visualization, and
parameterized criterion benchmarks.
Wire pirx-export into the CLI as `pirx export`. Accepts a trace JSON
file and exports to Perfetto protobuf or Chrome TEF format. Optional
--hw flag provides factory pool names and calibrated cycle timing.
Deduplicate max_factory_id into a crate-level pub(crate) helper shared
by both Perfetto and Chrome TEF exporters. Extract per-event conversion
into a standalone convert_event function with explicit ChromeState,
removing mutable borrows from the top-level loop. Add test for
zero-cycle-time clamping and tighten lint allows.
Add an HTML report generator backed by Plotly.js (vendored) that
produces self-contained, single-file dashboards for profile,
monte-carlo, and compare commands. Each dashboard includes interactive
charts for metrics like cycle counts, stall rates, buffer utilization,
and cross-model comparisons. The Plotly library is embedded inline so
the output works fully offline.
Ignore JSON output files produced by profile, monte-carlo, compare,
and sensitivity commands so they don't get accidentally committed.
Expose read-only accessors for the most recently recorded trace event
and the current simulation cycle. Propagates through EventSink,
TraceCollector, and SampledTraceCollector. Streaming mode returns None
(events are not stored). Enables step-by-step simulation consumers
to observe engine state without accessing internal fields.
Thin wasm-bindgen wrapper over pirx-core, pirx-ir, and pirx-hw.
Exposes one-shot profiling (streaming mode), Monte Carlo simulation
(sequential, single-threaded), and a step-by-step WasmEngine for
frame-by-frame animation. Excluded from workspace (separate
wasm-pack build). Includes demo page, WASM tests, and Makefile
targets (build-wasm, test-wasm, clean-wasm).
@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 27 untouched benchmarks


Comparing feat/trace-export (fe7eab9) with master (906bf50)

Open in CodSpeed

m2papierz added 14 commits June 19, 2026 22:25
Fixes cargo-deny wildcard ban for unpublished workspace crate.
Drop criterion bench, [[bench]] section, and codspeed dev-dependency.
bytes 1.12.0 was published <7 days ago, failing CI freshness check.
Perfetto: validates non-empty output with correct protobuf field tag.
Chrome TEF: validates JSON output contains traceEvents key.
Write raw trace JSON to disk for downstream `pirx export`.
Uses full trace mode when saving; adds TraceUnavailable error
for streaming-mode fallback. Includes demo-export Makefile target.
…perf()/etc.. Do the commit BUT YOU ARE NOT ALLOWED TO WRITE THE AUTHOR OF IT! Just clean commit
Introduce ProfileArgs, MonteCarloArgs, and CompareArgs structs to replace
8-parameter function signatures in CLI command handlers. Removes
#[allow(clippy::too_many_arguments)] suppressions.
Propagate gate IDs into Chrome TEF args and Perfetto debug annotations
so individual events are identifiable in trace viewers. Extract
emit_factory_complete helper to deduplicate factory span emission.

Harden HTML dashboards: escape </script> injection in embedded JSON,
add single-quote entity escaping, remove dead distViolin helper.

Fix u16 truncation in WASM factory_count (saturate instead of wrapping).
Add engine accessor tests for last_event and current_cycle.
Replace single demo-export target with focused demo targets
(demo-distillation, demo-perfetto, demo-real-circuit, demo-compare)
outputting to demo-output/. Normalize Python targets to -py suffix.
Remove redundant section comments.

Restructure CHANGELOG to document trace export, WASM engine, HTML
dashboards, and CLI improvements. Move sensitivity hardening entries
under their original section.
TrackDescriptor had name (tag=4) and thread (tag=2) swapped relative to
the official Perfetto track_descriptor.proto (name=2, thread=4). This
caused Perfetto UI import errors due to wire-format field mismatches.
Scope CLI output artifacts to their crate directory, group coding tool
entries together, and add AGENTS.md to ignored files.
Introduce EventSpec in Perfetto encoder, FactoryTrack in Chrome TEF
encoder, and ExportArgs in the CLI export command to replace long
positional parameter lists. Merge duplicate TraceCollector impl block
and tighten last_event visibility to pub(crate). Remove unnecessary
Clone/Copy derives on PoolDescriptor and ExportConfig.
Reject circuits exceeding 50,000 ops in step-by-step WasmEngine to
prevent unbounded trace memory growth in the WASM heap. Remove unused
js-sys dependency, mark crate as publish = false, and enable additional
clippy lints (cast safety, needless clones, pass-by-value, etc.).
@m2papierz m2papierz merged commit 7bffc5c into master Jun 20, 2026
11 checks passed
@m2papierz m2papierz deleted the feat/trace-export branch June 20, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant