LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

memray

Python memory profiler that tracks allocations

TLDR

Profile memory usage
$ memray run [script.py]
copy
Profile with output file
$ memray run -o [output.bin] [script.py]
copy
Generate flame graph
$ memray flamegraph [output.bin]
copy
Generate summary report
$ memray summary [output.bin]
copy
Live memory view
$ memray run --live [script.py]
copy
Profile with native tracking
$ memray run --native [script.py]
copy
Generate tree view
$ memray tree [output.bin]
copy
Attach to running process
$ memray attach [pid]
copy

SYNOPSIS

memray [run] [flamegraph] [summary] [tree] [attach] [options] [args]

DESCRIPTION

memray profiles Python memory allocations, tracking where memory is allocated and by which code. It helps identify memory leaks, high-water marks, and allocation patterns.The tool tracks every allocation and deallocation, recording stack traces. Post-run analysis generates visualizations showing memory usage over time and by location.Flame graphs show allocation call stacks, with width representing allocation size. They quickly identify which functions allocate most memory.Live mode provides real-time visualization during execution. It's useful for understanding memory patterns in long-running applications.Native tracking includes C extension allocations, not just Python objects. This reveals memory used by numpy, pandas, and other libraries with native components.Process attachment profiles already-running applications, useful for production debugging without restart.

PARAMETERS

run SCRIPT

Profile script execution.
flamegraph FILE
Generate flame graph HTML.
summary FILE
Show allocation summary.
tree FILE
Show tree view of allocations.
stats FILE
Show statistics.
table FILE
Show table of allocations.
attach PID
Attach to running process.
-o FILE, --output FILE
Output file for profile data.
--live
Show live memory view.
--native
Track native (C/C++) allocations.
--follow-fork
Follow child processes.
-f, --force
Overwrite existing output.

INSTALL

sudo apt install python3-memray
copy
sudo dnf install python3-memray
copy
sudo pacman -S memray
copy
brew install memray
copy
nix profile install nixpkgs#memray
copy

CAVEATS

Tracking overhead slows execution. Large profiles consume disk space. Native tracking requires debug symbols for readable output. Some allocations may be missed in highly optimized code.

HISTORY

memray was developed by Bloomberg and released as open source in 2022. It was designed for debugging memory issues in large-scale Python applications used in financial services.

SEE ALSO

py-spy(1), valgrind(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid