diff --git a/.cursor/skills/memory-snapshot-report/SKILL.md b/.claude/skills/memory-snapshot-report/SKILL.md similarity index 72% rename from .cursor/skills/memory-snapshot-report/SKILL.md rename to .claude/skills/memory-snapshot-report/SKILL.md index 26f6719..6d16019 100644 --- a/.cursor/skills/memory-snapshot-report/SKILL.md +++ b/.claude/skills/memory-snapshot-report/SKILL.md @@ -1,26 +1,31 @@ --- name: memory-snapshot-report -description: Generate and view Unity memory snapshot reports. Use when the user wants to analyze a Unity memory snapshot, export it to a database, or generate/view an HTML report. +description: 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. --- # 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. -- Project path: **MemorySnapshotDataTools** is the project root; run commands from that directory. +- Run commands from the **repo root** (the directory containing `MemorySnapshotDataTools.sln`). ## Steps ### 1. Export snapshot to database -From the MemorySnapshotDataTools directory: +From the repo root: ```bash dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- export --validate minimal --verbose @@ -45,9 +50,10 @@ dotnet run --project Cli/MemorySnapshotDataTools.Cli.csproj -- batch-export export a .snap to DuckDB -> summary -> HTML report -> screenshot +# +# This is the agent path for "run the tool" / "confirm a change works in the real app." +# The tool is a CLI whose real product is a rendered HTML report, so the script renders +# that report headless with Chrome and writes a PNG you can actually look at. +# +# A .snap snapshot is required and is NOT shipped in this repo (captures are large and +# user-specific). You must supply one — capture it from the Unity Memory Profiler, or +# point at one you already have. +# +# Usage: +# .claude/skills/run-memory-snapshot-data-tool/smoke.sh +# MSDT_SNAP=/path/to/snapshot.snap .claude/skills/run-memory-snapshot-data-tool/smoke.sh +# MSDT_SNAP_DIR=/path/to/captures .claude/skills/run-memory-snapshot-data-tool/smoke.sh # picks the smallest .snap there +# +# Env overrides: +# MSDT_SNAP explicit path to a .snap (alternative to the positional argument) +# MSDT_SNAP_DIR dir to search for the smallest .snap when no path is given (no default) +# MSDT_OUT_DIR where artifacts land (default: /tmp/msdt-run) +# MSDT_CONFIG dotnet build configuration (default: Release) +# MSDT_SQLITE=1 also exercise the SQLite backend (export + report). +# NOTE: the SQLite *report* query is very slow (~150s); DuckDB is ~0.1s. +# MSDT_NO_BUILD=1 skip the build step (assume the solution is already built) +# +# Exit code 0 = every checked step passed. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" +cd "$REPO_ROOT" + +OUT_DIR="${MSDT_OUT_DIR:-/tmp/msdt-run}" +CONFIG="${MSDT_CONFIG:-Release}" +CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" +mkdir -p "$OUT_DIR" + +fail() { echo "SMOKE FAIL: $*" >&2; exit 1; } +step() { echo; echo "==> $*"; } + +# ---- resolve snapshot (arg > $MSDT_SNAP > smallest under $MSDT_SNAP_DIR) ---- +SNAP="${1:-${MSDT_SNAP:-}}" +if [[ -z "$SNAP" && -n "${MSDT_SNAP_DIR:-}" ]]; then + step "Discovering smallest .snap under $MSDT_SNAP_DIR" + SNAP="$(find "$MSDT_SNAP_DIR" -maxdepth 1 -name '*.snap' -type f 2>/dev/null | while read -r f; do + printf '%s %s\n' "$(wc -c < "$f")" "$f" + done | sort -n | head -1 | cut -d' ' -f2-)" +fi +[[ -n "$SNAP" && -f "$SNAP" ]] || fail "No .snap provided. Pass one as an argument, set MSDT_SNAP, or set MSDT_SNAP_DIR. Captures are large and live outside this repo (see SKILL.md)." +echo "Using snapshot: $SNAP" + +# ---- build ---- +if [[ "${MSDT_NO_BUILD:-}" != "1" ]]; then + step "Building solution ($CONFIG)" + dotnet build MemorySnapshotDataTools.sln -c "$CONFIG" >/dev/null || fail "build failed" +fi + +# ---- locate the CLI (RID-specific output dir; glob avoids hard-coding osx-arm64) ---- +CLI_DLL="$(find "Cli/bin/$CONFIG" -name MemorySnapshotDataTools.dll 2>/dev/null | head -1)" +[[ -n "$CLI_DLL" ]] || fail "CLI dll not found under Cli/bin/$CONFIG — run a build first (unset MSDT_NO_BUILD)." +run_cli() { dotnet "$CLI_DLL" "$@"; } + +step "CLI help (sanity)" +run_cli --help >/dev/null || fail "--help failed" + +# ---- export -> DuckDB ---- +DB="$OUT_DIR/out.duckdb" +rm -f "$DB" "$DB.wal" +step "export -> $DB (DuckDB)" +run_cli export "$SNAP" "$DB" --validate minimal --verbose || fail "export failed" +[[ -s "$DB" ]] || fail "export produced no database file" + +# ---- summary (no DB generated; reads the one we just made) ---- +step "summary $DB" +run_cli summary "$DB" | tee "$OUT_DIR/summary.txt" +grep -q "Memory Usage Summary" "$OUT_DIR/summary.txt" || fail "summary output missing expected header" + +# ---- report -> HTML ---- +HTML="$OUT_DIR/report.html" +rm -f "$HTML" +step "report $DB -> $HTML" +run_cli report "$DB" --out "$HTML" --title "MSDT Smoke Report" --verbose || fail "report failed" +grep -q "" "$HTML" || fail "report HTML does not look like HTML" + +# ---- screenshot the rendered report ---- +PNG="$OUT_DIR/report.png" +rm -f "$PNG" +if [[ -x "$CHROME" ]]; then + step "screenshot $HTML -> $PNG" + "$CHROME" --headless --disable-gpu --hide-scrollbars --window-size=1400,2400 \ + --screenshot="$PNG" "file://$HTML" >/dev/null 2>&1 || true + if [[ -s "$PNG" ]]; then echo "screenshot OK: $PNG"; else echo "WARN: screenshot not produced (open $HTML manually)"; fi +else + echo "WARN: Chrome not found at '$CHROME' — skipping screenshot. Open $HTML in a browser instead." +fi + +# ---- optional SQLite backend coverage (slow report; off by default) ---- +if [[ "${MSDT_SQLITE:-}" == "1" ]]; then + SDB="$OUT_DIR/out.db" + rm -f "$SDB" "$SDB-wal" "$SDB-shm" + step "export -> $SDB (SQLite)" + run_cli export "$SNAP" "$SDB" --destination sqlite --validate minimal || fail "sqlite export failed" + step "report from SQLite -> $OUT_DIR/report-sqlite.html (SLOW: query ~150s)" + run_cli report "$SDB" --out "$OUT_DIR/report-sqlite.html" || fail "sqlite report failed" +fi + +step "DONE — artifacts in $OUT_DIR" +ls -la "$OUT_DIR" diff --git a/CLAUDE.md b/CLAUDE.md index 9a6636b..4477ceb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,6 +1,6 @@ # Project guidance for Claude -MemorySnapshotDataTool parses Unity memory snapshot (`.snap`) files and exports them to +MemorySnapshotDataTools parses Unity memory snapshot (`.snap`) files and exports them to DuckDB / SQLite databases, then runs SQL to build HTML reports. Because the whole tool is built around composing and executing SQL, **SQL safety is a first-class rule in this repo.** diff --git a/LICENSE.md b/LICENSE.md index 89e6941..cffda90 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -MemorySnapshotDataTool © 2026 Unity Technologies +MemorySnapshotDataTools © 2026 Unity Technologies Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license). diff --git a/Third Party Notices.md b/Third Party Notices.md new file mode 100644 index 0000000..48ba4b5 --- /dev/null +++ b/Third Party Notices.md @@ -0,0 +1,313 @@ +# Third Party Notices + +This package contains third-party software components governed by the license(s) +indicated below. The components listed under **Redistributed components** are bundled +in, or distributed with, the shipped MemorySnapshotDataTools binaries. The components +listed under **Build- and test-time-only dependencies** are used only to build and test +the project and are **not** redistributed with the tool. + +All redistributed components are licensed under MIT, Apache-2.0, or are dedicated to the +public domain. The full text of each license type referenced below appears in the +[License texts](#license-texts) section at the end of this file. + +--- + +## Redistributed components + +### DuckDB.NET (`DuckDB.NET.Data.Full`, `DuckDB.NET.Bindings.Full`) + +- Version: 1.4.4 +- License Type: MIT +- Copyright © 2020 - 2026 Giorgi Dalakishvili +- Project: https://github.com/Giorgi/DuckDB.NET + +### DuckDB (native database engine, bundled inside `DuckDB.NET.Bindings.Full`) + +- Version: 1.4.x +- License Type: MIT +- Copyright © 2018 - 2026 Stichting DuckDB Foundation +- Project: https://github.com/duckdb/duckdb + +### Microsoft.Data.Sqlite (`Microsoft.Data.Sqlite`, `Microsoft.Data.Sqlite.Core`) + +- Version: 10.0.3 +- License Type: MIT +- Copyright © Microsoft Corporation. All rights reserved. +- Project: https://learn.microsoft.com/dotnet/standard/data/sqlite/ + +### SQLitePCLRaw (`SQLitePCLRaw.bundle_e_sqlite3`, `SQLitePCLRaw.core`, `SQLitePCLRaw.lib.e_sqlite3`, `SQLitePCLRaw.provider.e_sqlite3`) + +- Version: 2.1.11 +- License Type: Apache-2.0 +- Copyright 2014 - 2024 SourceGear, LLC (Eric Sink) +- Project: https://github.com/ericsink/SQLitePCL.raw + +### SQLite (native database engine, bundled as `e_sqlite3` inside `SQLitePCLRaw.lib.e_sqlite3`) + +- Version: 3.x +- License Type: Public Domain +- Project: https://www.sqlite.org/copyright.html + + SQLite is in the public domain and does not require a license. See the SQLite + blessing in the [License texts](#license-texts) section below. + +### System.CommandLine (`System.CommandLine`) + +- Version: 2.0.3 +- License Type: MIT +- Copyright © Microsoft Corporation. All rights reserved. +- Project: https://github.com/dotnet/command-line-api + +--- + +## Build- and test-time-only dependencies + +These dependencies are required to build and/or test the project and are **not** +redistributed with the shipped tool. They are listed here for completeness. + +| Component | Version | License | Project | +|---|---|---|---| +| Microsoft.NET.ILLink.Tasks | 10.0.3 | MIT | https://github.com/dotnet/runtime | +| xunit | 2.9.2 | Apache-2.0 | https://github.com/xunit/xunit | +| xunit.runner.visualstudio | 2.8.2 | Apache-2.0 | https://github.com/xunit/visualstudio.xunit | +| Microsoft.NET.Test.Sdk | 17.11.1 | MIT (MICROSOFT .NET LIBRARY) | https://github.com/microsoft/vstest | +| Microsoft.TestPlatform.* | 17.11.1 | MIT (MICROSOFT .NET LIBRARY) | https://github.com/microsoft/vstest | +| Microsoft.CodeCoverage | 17.11.1 | MIT (MICROSOFT .NET LIBRARY) | https://github.com/microsoft/vstest | +| Newtonsoft.Json | 13.0.1 | MIT | https://www.newtonsoft.com/json | + +--- + +## License texts + +### MIT License + +``` +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` + +### Apache License 2.0 + +``` + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative + Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, excluding + those notices that do not pertain to any part of the Derivative + Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one of + the following places: within a NOTICE text file distributed as + part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and do + not modify the License. You may add Your own attribution notices + within Derivative Works that You distribute, alongside or as an + addendum to the NOTICE text from the Work, provided that such + additional attribution notices cannot be construed as modifying + the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2014-2024 SourceGear, LLC (SQLitePCLRaw) + Copyright .NET Foundation and Contributors (xunit) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use these files except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +``` + +### SQLite Public Domain Dedication ("The Blessing") + +``` +2001 September 15 + +The author disclaims copyright to this source code. In place of +a legal notice, here is a blessing: + + May you do good and not evil. + May you find forgiveness for yourself and forgive others. + May you share freely, never taking more than you give. +``` diff --git a/docs/intro.md b/docs/intro.md index 4b584b9..d40ced5 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -1,14 +1,14 @@ # Introduction to [tool/service] -MemorySnapshotDataTool is a collection of tools to support analyzing snapshot files generated by the Unity Memory Profiler, such as exporting snapshot data into database files. +MemorySnapshotDataTools is a collection of tools to support analyzing snapshot files generated by the Unity Memory Profiler, such as exporting snapshot data into database files. ## How [tool/service] works -MemorySnapshotDataTool is primarily a C# Console Application that parses binary snapshot file formats and creates local database files to populate with snapshot data. This project also includes an Unity package to extracting summary data for loaded memory snapshots from the Unity Memory Profiler Editor window, used to validate the results for the snapshot extraction. +MemorySnapshotDataTools is primarily a C# Console Application that parses binary snapshot file formats and creates local database files to populate with snapshot data. This project also includes an Unity package to extracting summary data for loaded memory snapshots from the Unity Memory Profiler Editor window, used to validate the results for the snapshot extraction. ## Intended use case -MemorySnapshotDataTool allow users to analyzer memory snapshot files using SQL queries, and can be used by software developers, data analysts, and QA. +MemorySnapshotDataTools allow users to analyzer memory snapshot files using SQL queries, and can be used by software developers, data analysts, and QA. ## Support