Memray
Testing & QualitymemrayMemray is an Agent Skill for testing & quality published in the scverse/spatialdata repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Profile the memory usage of a Python script using memray and visualize a temporal flamegraph in the browser. Use when the user wants to investigate memory consumption, find leaks, or understand allocation patterns.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/scverse/spatialdata/blob/HEAD/.claude/skills/memray/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/memray, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Steps
-
Ask the user which script to profile (full or relative path).
-
Run the script under memray:
pixi run -e profiling memray-run script.pyThis produces a binary file named
memray-script.py.<pid>.binin the current directory. -
Generate the flamegraph HTML report from the
.binfile:pixi run -e profiling memray-flame memray-script.py.<pid>.binReplace
<pid>with the actual PID shown in the filename. This writesmemray-flamegraph-script.py.<pid>.html. -
Open the report in the browser:
- macOS:
open memray-flamegraph-script.py.<pid>.html - Linux:
xdg-open memray-flamegraph-script.py.<pid>.html - Either:
python -m webbrowser memray-flamegraph-script.py.<pid>.html
- macOS:
Notes
- The
--temporalflag (included inmemray-flame) shows memory over time, not just peak — use this to spot leaks and allocation bursts. - To find the
.binfile if unsure of the name:ls memray-*.bin - To compare runs, save the previous report:
cp memray-flamegraph-script.py.<pid>.html memray-flamegraph-before.html