Add @profile to a Python function and run memory_profiler to pinpoint which line is causing a memory spike.
Use mprof run to record total memory over the lifetime of a long-running Python script, then plot it as a graph.
Profile a multi-process Python program and track child process memory separately or combined with the parent.
Run memory profiling interactively inside a Jupyter notebook using the built-in magic command.
Package is no longer actively maintained, it still works but may not support the latest Python versions.
memory_profiler is a Python tool for measuring how much memory your Python code uses while it runs. It has two main modes: line-by-line analysis and time-based tracking. The README notes upfront that the package is no longer actively maintained. The line-by-line mode works by adding a @profile decorator to any Python function you want to inspect. When you run your script with a special command, the tool prints a table showing each line of that function, how much memory the Python process was using after that line ran, and how much memory that line added or freed. This makes it straightforward to spot which specific lines in your code are responsible for large memory increases. The time-based mode uses a separate command called mprof. You run mprof run followed by your script, and the tool records total memory usage over the full lifetime of the process. Afterward, mprof plot generates a graph of memory over time using matplotlib. If you also decorate functions with @profile, the graph can show exactly when each function was entered and exited, helping identify which part of the program caused a memory spike. The tool also handles programs that spawn multiple processes. You can tell mprof to track child processes separately or add their memory together with the parent's, giving a more accurate picture of total resource use in parallel workloads. Installation is a single pip install command. The package depends on psutil, a standard cross-platform library for reading system metrics. It also works inside Jupyter notebooks through a built-in magic command, so you can profile code interactively without leaving the notebook environment.
← pythonprofilers on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.