Memory Snapshot Report
This is the analysis workflow for the tool (export → validate → report, plus ad-hoc SQL).
To build, launch, and screenshot the tool end-to-end from a clean checkout, use the
run-memory-snapshot-data-tool skill and its driver.
When to use
- User wants to analyze a Unity memory snapshot (
.snap file).
- User wants to export a snapshot to a DuckDB or SQLite database.
- User wants to generate or view an HTML report from an exported snapshot database.
- User wants to validate an export against Unity golden values.
Prerequisites
- .NET 10 SDK.
- Run commands from the repo root (the directory containing
MemorySnapshotDataTools.sln).
Steps
1. Export snapshot to database
From the repo root:
dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- export <path/to/snapshot.snap> <path/to/output.duckdb> --validate minimal --verbose
- Use
.duckdb for DuckDB (recommended) or .db for SQLite.
- For SQLite add
--destination sqlite.
--verbose prints progress and timings (parse+extract vs. write).
Batch export every .snap in a directory to <basename>.duckdb alongside each file:
dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- batch-export <directory> \
--filter MyGame \
--skip-existing \
--verbose
--filter is optional (case-insensitive substring on filenames).
--skip-existing skips when the output DB is newer than the snap.
- Exit code
0 = all succeeded, 1 = one or more failures, 2 = cancelled.
2. Validate export against Unity golden JSON
For the full validation workflow (extracting golden values in Unity, every compared metric,
tolerances, and failure formats) use the validate-golden skill and
docs/golden-validation.md. Quick path:
The golden extractor lives in the com.unity.memory-snapshot-data-tools package under
UnityPackage/ in this repo, imported into a Unity project via a local file: path in that
project's Packages/manifest.json. After extracting *_golden.json in Unity
(Tools → Memory Snapshot Validation → Extract Golden Values):
dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- validate \
<path/to/snapshot_golden.json> \
<path/to/exported.duckdb>
- Compares AssetBundle, SerializedFile (Unity Subsystems native roots), and Remapper metrics.
- Also compares the MemoryProfiler Summary page metrics from the
summary_metrics table:
- Allocated Memory Distribution: Total Allocated, Total Resident, Native, Managed,
Executables & Mapped, Graphics (Estimated), Untracked.
- Managed Heap Utilization: Virtual Machine, Objects, Empty Heap Space.
- Committed bytes use a 1% / 64 KB tolerance (5% / 1 MB for the estimated Graphics and Untracked rows);
resident bytes use 1% / 64 KB and are skipped for Graphics and Untracked (resident unavailable).
- Writes
*_validation_result.json next to the golden file unless --out is set.
- Exit code
0 = pass, 1 = metric mismatch, 3 = error.
3. Generate HTML report
dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- report <path/to/output.duckdb> --out report.html --verbose
- Omit
--out to write to a temp file and open in the browser.
- Use
--title "My Report" to set the report title.
- Report works with either DuckDB or SQLite databases produced by the export command.
Prefer DuckDB — the SQLite report query is dramatically slower (seconds → minutes).
4. Optional
- Open the generated HTML file or DB in the user’s preferred viewer.
- For ad-hoc SQL, use the same DB path; tables are
schema_meta, snapshot_info, native_objects,
managed_objects, connections, native_roots, memory_regions, native_allocations,
system_memory_regions, and summary_metrics (MemoryProfiler Summary-page breakdown). Analysis
views (v_allocation_enriched, v_system_region_summary, v_region_owner_breakdown) and DuckDB
macros (region_allocations, region_page_density) simplify native-memory/region queries. For
schema details, join keys, and version compatibility, use the memory-db-sql skill and
docs/database-schema.md.
Domain
- The tool supports DuckDB (default) and SQLite; report can be generated from either.
- The CLI reports timings: export shows parse+extract vs. write; report shows query vs. render vs. write. Use
--verbose to see them.
1---2name: memory-snapshot-report3description: Generate and view Unity memory snapshot reports. Use when the user wants to analyze a Unity memory snapshot, export it to a database, validate an export against Unity golden values, or generate/view an HTML report.4---56# Memory Snapshot Report78This is the **analysis workflow** for the tool (export → validate → report, plus ad-hoc SQL).9To build, launch, and **screenshot** the tool end-to-end from a clean checkout, use the10`run-memory-snapshot-data-tool` skill and its driver.1112## When to use1314- User wants to analyze a Unity memory snapshot (`.snap` file).15- User wants to export a snapshot to a DuckDB or SQLite database.16- User wants to generate or view an HTML report from an exported snapshot database.17- User wants to validate an export against Unity golden values.1819## Prerequisites2021- .NET 10 SDK.22- Run commands from the **repo root** (the directory containing `MemorySnapshotDataTools.sln`).2324## Steps2526### 1. Export snapshot to database2728From the repo root:2930```bash31dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- export <path/to/snapshot.snap> <path/to/output.duckdb> --validate minimal --verbose32```3334- Use `.duckdb` for DuckDB (recommended) or `.db` for SQLite.35- For SQLite add `--destination sqlite`.36- `--verbose` prints progress and timings (parse+extract vs. write).3738**Batch export** every `.snap` in a directory to `<basename>.duckdb` alongside each file:3940```bash41dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- batch-export <directory> \42 --filter MyGame \43 --skip-existing \44 --verbose45```4647- `--filter` is optional (case-insensitive substring on filenames).48- `--skip-existing` skips when the output DB is newer than the snap.49- Exit code `0` = all succeeded, `1` = one or more failures, `2` = cancelled.5051### 2. Validate export against Unity golden JSON5253For the full validation workflow (extracting golden values in Unity, every compared metric,54tolerances, and failure formats) use the **`validate-golden`** skill and55[`docs/golden-validation.md`](../../../docs/golden-validation.md). Quick path:5657The golden extractor lives in the `com.unity.memory-snapshot-data-tools` package under58`UnityPackage/` in this repo, imported into a Unity project via a local `file:` path in that59project's `Packages/manifest.json`. After extracting `*_golden.json` in Unity60(**Tools → Memory Snapshot Validation → Extract Golden Values**):6162```bash63dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- validate \64 <path/to/snapshot_golden.json> \65 <path/to/exported.duckdb>66```6768- Compares AssetBundle, SerializedFile (Unity Subsystems native roots), and Remapper metrics.69- Also compares the MemoryProfiler **Summary** page metrics from the `summary_metrics` table:70 - *Allocated Memory Distribution*: Total Allocated, Total Resident, Native, Managed,71 Executables & Mapped, Graphics (Estimated), Untracked.72 - *Managed Heap Utilization*: Virtual Machine, Objects, Empty Heap Space.73 - Committed bytes use a 1% / 64 KB tolerance (5% / 1 MB for the estimated Graphics and Untracked rows);74 resident bytes use 1% / 64 KB and are skipped for Graphics and Untracked (resident unavailable).75- Writes `*_validation_result.json` next to the golden file unless `--out` is set.76- Exit code `0` = pass, `1` = metric mismatch, `3` = error.7778### 3. Generate HTML report7980```bash81dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- report <path/to/output.duckdb> --out report.html --verbose82```8384- Omit `--out` to write to a temp file and open in the browser.85- Use `--title "My Report"` to set the report title.86- Report works with either DuckDB or SQLite databases produced by the export command.87 Prefer **DuckDB** — the SQLite report query is dramatically slower (seconds → minutes).8889### 4. Optional9091- Open the generated HTML file or DB in the user’s preferred viewer.92- For ad-hoc SQL, use the same DB path; tables are `schema_meta`, `snapshot_info`, `native_objects`,93 `managed_objects`, `connections`, `native_roots`, `memory_regions`, `native_allocations`,94 `system_memory_regions`, and `summary_metrics` (MemoryProfiler Summary-page breakdown). Analysis95 views (`v_allocation_enriched`, `v_system_region_summary`, `v_region_owner_breakdown`) and DuckDB96 macros (`region_allocations`, `region_page_density`) simplify native-memory/region queries. For97 schema details, join keys, and version compatibility, use the **`memory-db-sql`** skill and98 [`docs/database-schema.md`](../../../docs/database-schema.md).99100## Domain101102- The tool supports **DuckDB** (default) and **SQLite**; report can be generated from either.103- The CLI reports **timings**: export shows parse+extract vs. write; report shows query vs. render vs. write. Use `--verbose` to see them.