Steps
- Ask the user which script to profile (full or relative path).
- Run the script under memray:
```bash
pixi run -e profiling memray-run script.py
```
This produces a binary file named memray-script.py.<pid>.bin in the current directory.
- Generate the flamegraph HTML report from the
.binfile:
```bash
pixi run -e profiling memray-flame memray-script.py.<pid>.bin
```
Replace <pid> with the actual PID shown in the filename. This writes memray-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
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