gitwtfhub

wtf is memory_profiler?

pythonprofilers/memory_profiler — explained in plain English

Analysis updated 2026-06-26

4,569PythonAudience · developerComplexity · 2/5Setup · easy

TL;DR

A Python tool that shows exactly how much memory each line of your code uses. Add a decorator to any function, run it, and get a line-by-line table showing where memory grows or shrinks.

Mindmap

mindmap
  root((memory_profiler))
    Line-by-line Mode
      Decorator usage
      Memory per line
      Memory delta
    Time-based Mode
      mprof run
      Plot graph
      Function markers
    Multi-process
      Child tracking
      Combined totals
    Integration
      Jupyter notebooks
      pip install

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Add @profile to a Python function and run memory_profiler to pinpoint which line is causing a memory spike.

REASON 2

Use mprof run to record total memory over the lifetime of a long-running Python script, then plot it as a graph.

REASON 3

Profile a multi-process Python program and track child process memory separately or combined with the parent.

REASON 4

Run memory profiling interactively inside a Jupyter notebook using the built-in magic command.

What's in the stack?

Pythonpsutilmatplotlib

How it stacks up

pythonprofilers/memory_profilerintelowlproject/intelowlantgroup/echomimic_v2
Stars4,5694,5694,568
LanguagePythonPythonPython
Setup difficultyeasyhardhard
Complexity2/54/54/5
Audiencedeveloperops devopsresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Package is no longer actively maintained, it still works but may not support the latest Python versions.

Wtf does this do

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.

Yoink these prompts

Prompt 1
Show me how to add the @profile decorator to my Python function and run memory_profiler to see which lines use the most memory.
Prompt 2
Write a script that uses mprof to profile my Python data pipeline and generate a memory-over-time graph with matplotlib.
Prompt 3
I'm using memory_profiler in a Jupyter notebook, give me the magic command syntax to profile a specific function.
Prompt 4
My Python script spawns multiple worker processes. How do I use mprof to track child process memory separately from the parent?

Frequently asked questions

wtf is memory_profiler?

A Python tool that shows exactly how much memory each line of your code uses. Add a decorator to any function, run it, and get a line-by-line table showing where memory grows or shrinks.

What language is memory_profiler written in?

Mainly Python. The stack also includes Python, psutil, matplotlib.

How hard is memory_profiler to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is memory_profiler for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.